This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
forked from lwydyby/poe-api
/
constant.go
69 lines (58 loc) · 1.78 KB
/
constant.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
package poe_api
import (
"embed"
"io/fs"
"log"
"os"
"path/filepath"
"strings"
fhttp "github.com/bogdanfinn/fhttp"
)
const (
gqlURL = "https://poe.com/api/gql_POST"
gqlRecvURL = "https://poe.com/api/receive_POST"
homeURL = "https://poe.com"
settingsURL = "https://poe.com/api/settings"
)
//go:embed poe_graphql/*.graphql
var graphql embed.FS
var queries = make(map[string]string)
var logger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
var userAgent = "This will be ignored! See the README for info on how to set custom headers."
var headers = fhttp.Header{
"User-Agent": []string{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.82"},
"Accept": []string{"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"},
// "Accept-Encoding": []string{"gzip, deflate, br"},
// "Accept-Language": []string{"en-US,en;q=0.5"},
// "Te": []string{"trailers"},
// "Upgrade-Insecure-Requests": []string{"1"},
}
//var clientIdentifier = "firefox_102"
func init() {
loadQueries()
}
func loadQueries() {
queryFS, err := fs.Sub(graphql, "poe_graphql")
if err != nil {
panic(err)
}
// 遍历嵌入的查询文件
err = fs.WalkDir(queryFS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || filepath.Ext(path) != ".graphql" {
return nil
}
queryBytes, err := fs.ReadFile(queryFS, path)
if err != nil {
return err
}
// 将查询文件内容存储到 queries 映射中
queries[strings.TrimSuffix(d.Name(), filepath.Ext(d.Name()))] = string(queryBytes)
return nil
})
if err != nil {
panic(err)
}
}