| @@ -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 */ |
| |
119 | type DailyDeviations struct { |
| |
120 | HasMore bool |
| |
121 | Strips []struct { |
| |
122 | Codename, Title string |
| |
123 | TitleType string |
| |
124 | Deviations []Deviation |
| |
125 | } |
| |
126 | Deviations []Deviation |
| |
127 | } |
| |
128 | |
| |
129 | func DailyDeviationsFunc(page int) (dd DailyDeviations) { |
| |
130 | ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd) |
| |
131 | return |
| |
132 | } |
| |
133 | |
| 118 | /* SEARCH */ |
134 | /* SEARCH */ |
| 119 | type Search struct { |
135 | type 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 */ |
| 173 | func puppy(data string) (string, error) { |
190 | // получение или обновление токена |
| 174 | // получение или обновление токена |
191 | var cookie string |
| 175 | update := func() (string, string, error) { |
192 | var 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) |
194 | func 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 | |
| |
212 | func 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) |