2016-11-19 14:54:31 +00:00
|
|
|
package anime
|
|
|
|
|
|
|
|
import (
|
2017-06-19 18:59:02 +00:00
|
|
|
"net/http"
|
|
|
|
|
2016-11-19 14:54:31 +00:00
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-06-19 18:59:02 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2016-11-19 14:54:31 +00:00
|
|
|
)
|
|
|
|
|
2017-06-28 21:08:58 +00:00
|
|
|
const maxEpisodes = 26
|
|
|
|
const maxEpisodesLongSeries = 5
|
|
|
|
|
2017-06-16 23:25:02 +00:00
|
|
|
// Get anime page.
|
2016-11-19 14:54:31 +00:00
|
|
|
func Get(ctx *aero.Context) string {
|
2017-06-03 23:17:00 +00:00
|
|
|
id := ctx.Get("id")
|
2017-06-19 18:59:02 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2016-11-19 14:54:31 +00:00
|
|
|
anime, err := arn.GetAnime(id)
|
|
|
|
|
|
|
|
if err != nil {
|
2017-06-19 18:59:02 +00:00
|
|
|
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
2016-11-19 14:54:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 23:05:39 +00:00
|
|
|
tracks, err := arn.GetSoundTracksByTag("anime:" + anime.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Error fetching soundtracks", err)
|
|
|
|
}
|
|
|
|
|
2017-06-28 21:08:58 +00:00
|
|
|
episodesReversed := false
|
|
|
|
|
|
|
|
if len(anime.Episodes) > maxEpisodes {
|
|
|
|
episodesReversed = true
|
|
|
|
anime.Episodes = anime.Episodes[len(anime.Episodes)-maxEpisodesLongSeries-1:]
|
|
|
|
|
|
|
|
for i, j := 0, len(anime.Episodes)-1; i < j; i, j = i+1, j-1 {
|
|
|
|
anime.Episodes[i], anime.Episodes[j] = anime.Episodes[j], anime.Episodes[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.HTML(components.Anime(anime, tracks, user, episodesReversed))
|
2016-11-19 14:54:31 +00:00
|
|
|
}
|