-
Notifications
You must be signed in to change notification settings - Fork 97
/
api.go
123 lines (117 loc) · 2.67 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package hh_lol_prophet
import (
"encoding/json"
"strings"
"github.com/gin-gonic/gin"
"github.com/real-web-world/hh-lol-prophet/conf"
"github.com/real-web-world/hh-lol-prophet/global"
ginApp "github.com/real-web-world/hh-lol-prophet/pkg/gin"
"github.com/real-web-world/hh-lol-prophet/services/db/models"
"github.com/real-web-world/hh-lol-prophet/services/lcu"
)
type (
Api struct {
p *Prophet
}
summonerNameReq struct {
SummonerName string `json:"summonerName"`
}
)
func (api Api) ProphetActiveMid(c *gin.Context) {
app := ginApp.GetApp(c)
if !api.p.lcuActive {
app.ErrorMsg("请检查lol客户端是否已启动")
return
}
c.Next()
}
func (api Api) QueryHorseBySummonerName(c *gin.Context) {
app := ginApp.GetApp(c)
d := &summonerNameReq{}
if err := c.ShouldBind(d); err != nil {
app.ValidError(err)
return
}
summonerName := strings.TrimSpace(d.SummonerName)
var summoner *lcu.Summoner
if summonerName == "" {
if api.p.currSummoner == nil {
app.ErrorMsg("系统错误")
return
}
summoner = lcu.ConvertCurrSummonerToSummoner(api.p.currSummoner)
} else {
info, err := lcu.QuerySummonerByName(summonerName)
if err != nil || info.SummonerId <= 0 {
app.ErrorMsg("未查询到召唤师")
return
}
summoner = info
}
scoreInfo, err := GetUserScore(summoner)
if err != nil {
app.CommonError(err)
return
}
scoreCfg := global.GetScoreConf()
clientCfg := global.GetClientConf()
var horse string
for i, v := range scoreCfg.Horse {
if scoreInfo.Score >= v.Score {
horse = clientCfg.HorseNameConf[i]
break
}
}
app.Data(gin.H{
"score": scoreInfo.Score,
"currKDA": scoreInfo.CurrKDA,
"horse": horse,
})
}
func (api Api) CopyHorseMsgToClipBoard(c *gin.Context) {
app := ginApp.GetApp(c)
app.Success()
}
func (api Api) GetAllConf(c *gin.Context) {
app := ginApp.GetApp(c)
app.Data(global.GetClientConf())
}
func (api Api) UpdateClientConf(c *gin.Context) {
app := ginApp.GetApp(c)
d := &conf.UpdateClientConfReq{}
if err := c.ShouldBind(d); err != nil {
app.ValidError(err)
return
}
cfg := global.SetClientConf(*d)
bts, _ := json.Marshal(cfg)
m := models.Config{}
err := m.Update(models.LocalClientConfKey, string(bts))
if err != nil {
app.CommonError(err)
return
}
app.Success()
}
func (api Api) DevHand(c *gin.Context) {
app := ginApp.GetApp(c)
app.Data(gin.H{
"buffge": 23456,
})
}
func (api Api) GetAppInfo(c *gin.Context) {
app := ginApp.GetApp(c)
app.Data(global.AppBuildInfo)
}
func (api Api) GetLcuAuthInfo(c *gin.Context) {
app := ginApp.GetApp(c)
port, token, err := lcu.GetLolClientApiInfo()
if err != nil {
app.CommonError(err)
return
}
app.Data(gin.H{
"token": token,
"port": port,
})
}