summaryrefslogtreecommitdiff
path: root/misc.go
diff options
context:
space:
mode:
authorlost+skunk <[email protected]>2024-06-05 14:32:40 +0300
committerlost+skunk <[email protected]>2024-06-05 14:32:40 +0300
commit9b850886656bb2ecf192e6d9df63ea07d175de06 (patch)
tree342e0ab5a0bab961f3496be3ac14fe9909a3b977 /misc.go
parent66ab740d7fec430d97f69ab0ed52ba0f01973d46 (diff)
downloaddevianter-9b850886656bb2ecf192e6d9df63ea07d175de06.tar.gz
devianter-9b850886656bb2ecf192e6d9df63ea07d175de06.tar.bz2
devianter-9b850886656bb2ecf192e6d9df63ea07d175de06.zip
User implementation and particaly groups
Diffstat (limited to 'misc.go')
-rw-r--r--misc.go49
1 files changed, 35 insertions, 14 deletions
diff --git a/misc.go b/misc.go
index c847e44..d5f6793 100644
--- a/misc.go
+++ b/misc.go
@@ -3,11 +3,11 @@ package devianter
import (
"encoding/json"
"errors"
- "fmt"
"io"
"log"
"math"
"net/http"
+ "strconv"
"strings"
)
@@ -117,27 +117,44 @@ func AEmedia(name string, t rune) (string, error) {
/* SEARCH */
type search struct {
- Total int `json:"estTotal"`
- Pages int // only for 'a' scope.
- Deviations []deviantion
+ Total int `json:"estTotal"`
+ Pages int // only for 'a' and 'g' scope.
+ Results []deviantion `json:"deviations,results"`
}
-func Search(query, page string, scope rune) (ss search) {
+func Search(query string, page int, scope rune, user ...string) (ss search, e error) {
var url strings.Builder
+ e = nil
// о5 построение ссылок.
switch scope {
- case 'a':
+ case 'a': // поиск артов по названию
url.WriteString("dabrowse/search/all?q=")
- case 't':
+ case 't': // поиск артов по тегам
url.WriteString("dabrowse/networkbar/tag/deviations?tag=")
+ case 'g': // поиск артов пользователя или группы
+ if user != nil {
+ url.WriteString("dashared/gallection/search?username=")
+ for _, a := range user {
+ url.WriteString(a)
+ }
+ url.WriteString("&type=gallery&order=most-recent&init=true&limit=50&q=")
+ } else {
+ e = errors.New("Missing username (last argument)")
+ return
+ }
default:
- log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag.")
+ log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.")
}
url.WriteString(query)
- url.WriteString("&page=")
- url.WriteString(page)
+ if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код
+ url.WriteString("&page=")
+ } else { // иначе вместо страницы будет оффсет и страница умножится на 50
+ url.WriteString("&offset=")
+ page = 50 * page
+ }
+ url.WriteString(strconv.Itoa(page))
ujson(url.String(), &ss)
@@ -184,10 +201,14 @@ func puppy(data string) (string, error) {
}
}
- body := request(
- fmt.Sprintf("https://www.deviantart.com/_puppy/%s&csrf_token=%s&da_minor_version=20230710", data, token),
- cookie,
- )
+ var url strings.Builder
+ url.WriteString("https://www.deviantart.com/_puppy/")
+ url.WriteString(data)
+ url.WriteString("&csrf_token=")
+ url.WriteString(token)
+ url.WriteString("&da_minor_version=20230710")
+
+ body := request(url.String(), cookie)
// если код ответа не 200, возвращается ошибка
if body.Status != 200 {