forked from Sora233/DDBOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
91 lines (81 loc) · 2.02 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package lolicon_pool
import (
"github.com/starskim/DDBOT/proxy_pool"
"github.com/starskim/DDBOT/requests"
"github.com/starskim/DDBOT/utils"
"github.com/starskim/MiraiGo-Template/config"
"time"
)
const Host = "https://api.lolicon.app/setu"
type R18Type int
const (
R18Off R18Type = iota
R18On
//R18Mix
)
func (r R18Type) String() string {
switch r {
case R18Off:
return "R18Off"
case R18On:
return "R18On"
//case R18Mix:
// return "R18Mix"
default:
return "Unknown"
}
}
type Request struct {
Apikey string `json:"apikey"`
R18 int `json:"r18"`
Keyword string `json:"keyword"`
Num int `json:"num"`
Proxy string `json:"proxy"`
Size1200 bool `json:"size1200"`
}
type Setu struct {
Pid int `json:"pid"`
P int `json:"p"`
Uid int `json:"uid"`
Title string `json:"title"`
Author string `json:"author"`
Url string `json:"url"`
R18 bool `json:"r18"`
Width int `json:"width"`
Height int `json:"height"`
Tags []string `json:"tags"`
}
func (s *Setu) Content() ([]byte, error) {
return utils.ImageGet(s.Url, requests.HeaderOption("referer", "https://www.pixiv.net"), requests.ProxyOption(proxy_pool.PreferOversea))
}
type Response struct {
Code int `json:"code"`
Msg string `json:"msg"`
Quota int `json:"quota"`
QuotaMinTTL int `json:"quota_min_ttl"`
Count int `json:"count"`
Data []*Setu `json:"data"`
}
func LoliconAppSetu(apikey string, R18 R18Type, keyword string, num int) (*Response, error) {
params, err := utils.ToParams(&Request{
Apikey: apikey,
R18: int(R18),
Keyword: keyword,
Num: num,
Proxy: config.GlobalConfig.GetString("loliconPool.proxy"),
Size1200: true,
})
if err != nil {
return nil, err
}
apiResp := new(Response)
err = requests.Get(Host, params, apiResp,
requests.RetryOption(3),
requests.TimeoutOption(time.Second*15),
requests.ProxyOption(proxy_pool.PreferOversea),
)
if err != nil {
return nil, err
}
return apiResp, nil
}