Commit 949bef2c5d
949bef2c5d5ee53a5d6158e16921c698f8a6e266
parent: efa4b86a67
Unsigned
lost+skunk <skunky@ebloid.ru> · 2024-06-30 11:39 UTC
по мелочи
Layout: unified · split
README.md
+1 −1
| @@ -1,6 +1,6 @@ |
| 1 | # Devianter |
1 | # Devianter |
| 2 | |
2 | |
| 3 | [](https://nogithub.codeberg.page) |
3 | [](https://nogithub.codeberg.page) [](https://pkg.go.dev/git.macaw.me/skunky/devianter) [](https://www.gnu.org/licenses/agpl-3.0) |
| 4 | |
4 | |
| 5 | |
5 | |
| 6 | A DeviantART API library for Go. |
6 | A DeviantART API library for Go. |
comments.go
+24 −27
| @@ -2,48 +2,45 @@ package devianter |
| 2 | |
2 | |
| 3 | import ( |
3 | import ( |
| 4 | "encoding/json" |
4 | "encoding/json" |
| |
5 | "net/url" |
| 5 | "strconv" |
6 | "strconv" |
| 6 | "strings" |
| |
| 7 | ) |
7 | ) |
| 8 | |
8 | |
| |
9 | type Thread struct { |
| |
10 | Replies, Likes int |
| |
11 | ID int `json:"commentId"` |
| |
12 | Parent int `json:"parentId"` |
| |
13 | |
| |
14 | Posted time |
| |
15 | Author bool `json:"isAuthorHighlited"` |
| |
16 | |
| |
17 | Desctiption string |
| |
18 | Comment string |
| |
19 | |
| |
20 | TextContent Text |
| |
21 | |
| |
22 | User struct { |
| |
23 | Username string |
| |
24 | Banned bool `json:"isBanned"` |
| |
25 | } |
| |
26 | } |
| |
27 | |
| 9 | type Comments struct { |
28 | type Comments struct { |
| 10 | Cursor string |
29 | Cursor string |
| 11 | PrevOffset int |
30 | PrevOffset int |
| 12 | HasMore, HasLess bool |
31 | HasMore, HasLess bool |
| 13 | |
32 | |
| 14 | Total int |
33 | Total int |
| 15 | Thread []struct { |
34 | Thread []Thread |
| 16 | Replies, Likes int |
| |
| 17 | ID int `json:"commentId"` |
| |
| 18 | Parent int `json:"parentId"` |
| |
| 19 | |
| |
| 20 | Posted time |
| |
| 21 | Author bool `json:"isAuthorHighlited"` |
| |
| 22 | |
| |
| 23 | Desctiption string |
| |
| 24 | Comment string |
| |
| 25 | |
| |
| 26 | TextContent Text |
| |
| 27 | |
| |
| 28 | User struct { |
| |
| 29 | Username string |
| |
| 30 | Banned bool `json:"isBanned"` |
| |
| 31 | } |
| |
| 32 | } |
| |
| 33 | } |
35 | } |
| 34 | |
36 | |
| 35 | // функция для обработки комментариев поста, пользователя, группы и многого другого |
37 | // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя |
| 36 | func CommentsFunc( |
38 | func CommentsFunc(postid string, cursor string, page int, typ int) (cmmts Comments) { |
| 37 | postid string, |
| |
| 38 | cursor string, |
| |
| 39 | page int, |
| |
| 40 | typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя |
| |
| 41 | ) (cmmts Comments) { |
| |
| 42 | for x := 0; x <= page; x++ { |
39 | for x := 0; x <= page; x++ { |
| 43 | ujson( |
40 | ujson( |
| 44 | "dashared/comments/thread?typeid="+strconv.Itoa(typ)+ |
41 | "dashared/comments/thread?typeid="+strconv.Itoa(typ)+ |
| 45 | "&itemid="+postid+"&maxdepth=1000&order=newest"+ |
42 | "&itemid="+postid+"&maxdepth=1000&order=newest"+ |
| 46 | "&limit=50&cursor="+strings.ReplaceAll(cursor, "+", `%2B`), |
43 | "&limit=50&cursor="+url.QueryEscape(cursor), |
| 47 | &cmmts, |
44 | &cmmts, |
| 48 | ) |
45 | ) |
| 49 | |
46 | |
misc.go
+11 −5
| @@ -7,6 +7,7 @@ import ( |
| 7 | "log" |
7 | "log" |
| 8 | "math" |
8 | "math" |
| 9 | "net/http" |
9 | "net/http" |
| |
10 | u "net/url" |
| 10 | "strconv" |
11 | "strconv" |
| 11 | "strings" |
12 | "strings" |
| 12 | ) |
13 | ) |
| @@ -131,10 +132,11 @@ func DailyDeviationsFunc(page int) (dd DailyDeviations) { |
| 131 | |
132 | |
| 132 | /* SEARCH */ |
133 | /* SEARCH */ |
| 133 | type Search struct { |
134 | type Search struct { |
| 134 | Total int `json:"estTotal"` |
135 | Total int `json:"estTotal"` |
| 135 | Pages int // only for 'a' and 'g' scope. |
136 | Pages int // only for 'a' and 'g' scope. |
| 136 | HasMore bool |
137 | HasMore bool |
| 137 | Results []Deviation `json:"deviations,results"` |
138 | Results []Deviation `json:"deviations"` |
| |
139 | ResultsGalleryTemp []Deviation `json:"results"` |
| 138 | } |
140 | } |
| 139 | |
141 | |
| 140 | func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, e error) { |
142 | func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, e error) { |
| @@ -162,7 +164,7 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, |
| 162 | log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.") |
164 | log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.") |
| 163 | } |
165 | } |
| 164 | |
166 | |
| 165 | url.WriteString(query) |
167 | url.WriteString(u.QueryEscape(query)) |
| 166 | if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код |
168 | if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код |
| 167 | url.WriteString("&page=") |
169 | url.WriteString("&page=") |
| 168 | } else { // иначе вместо страницы будет оффсет и страница умножится на 50 |
170 | } else { // иначе вместо страницы будет оффсет и страница умножится на 50 |
| @@ -173,6 +175,10 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, |
| 173 | |
175 | |
| 174 | ujson(url.String(), &ss) |
176 | ujson(url.String(), &ss) |
| 175 | |
177 | |
| |
178 | if scope == 'g' { |
| |
179 | ss.Results = ss.ResultsGalleryTemp |
| |
180 | } |
| |
181 | |
| 176 | // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум |
182 | // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум |
| 177 | totalfloat := int(math.Round(float64(ss.Total / 25))) |
183 | totalfloat := int(math.Round(float64(ss.Total / 25))) |
| 178 | for x := 0; x < totalfloat; x++ { |
184 | for x := 0; x < totalfloat; x++ { |