forked from 764763903a/xdd-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ua.go
43 lines (37 loc) · 1 KB
/
ua.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
package models
import (
"strings"
"github.com/beego/beego/v2/adapter/logs"
"github.com/beego/beego/v2/client/httplib"
)
var ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 SP-engine/2.14.0 main%2F1.0 baiduboxapp/11.18.0.16 (Baidu; P2 13.3.1) NABar/0.0"
func initUserAgent() {
u := &UserAgent{}
err := db.Order("id desc").First(u).Error
if err != nil && strings.Contains(err.Error(), "converting") {
db.Migrator().DropTable(&UserAgent{})
Daemon()
}
if u.Content != "" {
ua = u.Content
} else {
if Config.UserAgent != "" {
logs.Info("使用自定义User-Agent")
ua = Config.UserAgent
} else {
logs.Info("更新User-Agent")
var err error
ua, err = httplib.Get(GhProxy + "https://raw.githubusercontent.com/764763903a/xdd-plus/main/ua.txt").String()
if err != nil {
logs.Info("更新User-Agent失败")
}
}
}
}
func GetUserAgent() string {
return ua
}
type UserAgent struct {
ID int
Content string
}