Commit b3c99749f1

b3c99749f133abf6c04506135c2e4e7567da5254

parent: 4487cdcbe9

Unsigned

lost+skunk <skunky@ebloid.ru> · 2024-09-04 17:18 UTC

ошибки

Layout: unified · split

comments.go +2 −2
@@ -35,9 +35,9 @@ type Comments struct {
35} 35}
36 36
37// 1 - комментарии поста; 4 - комментарии на стене группы или пользователя 37// 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
38func GetComments(postid string, cursor string, page int, typ int) (cmmts Comments) { 38func GetComments(postid string, cursor string, page int, typ int) (cmmts Comments, err Error) {
39 for x := 0; x <= page; x++ { 39 for x := 0; x <= page; x++ {
40 ujson( 40 err = ujson(
41 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+ 41 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+
42 "&itemid="+postid+"&maxdepth=1000&order=newest"+ 42 "&itemid="+postid+"&maxdepth=1000&order=newest"+
43 "&limit=50&cursor="+url.QueryEscape(cursor), 43 "&limit=50&cursor="+url.QueryEscape(cursor),
deviantion.go +13 −11
@@ -58,6 +58,7 @@ type Deviation struct {
58// её выпердыши 58// её выпердыши
59type Media struct { 59type Media struct {
60 BaseUri string 60 BaseUri string
61 Name string `json:"prettyName"`
61 Token []string 62 Token []string
62 Types []struct { 63 Types []struct {
63 T string 64 T string
@@ -90,7 +91,7 @@ type Post struct {
90} 91}
91 92
92// преобразование урла в правильный 93// преобразование урла в правильный
93func UrlFromMedia(m Media, thumb ...int) string { 94func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename string) {
94 var url strings.Builder 95 var url strings.Builder
95 96
96 subtractWidthHeight := func(to int, target ...*int) { 97 subtractWidthHeight := func(to int, target ...*int) {
@@ -108,14 +109,15 @@ func UrlFromMedia(m Media, thumb ...int) string {
108 if len(thumb) != 0 { 109 if len(thumb) != 0 {
109 subtractWidthHeight(thumb[0], &t.W, &t.H) 110 subtractWidthHeight(thumb[0], &t.W, &t.H)
110 } 111 }
112 wellFormattedFilename = m.Name + m.BaseUri[l-4:]
111 113
112 url.WriteString("/v1/fit/w_") 114 url.WriteString("/v1/fit/w_")
113 url.WriteString(strconv.Itoa(t.W)) 115 url.WriteString(strconv.Itoa(t.W))
114 url.WriteString(",h_") 116 url.WriteString(",h_")
115 url.WriteString(strconv.Itoa(t.H)) 117 url.WriteString(strconv.Itoa(t.H))
116 url.WriteString("/") 118 url.WriteString("/")
117 url.WriteString("image") 119 url.WriteString(wellFormattedFilename)
118 url.WriteString(".gif") 120
119 } 121 }
120 if len(m.Token) > 0 { 122 if len(m.Token) > 0 {
121 url.WriteString("?token=") 123 url.WriteString("?token=")
@@ -124,18 +126,19 @@ func UrlFromMedia(m Media, thumb ...int) string {
124 } 126 }
125 } 127 }
126 128
127 return url.String() 129 urlParsed = url.String()
130
131 return
128} 132}
129 133
130// для работы функции нужно ID поста и имя пользователя. 134// для работы функции нужно ID поста и имя пользователя.
131func GetDeviation(id string, user string) Post { 135func GetDeviation(id string, user string) (st Post, err Error) {
132 var st Post 136 err = ujson(
133 ujson(
134 "dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true", 137 "dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true",
135 &st, 138 &st,
136 ) 139 )
137 140
138 st.IMG = UrlFromMedia(st.Deviation.Media) 141 st.IMG, _ = UrlFromMedia(st.Deviation.Media)
139 142
140 // базовая обработка описания 143 // базовая обработка описания
141 txt := st.Deviation.TextContent.Html.Markup 144 txt := st.Deviation.TextContent.Html.Markup
@@ -151,8 +154,7 @@ func GetDeviation(id string, user string) Post {
151 txt = a.Text 154 txt = a.Text
152 } 155 }
153 } 156 }
154
155 st.Description = txt 157 st.Description = txt
156 158
157 return st 159 return
158} 160}
misc.go +5 −6
@@ -64,8 +64,8 @@ type DailyDeviations struct {
64 Deviations []Deviation 64 Deviations []Deviation
65} 65}
66 66
67func GetDailyDeviations(page int) (dd DailyDeviations) { 67func GetDailyDeviations(page int) (dd DailyDeviations, err Error) {
68 ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd) 68 err = ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd)
69 return 69 return
70} 70}
71 71
@@ -78,9 +78,8 @@ type Search struct {
78 ResultsGalleryTemp []Deviation `json:"results"` 78 ResultsGalleryTemp []Deviation `json:"results"`
79} 79}
80 80
81func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, e error) { 81func PerformSearch(query string, page int, scope rune, user ...string) (ss Search, err error, daError Error) {
82 var buildurl strings.Builder 82 var buildurl strings.Builder
83 e = nil
84 83
85 // о5 построение ссылок. 84 // о5 построение ссылок.
86 switch scope { 85 switch scope {
@@ -90,7 +89,7 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
90 buildurl.WriteString("dabrowse/networkbar/tag/deviations?tag=") 89 buildurl.WriteString("dabrowse/networkbar/tag/deviations?tag=")
91 case 'g', 'f': // поиск артов пользователя или группы 90 case 'g', 'f': // поиск артов пользователя или группы
92 if user == nil { 91 if user == nil {
93 e = errors.New("missing username (last argument)") 92 err = errors.New("missing username (last argument)")
94 return 93 return
95 } 94 }
96 95
@@ -116,7 +115,7 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
116 } 115 }
117 buildurl.WriteString(strconv.Itoa(page)) 116 buildurl.WriteString(strconv.Itoa(page))
118 117
119 ujson(buildurl.String(), &ss) 118 daError = ujson(buildurl.String(), &ss)
120 119
121 if ss.Results == nil { 120 if ss.Results == nil {
122 ss.Results = ss.ResultsGalleryTemp 121 ss.Results = ss.ResultsGalleryTemp
user-group.go +8 −8
@@ -75,16 +75,16 @@ type Group struct {
75} 75}
76 76
77// подходит как группа, так и пользователь 77// подходит как группа, так и пользователь
78func (s Group) Get() (g GRuser, err error) { 78func (s Group) Get() (g GRuser, err error, daError Error) {
79 if s.Name == "" { 79 if s.Name == "" {
80 return g, errors.New("missing Name field") 80 return g, errors.New("missing Name field"), daError
81 } 81 }
82 ujson("dauserprofile/init/about?username="+s.Name, &g) 82 daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
83 83
84 return 84 return
85} 85}
86 86
87func (s Group) Favourites(page int, all bool, folderid ...int) (g Group) { 87func (s Group) Favourites(page int, all bool, folderid ...int) (g Group, err Error) {
88 var url strings.Builder 88 var url strings.Builder
89 89
90 if fid := folderid[0]; fid > 0 || all { 90 if fid := folderid[0]; fid > 0 || all {
@@ -105,14 +105,14 @@ func (s Group) Favourites(page int, all bool, folderid ...int) (g Group) {
105 url.WriteString("&with_subfolders=true&offset=") 105 url.WriteString("&with_subfolders=true&offset=")
106 url.WriteString(strconv.Itoa(page * 50)) 106 url.WriteString(strconv.Itoa(page * 50))
107 107
108 ujson(url.String(), &g.Content) 108 err = ujson(url.String(), &g.Content)
109 return 109 return
110} 110}
111 111
112// гарелея пользователя или группы 112// гарелея пользователя или группы
113func (s Group) Gallery(page int, folderid ...int) (g Group, err error) { 113func (s Group) Gallery(page int, folderid ...int) (g Group, err error, daError Error) {
114 if s.Name == "" { 114 if s.Name == "" {
115 return g, errors.New("missing Name field") 115 return g, errors.New("missing Name field"), daError
116 } 116 }
117 117
118 var url strings.Builder 118 var url strings.Builder
@@ -135,7 +135,7 @@ func (s Group) Gallery(page int, folderid ...int) (g Group, err error) {
135 url.WriteString("limit=50") 135 url.WriteString("limit=50")
136 url.WriteString("&with_subfolders=false") 136 url.WriteString("&with_subfolders=false")
137 137
138 ujson(url.String(), &g.Content) 138 daError = ujson(url.String(), &g.Content)
139 return 139 return
140} 140}
141 141
util.go +18 −4
@@ -15,11 +15,25 @@ func try(txt error) {
15 } 15 }
16} 16}
17 17
18// сокращение для вызова щенка и парсинга жсона 18func ujson(data string, output any) Error {
19func ujson(data string, output any) {
20 input, err := puppy(data) 19 input, err := puppy(data)
21 try(err) 20 if err == nil {
22 try(json.Unmarshal([]byte(input), output)) 21 try(json.Unmarshal([]byte(input), output))
22 }
23 return APIError(err)
24}
25
26type Error struct {
27 Reason string `json:"error"`
28 Error string `json:"errorDescription"`
29 RAW []byte `json:"-"`
30}
31func APIError(inputError error) (err Error) {
32 if inputError != nil {
33 err.RAW = []byte(inputError.Error())
34 try(json.Unmarshal(err.RAW, &err))
35 }
36 return
23} 37}
24 38
25/* REQUEST SECTION */ 39/* REQUEST SECTION */