| @@ -115,10 +115,27 @@ func AEmedia(name string, t rune) (string, error) { |
| 115 | 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 | 134 | /* SEARCH */ |
| 119 | 135 | type 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 |
| 122 | 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 | 189 | /* PUPPY aka DeviantArt API */ |
| 173 | | func 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 | // получение или обновление токена |
| 191 | var cookie string |
| 192 | var token string |
| 184 | 193 | |
| 185 | | req := request("https://www.deviantart.com", cookie) |
| 186 | | if req.Status != 200 { |
| 187 | | return "", "", errors.New(req.Body) |
| 188 | | } |
| 194 | func UpdateCSRF() error { |
| 195 | if cookie == "" { |
| 196 | req := request("https://www.deviantart.com/_puppy") |
| 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 | | // использование токена |
| 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) |
| 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 | 213 | var url strings.Builder |
| 206 | 214 | url.WriteString("https://www.deviantart.com/_puppy/") |
| 207 | 215 | url.WriteString(data) |