forked from 764763903a/xdd-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (83 loc) · 3.03 KB
/
main.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
package main
import (
"io/ioutil"
"os"
"strings"
"time"
"github.com/beego/beego/v2/client/httplib"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
"github.com/cdle/xdd/controllers"
"github.com/cdle/xdd/models"
"github.com/cdle/xdd/qbot"
)
var theme = ""
func main() {
go func() {
models.Save <- &models.JdCookie{}
}()
web.Get("/count", func(ctx *context.Context) {
ctx.WriteString(models.Count())
})
web.Get("/", func(ctx *context.Context) {
if models.Config.Theme == "" {
models.Config.Theme = models.GhProxy + "https://ghproxy.com/https://raw.githubusercontent.com/764763903a/xdd-plus/main/theme/admin.html"
}
if theme != "" {
ctx.WriteString(theme)
return
}
if strings.Contains(models.Config.Theme, "http") {
logs.Info("下载最新主题")
s, _ := httplib.Get(models.Config.Theme).String()
if s != "" {
theme = s
ctx.WriteString(s)
return
}
logs.Warn("主题下载失败,使用默认主题")
}
f, err := os.Open(models.Config.Theme)
if err == nil {
d, _ := ioutil.ReadAll(f)
theme = string(d)
ctx.WriteString(string(d))
return
}
})
web.Router("/api/login/qrcode", &controllers.LoginController{}, "get:GetQrcode")
web.Router("/api/login/qrcode.png", &controllers.LoginController{}, "get:GetQrcode")
web.Router("/api/login/qrcode1", &controllers.LoginController{}, "get:GetQrcode1")
web.Router("/api/login/query", &controllers.LoginController{}, "get:Query")
web.Router("/api/login/cookie", &controllers.LoginController{}, "get:Cookie")
web.Router("/api/login/admin", &controllers.LoginController{}, "post:IsAdmin")
web.Router("/api/login/cklogin", &controllers.LoginController{}, "post:CkLogin")
web.Router("/api/login/smslogin", &controllers.LoginController{}, "post:SMSLogin")
web.Router("/api/getUserInfo", &controllers.LoginController{}, "post:GetUserInfo")
web.Router("/api/getUserInfo", &controllers.LoginController{}, "get:GetUserInfo")
web.Router("/api/account", &controllers.AccountController{}, "get:List")
web.Router("/api/account", &controllers.AccountController{}, "post:CreateOrUpdate")
web.Router("/admin", &controllers.AccountController{}, "get:Admin")
web.Router("/admin", &controllers.AccountController{}, "post:Admin")
web.Router("/userCenter", &controllers.AccountController{}, "get:UserCenter")
web.Router("/userCenter", &controllers.AccountController{}, "post:UserCenter")
if models.Config.Static == "" {
models.Config.Static = "./static"
}
web.BConfig.WebConfig.StaticDir["/static"] = models.Config.Static
web.BConfig.AppName = models.AppName
web.BConfig.WebConfig.AutoRender = false
web.BConfig.CopyRequestBody = true
web.BConfig.WebConfig.Session.SessionOn = true
web.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600
web.BConfig.WebConfig.Session.SessionName = models.AppName
go func() {
time.Sleep(time.Second * 4)
(&models.JdCookie{}).Push("小滴滴已启动")
}()
if models.Config.QQID != 0 || models.Config.QQGroupID != 0 {
go qbot.Main()
}
web.Run()
}