2017-12-04 20:07:13 +00:00
|
|
|
package episode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get renders the anime episode.
|
|
|
|
func Get(ctx *aero.Context) string {
|
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
id := ctx.Get("id")
|
|
|
|
episodeNumber, err := ctx.GetInt("episode-number")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusBadRequest, "Episode is not a number", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get anime
|
|
|
|
anime, err := arn.GetAnime(id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get anime episodes
|
|
|
|
animeEpisodes, err := arn.GetAnimeEpisodes(id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
|
|
|
|
}
|
|
|
|
|
2018-07-07 05:24:34 +00:00
|
|
|
episode, episodeIndex := animeEpisodes.Find(episodeNumber)
|
2017-12-04 20:07:13 +00:00
|
|
|
|
|
|
|
if episode == nil {
|
2018-07-07 03:42:00 +00:00
|
|
|
return ctx.Error(http.StatusNotFound, "Anime episode not found")
|
2017-12-04 20:07:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 07:19:06 +00:00
|
|
|
return ctx.HTML(components.AnimeEpisode(anime, episode, episodeIndex, user))
|
2017-12-04 20:07:13 +00:00
|
|
|
}
|