Episode page improvements

This commit is contained in:
2018-12-10 13:42:29 +09:00
parent 20a4e31999
commit 2b8288e208
8 changed files with 1166 additions and 29 deletions

View File

@ -1,14 +1,34 @@
package episode
import (
"fmt"
"log"
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
minio "github.com/minio/minio-go"
)
var spaces *minio.Client
func init() {
go func() {
var err error
endpoint := "sfo2.digitaloceanspaces.com"
ssl := true
// Initiate a client using DigitalOcean Spaces.
spaces, err = minio.New(endpoint, arn.APIKeys.S3.ID, arn.APIKeys.S3.Secret, ssl)
if err != nil {
log.Fatal(err)
}
}()
}
// Get renders the anime episode.
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
@ -33,11 +53,19 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
}
// Does the episode exist?
uploaded := false
if spaces != nil {
stat, err := spaces.StatObject("arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episodeNumber), minio.StatObjectOptions{})
uploaded = (err == nil) && (stat.Size > 0)
}
episode, episodeIndex := animeEpisodes.Find(episodeNumber)
if episode == nil {
return ctx.Error(http.StatusNotFound, "Anime episode not found")
}
return ctx.HTML(components.AnimeEpisode(anime, episode, episodeIndex, user))
return ctx.HTML(components.AnimeEpisode(anime, episode, episodeIndex, uploaded, user))
}