48 lines
1.1 KiB
Go
Raw Normal View History

2017-12-04 21:07:13 +01:00
package episode
import (
2018-12-10 13:42:29 +09:00
"fmt"
2017-12-04 21:07:13 +01:00
"net/http"
"github.com/aerogo/aero"
2019-06-03 18:32:43 +09:00
"github.com/animenotifier/notify.moe/arn"
2017-12-04 21:07:13 +01:00
"github.com/animenotifier/notify.moe/components"
2019-06-03 20:17:09 +09:00
minio "github.com/minio/minio-go/v6"
2017-12-04 21:07:13 +01:00
)
// Get renders the anime episode.
2019-06-01 13:55:49 +09:00
func Get(ctx aero.Context) error {
2019-11-17 16:59:34 +09:00
user := arn.GetUserFromContext(ctx)
2017-12-04 21:07:13 +01:00
id := ctx.Get("id")
2019-08-28 17:06:42 +09:00
// Get episode
episode, err := arn.GetEpisode(id)
2017-12-04 21:07:13 +01:00
if err != nil {
2019-08-28 17:06:42 +09:00
return ctx.Error(http.StatusNotFound, "Episode not found", err)
2017-12-04 21:07:13 +01:00
}
// Get anime
2019-08-28 17:06:42 +09:00
anime := episode.Anime()
2017-12-04 21:07:13 +01:00
2019-08-28 17:06:42 +09:00
if anime == nil {
2017-12-04 21:07:13 +01:00
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
2018-12-10 13:42:29 +09:00
// Does the episode exist?
uploaded := false
2019-08-28 10:07:50 +09:00
if arn.Spaces != nil {
2019-08-28 17:06:42 +09:00
stat, err := arn.Spaces.StatObject("arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episode.Number), minio.StatObjectOptions{})
2018-12-10 13:42:29 +09:00
uploaded = (err == nil) && (stat.Size > 0)
}
2019-08-28 17:06:42 +09:00
_, episodeIndex := anime.Episodes().Find(episode.Number)
2017-12-04 21:07:13 +01:00
if episode == nil {
2018-07-07 12:42:00 +09:00
return ctx.Error(http.StatusNotFound, "Anime episode not found")
2017-12-04 21:07:13 +01:00
}
2019-08-28 17:06:42 +09:00
return ctx.HTML(components.Episode(anime, episode, episodeIndex, uploaded, user))
2017-12-04 21:07:13 +01:00
}