GetAnimeDetail

This commit is contained in:
daru
2022-04-15 03:10:05 +02:00
parent 7307b3c808
commit c8e0b0af2d
4 changed files with 80 additions and 1 deletions

22
ober.go
View File

@@ -181,7 +181,7 @@ func Register(ctx *fasthttp.RequestCtx) {
func WatchPost(ctx *fasthttp.RequestCtx) {
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" {
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || string(ctx.Request.Header.ContentType()) != "application/json" {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
@@ -190,6 +190,26 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
return
}
body := ctx.PostBody()
var animes []Anime
err := json.Unmarshal(body, &animes)
if err != nil || len(animes) == 0 {
ctx.WriteString(err.Error())
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
for _, anime := range animes {
// TODO iterate animes
detail, _, err := GetAnimeDetailData(anime.Anime)
if err != nil {
ctx.WriteString(err.Error())
ctx.SetStatusCode(fasthttp.StatusNotFound)
return
}
fmt.Printf("%+v\n", detail)
}
}
func GheddoAuth(username, auth string) bool {