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 @@
11# Devianter
22
3[![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page)
3[![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page) [![Go Reference](https://pkg.go.dev/badge/git.macaw.me/skunky/devianter.svg)](https://pkg.go.dev/git.macaw.me/skunky/devianter) [![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
44
55
66A DeviantART API library for Go.
comments.go +24 −27
@@ -2,48 +2,45 @@ package devianter
22
33import (
44 "encoding/json"
5 "net/url"
56 "strconv"
6 "strings"
77)
88
9type 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
928type Comments struct {
1029 Cursor string
1130 PrevOffset int
1231 HasMore, HasLess bool
1332
1433 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
3335}
3436
35// функция для обработки комментариев поста, пользователя, группы и многого другого
36func CommentsFunc(
37 postid string,
38 cursor string,
39 page int,
40 typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
41) (cmmts Comments) {
37// 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
38func CommentsFunc(postid string, cursor string, page int, typ int) (cmmts Comments) {
4239 for x := 0; x <= page; x++ {
4340 ujson(
4441 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+
4542 "&itemid="+postid+"&maxdepth=1000&order=newest"+
46 "&limit=50&cursor="+strings.ReplaceAll(cursor, "+", `%2B`),
43 "&limit=50&cursor="+url.QueryEscape(cursor),
4744 &cmmts,
4845 )
4946
misc.go +11 −5
@@ -7,6 +7,7 @@ import (
77 "log"
88 "math"
99 "net/http"
10 u "net/url"
1011 "strconv"
1112 "strings"
1213)
@@ -131,10 +132,11 @@ func DailyDeviationsFunc(page int) (dd DailyDeviations) {
131132
132133/* SEARCH */
133134type 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"`
138140}
139141
140142func 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,
162164 log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.")
163165 }
164166
165 url.WriteString(query)
167 url.WriteString(u.QueryEscape(query))
166168 if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код
167169 url.WriteString("&page=")
168170 } else { // иначе вместо страницы будет оффсет и страница умножится на 50
@@ -173,6 +175,10 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search,
173175
174176 ujson(url.String(), &ss)
175177
178 if scope == 'g' {
179 ss.Results = ss.ResultsGalleryTemp
180 }
181
176182 // расчёт, сколько всего страниц по запросу. без токена 417 страниц - максимум
177183 totalfloat := int(math.Round(float64(ss.Total / 25)))
178184 for x := 0; x < totalfloat; x++ {