diff options
| author | lost+skunk <[email protected]> | 2024-06-14 20:05:21 +0300 |
|---|---|---|
| committer | lost+skunk <[email protected]> | 2024-06-14 20:05:21 +0300 |
| commit | cec788554afe20b8c67357ede087b3c5c543be89 (patch) | |
| tree | b41e26b4e2c50cb1159c0084d2800793ca278046 /misc.go | |
| parent | 8f645d7ccb01c15650958f2f9dd14f15f9afd72b (diff) | |
| download | devianter-cec788554afe20b8c67357ede087b3c5c543be89.tar.gz devianter-cec788554afe20b8c67357ede087b3c5c543be89.tar.bz2 devianter-cec788554afe20b8c67357ede087b3c5c543be89.zip | |
Daily Deviations
Diffstat (limited to 'misc.go')
| -rw-r--r-- | misc.go | 64 |
1 files changed, 36 insertions, 28 deletions
@@ -115,10 +115,27 @@ func AEmedia(name string, t rune) (string, error) { return "", errors.New("User not exists") } +/* DAILY DEVIATIONS */ +type DailyDeviations struct { + HasMore bool + Strips []struct { + Codename, Title string + TitleType string + Deviations []Deviation + } + Deviations []Deviation +} + +func DailyDeviationsFunc(page int) (dd DailyDeviations) { + ujson("dabrowse/networkbar/rfy/deviations?page="+strconv.Itoa(page), &dd) + return +} + /* SEARCH */ type Search struct { - Total int `json:"estTotal"` - Pages int // only for 'a' and 'g' scope. + Total int `json:"estTotal"` + Pages int // only for 'a' and 'g' scope. + HasMore bool Results []Deviation `json:"deviations,results"` } @@ -170,38 +187,29 @@ func SearchFunc(query string, page int, scope rune, user ...string) (ss Search, } /* PUPPY aka DeviantArt API */ -func puppy(data string) (string, error) { - // получение или обновление токена - update := func() (string, string, error) { - var cookie string - if cookie == "" { - req := request("https://www.deviantart.com/_puppy") - - for _, content := range req.Cookies { - cookie = content.Raw - } - } +// получение или обновление токена +var cookie string +var token string - req := request("https://www.deviantart.com", cookie) - if req.Status != 200 { - return "", "", errors.New(req.Body) - } +func UpdateCSRF() error { + if cookie == "" { + req := request("https://www.deviantart.com/_puppy") - return cookie, req.Body[strings.Index(req.Body, "window.__CSRF_TOKEN__ = '")+25 : strings.Index(req.Body, "window.__XHR_LOCAL__")-3], nil + for _, content := range req.Cookies { + cookie = content.Raw + } } - // использование токена - var ( - cookie, token string - ) - if cookie == "" || token == "" { - var e error - cookie, token, e = update() - if e != nil { - return "", e - } + req := request("https://www.deviantart.com", cookie) + if req.Status != 200 { + return errors.New(req.Body) } + token = req.Body[strings.Index(req.Body, "window.__CSRF_TOKEN__ = '")+25 : strings.Index(req.Body, "window.__XHR_LOCAL__")-3] + return nil +} + +func puppy(data string) (string, error) { var url strings.Builder url.WriteString("https://www.deviantart.com/_puppy/") url.WriteString(data) |
