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 {
3535}
3636
3737// 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) {
3939 for x := 0; x <= page; x++ {
40 ujson(
40 err = ujson(
4141 "dashared/comments/thread?typeid="+strconv.Itoa(typ)+
4242 "&itemid="+postid+"&maxdepth=1000&order=newest"+
4343 "&limit=50&cursor="+url.QueryEscape(cursor),
deviantion.go +13 −11
@@ -58,6 +58,7 @@ type Deviation struct {
5858// её выпердыши
5959type Media struct {
6060 BaseUri string
61 Name string `json:"prettyName"`
6162 Token []string
6263 Types []struct {
6364 T string
@@ -90,7 +91,7 @@ type Post struct {
9091}
9192
9293// преобразование урла в правильный
93func UrlFromMedia(m Media, thumb ...int) string {
94func UrlFromMedia(m Media, thumb ...int) (urlParsed, wellFormattedFilename string) {
9495 var url strings.Builder
9596
9697 subtractWidthHeight := func(to int, target ...*int) {
@@ -108,14 +109,15 @@ func UrlFromMedia(m Media, thumb ...int) string {
108109 if len(thumb) != 0 {
109110 subtractWidthHeight(thumb[0], &t.W, &t.H)
110111 }
112 wellFormattedFilename = m.Name + m.BaseUri[l-4:]
111113
112114 url.WriteString("/v1/fit/w_")
113115 url.WriteString(strconv.Itoa(t.W))
114116 url.WriteString(",h_")
115117 url.WriteString(strconv.Itoa(t.H))
116118 url.WriteString("/")
117 url.WriteString("image")
118 url.WriteString(".gif")
119 url.WriteString(wellFormattedFilename)
120
119121 }
120122 if len(m.Token) > 0 {
121123 url.WriteString("?token=")
@@ -124,18 +126,19 @@ func UrlFromMedia(m Media, thumb ...int) string {
124126 }
125127 }
126128
127 return url.String()
129 urlParsed = url.String()
130
131 return
128132}
129133
130134// для работы функции нужно ID поста и имя пользователя.
131func GetDeviation(id string, user string) Post {
132 var st Post
133 ujson(
135func GetDeviation(id string, user string) (st Post, err Error) {
136 err = ujson(
134137 "dadeviation/init?deviationid="+id+"&username="+user+"&type=art&include_session=false&expand=deviation.related&preload=true",
135138 &st,
136139 )
137140
138 st.IMG = UrlFromMedia(st.Deviation.Media)
141 st.IMG, _ = UrlFromMedia(st.Deviation.Media)
139142
140143 // базовая обработка описания
141144 txt := st.Deviation.TextContent.Html.Markup
@@ -151,8 +154,7 @@ func GetDeviation(id string, user string) Post {
151154 txt = a.Text
152155 }
153156 }
154
155157 st.Description = txt
156
157 return st
158
159 return
158160}
misc.go +5 −6
@@ -64,8 +64,8 @@ type DailyDeviations struct {
6464 Deviations []Deviation
6565}
6666
67func GetDailyDeviations(page int) (dd DailyDeviations) {
68 ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd)
67func GetDailyDeviations(page int) (dd DailyDeviations, err Error) {
68 err = ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd)
6969 return
7070}
7171
@@ -78,9 +78,8 @@ type Search struct {
7878 ResultsGalleryTemp []Deviation `json:"results"`
7979}
8080
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) {
8282 var buildurl strings.Builder
83 e = nil
8483
8584 // о5 построение ссылок.
8685 switch scope {
@@ -90,7 +89,7 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
9089 buildurl.WriteString("dabrowse/networkbar/tag/deviations?tag=")
9190 case 'g', 'f': // поиск артов пользователя или группы
9291 if user == nil {
93 e = errors.New("missing username (last argument)")
92 err = errors.New("missing username (last argument)")
9493 return
9594 }
9695
@@ -116,7 +115,7 @@ func PerformSearch(query string, page int, scope rune, user ...string) (ss Searc
116115 }
117116 buildurl.WriteString(strconv.Itoa(page))
118117
119 ujson(buildurl.String(), &ss)
118 daError = ujson(buildurl.String(), &ss)
120119
121120 if ss.Results == nil {
122121 ss.Results = ss.ResultsGalleryTemp
user-group.go +8 −8
@@ -75,16 +75,16 @@ type Group struct {
7575}
7676
7777// подходит как группа, так и пользователь
78func (s Group) Get() (g GRuser, err error) {
78func (s Group) Get() (g GRuser, err error, daError Error) {
7979 if s.Name == "" {
80 return g, errors.New("missing Name field")
80 return g, errors.New("missing Name field"), daError
8181 }
82 ujson("dauserprofile/init/about?username="+s.Name, &g)
82 daError = ujson("dauserprofile/init/about?username="+s.Name, &g)
8383
8484 return
8585}
8686
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) {
8888 var url strings.Builder
8989
9090 if fid := folderid[0]; fid > 0 || all {
@@ -105,14 +105,14 @@ func (s Group) Favourites(page int, all bool, folderid ...int) (g Group) {
105105 url.WriteString("&with_subfolders=true&offset=")
106106 url.WriteString(strconv.Itoa(page * 50))
107107
108 ujson(url.String(), &g.Content)
108 err = ujson(url.String(), &g.Content)
109109 return
110110}
111111
112112// гарелея пользователя или группы
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) {
114114 if s.Name == "" {
115 return g, errors.New("missing Name field")
115 return g, errors.New("missing Name field"), daError
116116 }
117117
118118 var url strings.Builder
@@ -135,7 +135,7 @@ func (s Group) Gallery(page int, folderid ...int) (g Group, err error) {
135135 url.WriteString("limit=50")
136136 url.WriteString("&with_subfolders=false")
137137
138 ujson(url.String(), &g.Content)
138 daError = ujson(url.String(), &g.Content)
139139 return
140140}
141141
util.go +18 −4
@@ -15,11 +15,25 @@ func try(txt error) {
1515 }
1616}
1717
18// сокращение для вызова щенка и парсинга жсона
19func ujson(data string, output any) {
18func ujson(data string, output any) Error {
2019 input, err := puppy(data)
21 try(err)
22 try(json.Unmarshal([]byte(input), output))
20 if err == nil {
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
2337}
2438
2539/* REQUEST SECTION */