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 {
15 Thread []struct { 15 Thread []struct {
16 Replies, Likes int 16 Replies, Likes int
17 ID int `json:"commentId"` 17 ID int `json:"commentId"`
18 Parent int `json:"ParrentId"` 18 Parent int `json:"parentId"`
19 19
20 Posted time 20 Posted time
21 Author bool `json:"isAuthorHighlited"` 21 Author bool `json:"isAuthorHighlited"`
deviantion.go +4 −2
@@ -97,8 +97,10 @@ func UrlFromMedia(m media) string {
97 url.WriteString("image") 97 url.WriteString("image")
98 url.WriteString(".gif") 98 url.WriteString(".gif")
99 } 99 }
100 url.WriteString("?token=") 100 if len(m.Token) > 0 {
101 url.WriteString(m.Token[0]) 101 url.WriteString("?token=")
102 url.WriteString(m.Token[0])
103 }
102 } 104 }
103 } 105 }
104 return url.String() 106 return url.String()
misc.go +36 −28
@@ -115,10 +115,27 @@ func AEmedia(name string, t rune) (string, error) {
115 return "", errors.New("User not exists") 115 return "", errors.New("User not exists")
116} 116}
117 117
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
118/* SEARCH */ 134/* SEARCH */
119type Search struct { 135type Search struct {
120 Total int `json:"estTotal"` 136 Total int `json:"estTotal"`
121 Pages int // only for 'a' and 'g' scope. 137 Pages int // only for 'a' and 'g' scope.
138 HasMore bool
122 Results []Deviation `json:"deviations,results"` 139 Results []Deviation `json:"deviations,results"`
123} 140}
124 141
@@ -170,38 +187,29 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search,
170} 187}
171 188
172/* PUPPY aka DeviantArt API */ 189/* PUPPY aka DeviantArt API */
173func puppy(data string) (string, error) { 190// получение или обновление токена
174 // получение или обновление токена 191var cookie string
175 update := func() (string, string, error) { 192var token string
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 }
184 193
185 req := request("https://www.deviantart.com", cookie) 194func UpdateCSRF() error {
186 if req.Status != 200 { 195 if cookie == "" {
187 return "", "", errors.New(req.Body) 196 req := request("https://www.deviantart.com/_puppy")
188 }
189 197
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 }
191 } 201 }
192 202
193 // использование токена 203 req := request("https://www.deviantart.com", cookie)
194 var ( 204 if req.Status != 200 {
195 cookie, token string 205 return errors.New(req.Body)
196 )
197 if cookie == "" || token == "" {
198 var e error
199 cookie, token, e = update()
200 if e != nil {
201 return "", e
202 }
203 } 206 }
207 token = req.Body[strings.Index(req.Body, "window.__CSRF_TOKEN__ = '")+25 : strings.Index(req.Body, "window.__XHR_LOCAL__")-3]
204 208
209 return nil
210}
211
212func puppy(data string) (string, error) {
205 var url strings.Builder 213 var url strings.Builder
206 url.WriteString("https://www.deviantart.com/_puppy/") 214 url.WriteString("https://www.deviantart.com/_puppy/")
207 url.WriteString(data) 215 url.WriteString(data)