Commit cec788554a

cec788554afe20b8c67357ede087b3c5c543be89

parent: 8f645d7ccb

Unsigned

lost+skunk <skunky@macaw.me> · 2024-06-14 17:05 UTC

Daily Deviations

Layout: unified · split

comments.go +1 −1
@@ -15,7 +15,7 @@ type Comments struct {
1515 Thread []struct {
1616 Replies, Likes int
1717 ID int `json:"commentId"`
18 Parent int `json:"ParrentId"`
18 Parent int `json:"parentId"`
1919
2020 Posted time
2121 Author bool `json:"isAuthorHighlited"`
deviantion.go +4 −2
@@ -97,8 +97,10 @@ func UrlFromMedia(m media) string {
9797 url.WriteString("image")
9898 url.WriteString(".gif")
9999 }
100 url.WriteString("?token=")
101 url.WriteString(m.Token[0])
100 if len(m.Token) > 0 {
101 url.WriteString("?token=")
102 url.WriteString(m.Token[0])
103 }
102104 }
103105 }
104106 return url.String()
misc.go +36 −28
@@ -115,10 +115,27 @@ func AEmedia(name string, t rune) (string, error) {
115115 return "", errors.New("User not exists")
116116}
117117
118/* DAILY DEVIATIONS */
119type DailyDeviations struct {
120 HasMore bool
121 Strips []struct {
122 Codename, Title string
123 TitleType string
124 Deviations []Deviation
125 }
126 Deviations []Deviation
127}
128
129func DailyDeviationsFunc(page int) (dd DailyDeviations) {
130 ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd)
131 return
132}
133
118134/* SEARCH */
119135type Search struct {
120 Total int `json:"estTotal"`
121 Pages int // only for 'a' and 'g' scope.
136 Total int `json:"estTotal"`
137 Pages int // only for 'a' and 'g' scope.
138 HasMore bool
122139 Results []Deviation `json:"deviations,results"`
123140}
124141
@@ -170,38 +187,29 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search,
170187}
171188
172189/* PUPPY aka DeviantArt API */
173func puppy(data string) (string, error) {
174 // получение или обновление токена
175 update := func() (string, string, error) {
176 var cookie string
177 if cookie == "" {
178 req := request("https://www.deviantart.com/_puppy")
179
180 for _, content := range req.Cookies {
181 cookie = content.Raw
182 }
183 }
190// получение или обновление токена
191var cookie string
192var token string
184193
185 req := request("https://www.deviantart.com", cookie)
186 if req.Status != 200 {
187 return "", "", errors.New(req.Body)
188 }
194func UpdateCSRF() error {
195 if cookie == "" {
196 req := request("https://www.deviantart.com/_puppy")
189197
190 return cookie, req.Body[strings.Index(req.Body, "window.__CSRF_TOKEN__ = '")+25 : strings.Index(req.Body, "window.__XHR_LOCAL__")-3], nil
198 for _, content := range req.Cookies {
199 cookie = content.Raw
200 }
191201 }
192202
193 // использование токена
194 var (
195 cookie, token string
196 )
197 if cookie == "" || token == "" {
198 var e error
199 cookie, token, e = update()
200 if e != nil {
201 return "", e
202 }
203 req := request("https://www.deviantart.com", cookie)
204 if req.Status != 200 {
205 return errors.New(req.Body)
203206 }
207 token = req.Body[strings.Index(req.Body, "window.__CSRF_TOKEN__ = '")+25 : strings.Index(req.Body, "window.__XHR_LOCAL__")-3]
204208
209 return nil
210}
211
212func puppy(data string) (string, error) {
205213 var url strings.Builder
206214 url.WriteString("https://www.deviantart.com/_puppy/")
207215 url.WriteString(data)