This commit is contained in:
daru
2022-04-18 16:57:45 +02:00
parent 994bccb068
commit c34da3b1ba

16
ober.go
View File

@@ -16,6 +16,7 @@ func RunWebserv() {
r := router.New()
r.GET("/", Headers(Start))
r.GET("/api/season", Headers(Season))
r.GET("/api/auth", Headers(AuthTest))
r.GET("/api/anime/{id}", Headers(AnimeGet))
r.GET("/api/animesearch/", Headers(AnimeSearchGet))
r.GET("/api/user/{user?}", Headers(UserGet))
@@ -41,6 +42,21 @@ func Start(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusOK)
}
func AuthTest(ctx *fasthttp.RequestCtx) {
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || string(ctx.Request.Header.ContentType()) != "application/json" {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
username := fmt.Sprintf("%s", ctx.UserValue("user"))
legit, _ := GheddoAuth(username, string(auth))
if !legit {
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
return
}
ctx.SetStatusCode(fasthttp.StatusOK)
}
func Season(ctx *fasthttp.RequestCtx) {
data, err := seasoncache.Get(seasonApiJikan)
if err != nil {