Episode page improvements
This commit is contained in:
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user