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 | 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 | 6 | A DeviantART API library for Go. |
comments.go
+24 −27
| @@ -2,48 +2,45 @@ package devianter |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 4 | "encoding/json" |
| 5 | "net/url" |
| 5 | 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 | 28 | type Comments struct { |
| 10 | 29 | Cursor string |
| 11 | 30 | PrevOffset int |
| 12 | 31 | HasMore, HasLess bool |
| 13 | 32 | |
| 14 | 33 | Total int |
| 15 | | Thread []struct { |
| 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 | | } |
| 34 | Thread []Thread |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | | // функция для обработки комментариев поста, пользователя, группы и многого другого |
| 36 | | func CommentsFunc( |
| 37 | | postid string, |
| 38 | | cursor string, |
| 39 | | page int, |
| 40 | | typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя |
| 41 | | ) (cmmts Comments) { |
| 37 | // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя |
| 38 | func CommentsFunc(postid string, cursor string, page int, typ int) (cmmts Comments) { |
| 42 | 39 | for x := 0; x <= page; x++ { |
| 43 | 40 | ujson( |
| 44 | 41 | "dashared/comments/thread?typeid="+strconv.Itoa(typ)+ |
| 45 | 42 | "&itemid="+postid+"&maxdepth=1000&order=newest"+ |
| 46 | | "&limit=50&cursor="+strings.ReplaceAll(cursor, "+", `%2B`), |
| 43 | "&limit=50&cursor="+url.QueryEscape(cursor), |
| 47 | 44 | &cmmts, |
| 48 | 45 | ) |
| 49 | 46 | |
misc.go
+11 −5
| @@ -7,6 +7,7 @@ import ( |
| 7 | 7 | "log" |
| 8 | 8 | "math" |
| 9 | 9 | "net/http" |
| 10 | u "net/url" |
| 10 | 11 | "strconv" |
| 11 | 12 | "strings" |
| 12 | 13 | ) |
| @@ -131,10 +132,11 @@ func DailyDeviationsFunc(page int) (dd DailyDeviations) { |
| 131 | 132 | |
| 132 | 133 | /* SEARCH */ |
| 133 | 134 | type Search struct { |
| 134 | | Total int `json:"estTotal"` |
| 135 | | Pages int // only for 'a' and 'g' scope. |
| 136 | | HasMore bool |
| 137 | | Results []Deviation `json:"deviations,results"` |
| 135 | Total int `json:"estTotal"` |
| 136 | Pages int // only for 'a' and 'g' scope. |
| 137 | HasMore bool |
| 138 | Results []Deviation `json:"deviations"` |
| 139 | ResultsGalleryTemp []Deviation `json:"results"` |
| 138 | 140 | } |
| 139 | 141 | |
| 140 | 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 | 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 | 168 | if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код |
| 167 | 169 | url.WriteString("&page=") |
| 168 | 170 | } else { // иначе вместо страницы будет оффсет и страница умножится на 50 |
| @@ -173,6 +175,10 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, |
| 173 | 175 | |
| 174 | 176 | ujson(url.String(), &ss) |
| 175 | 177 | |
| 178 | if scope == 'g' { |
| 179 | ss.Results = ss.ResultsGalleryTemp |
| 180 | } |
| 181 | |
| 176 | 182 | // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум |
| 177 | 183 | totalfloat := int(math.Round(float64(ss.Total / 25))) |
| 178 | 184 | for x := 0; x < totalfloat; x++ { |