-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.go
63 lines (61 loc) · 1.74 KB
/
handler.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
package main
import (
"OwlGramServer/consts"
"OwlGramServer/handlers"
"OwlGramServer/telegram/github"
"github.com/valyala/fasthttp"
"strings"
)
func handler(ctx *fasthttp.RequestCtx) {
ip := string(ctx.Request.Header.Peek("X-Forwarded-For"))
if consts.IsDebug && ip != consts.SshIP {
handlers.Forbidden(ctx)
return
}
requestedPath := string(ctx.Path())
if ctx.IsGet() {
switch requestedPath {
case "/get_changelogs":
handlers.Changelogs(ctx, updatesClient)
case "/version":
handlers.Updates(ctx, updatesClient)
case "/dc_status":
handlers.DcStatus(ctx, tgChecker)
case "/language_pack":
handlers.LanguagePack(ctx, crowdinClient)
case "/language_version":
handlers.LanguageVersion(ctx, crowdinClient)
case "/webapp":
handlers.WebApp(ctx, crowdinClient, botClient.TelegramClient)
case "/emoji_packs":
handlers.EmojiPacks(ctx, emojiClient)
default:
if len(requestedPath) > 14 && strings.HasPrefix(requestedPath, "/previews/") &&
strings.HasSuffix(requestedPath, ".png") {
requestedPath = requestedPath[10 : len(requestedPath)-4]
handlers.EmojiPreview(ctx, requestedPath, emojiClient)
return
} else if len(requestedPath) > 10 && strings.HasPrefix(requestedPath, "/packs/") &&
strings.HasSuffix(requestedPath, ".zip") {
requestedPath = requestedPath[7 : len(requestedPath)-4]
handlers.EmojiFile(ctx, requestedPath, emojiClient)
return
}
handlers.NotFound(ctx)
}
} else if ctx.IsPost() {
switch string(ctx.Path()) {
case "/saveDcData":
handlers.SaveDCData(ctx, tgChecker)
case "/notify_upload":
handlers.NotifyUpload(ctx, botClient)
case "/notify_github":
github.SendPushEvent(ctx)
default:
handlers.NotFound(ctx)
break
}
} else {
handlers.Forbidden(ctx)
}
}