-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.go
59 lines (49 loc) · 1.34 KB
/
admin.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
package view
import (
"appengine"
"appengine/datastore"
"github.com/OwenDurni/loltools/model"
"github.com/OwenDurni/loltools/util/errwrap"
"net/http"
)
func AdminIndexHandler(
w http.ResponseWriter, r *http.Request, args map[string]string) {
c := appengine.NewContext(r)
user, _, err := model.GetUser(c)
if HandleError(c, w, errwrap.Wrap(err)) {
return
}
ctx := struct {
ctxBase
RiotApiKey *model.RiotApiKey
GameStatsBacklogCount int
RiotRateLimit string
}{}
ctx.ctxBase.init(c, user)
ctx.ctxBase.Title = "Admin Console"
riotApiKey, err := model.GetRiotApiKey(c)
ctx.RiotApiKey = riotApiKey
ctx.ctxBase.AddError(errwrap.Wrap(err))
q := datastore.NewQuery("PlayerGameStats").
Filter("Saved =", false).
Filter("NotAvailable =", false).
KeysOnly()
gameStatsKeys, err := q.GetAll(c, nil)
ctx.GameStatsBacklogCount = len(gameStatsKeys)
ctx.ctxBase.AddError(errwrap.Wrap(err))
ctx.RiotRateLimit = model.RiotApiRateLimiter.DebugStr(c)
err = RenderTemplate(w, "admin.html", "base", ctx)
if HandleError(c, w, errwrap.Wrap(err)) {
return
}
}
func ApiAdminRiotKeySetHandler(
w http.ResponseWriter, r *http.Request, args map[string]string) {
c := appengine.NewContext(r)
apikey := r.FormValue("key")
err := model.SetRiotApiKey(c, apikey)
if ApiHandleError(c, w, err) {
return
}
HttpReplyOkEmpty(w)
}