mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 10:39:53 +01:00
GET anime
This commit is contained in:
@@ -17,6 +17,7 @@ func GetAnimeDetailData(animeId int64) (*Anime, []byte, error) {
|
|||||||
key := strconv.FormatInt(animeId, 10)
|
key := strconv.FormatInt(animeId, 10)
|
||||||
data, err := animeCache.Get(key)
|
data, err := animeCache.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = nil
|
||||||
dataMal, err := GetDataMal(animeApiMal + key + "?fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,media_type,status,genres,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,studios")
|
dataMal, err := GetDataMal(animeApiMal + key + "?fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,media_type,status,genres,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,studios")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|||||||
39
ober.go
39
ober.go
@@ -16,6 +16,7 @@ func RunWebserv() {
|
|||||||
r := router.New()
|
r := router.New()
|
||||||
r.GET("/", Start)
|
r.GET("/", Start)
|
||||||
r.GET("/api/season", Season)
|
r.GET("/api/season", Season)
|
||||||
|
r.GET("/api/anime/{id}", AnimeGet)
|
||||||
r.GET("/api/watch/{user?}", WatchGet)
|
r.GET("/api/watch/{user?}", WatchGet)
|
||||||
r.POST("/api/register", Register)
|
r.POST("/api/register", Register)
|
||||||
r.POST("/api/watch/{user}", WatchPost)
|
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) {
|
func WatchGet(ctx *fasthttp.RequestCtx) {
|
||||||
usrVal := ctx.UserValue("user")
|
usrVal := ctx.UserValue("user")
|
||||||
var userId int64
|
var userId int64
|
||||||
|
|||||||
Reference in New Issue
Block a user