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