mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-15 20:59:53 +01:00
GET Auth
This commit is contained in:
16
ober.go
16
ober.go
@@ -16,6 +16,7 @@ func RunWebserv() {
|
|||||||
r := router.New()
|
r := router.New()
|
||||||
r.GET("/", Headers(Start))
|
r.GET("/", Headers(Start))
|
||||||
r.GET("/api/season", Headers(Season))
|
r.GET("/api/season", Headers(Season))
|
||||||
|
r.GET("/api/auth", Headers(AuthTest))
|
||||||
r.GET("/api/anime/{id}", Headers(AnimeGet))
|
r.GET("/api/anime/{id}", Headers(AnimeGet))
|
||||||
r.GET("/api/animesearch/", Headers(AnimeSearchGet))
|
r.GET("/api/animesearch/", Headers(AnimeSearchGet))
|
||||||
r.GET("/api/user/{user?}", Headers(UserGet))
|
r.GET("/api/user/{user?}", Headers(UserGet))
|
||||||
@@ -41,6 +42,21 @@ func Start(ctx *fasthttp.RequestCtx) {
|
|||||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
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) {
|
func Season(ctx *fasthttp.RequestCtx) {
|
||||||
data, err := seasoncache.Get(seasonApiJikan)
|
data, err := seasoncache.Get(seasonApiJikan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user