mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 17:29:54 +01:00
GET anime
This commit is contained in:
39
ober.go
39
ober.go
@@ -16,6 +16,7 @@ func RunWebserv() {
|
||||
r := router.New()
|
||||
r.GET("/", Start)
|
||||
r.GET("/api/season", Season)
|
||||
r.GET("/api/anime/{id}", AnimeGet)
|
||||
r.GET("/api/watch/{user?}", WatchGet)
|
||||
r.POST("/api/register", Register)
|
||||
r.POST("/api/watch/{user}", WatchPost)
|
||||
@@ -51,6 +52,44 @@ func Season(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
func AnimeGet(ctx *fasthttp.RequestCtx) {
|
||||
idVal := ctx.UserValue("id")
|
||||
if idVal == nil {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// check user exists
|
||||
malId, err := strconv.ParseInt(fmt.Sprintf("%s", idVal), 10, 64)
|
||||
if err != nil {
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// search season first
|
||||
anime, err := SearchSeason(malId)
|
||||
var bytes []byte
|
||||
if err != nil {
|
||||
_, bytes, err = GetAnimeDetailData(malId)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
bytes, err = json.Marshal(&anime)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
func WatchGet(ctx *fasthttp.RequestCtx) {
|
||||
usrVal := ctx.UserValue("user")
|
||||
var userId int64
|
||||
|
||||
Reference in New Issue
Block a user