From cec788554afe20b8c67357ede087b3c5c543be89 Mon Sep 17 00:00:00 2001 From: lost+skunk Date: Fri, 14 Jun 2024 20:05:21 +0300 Subject: Daily Deviations --- misc.go | 64 ++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'misc.go') diff --git a/misc.go b/misc.go index 5976e80..35251f3 100644 --- a/misc.go +++ b/misc.go @@ -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) -- cgit v1.2.3