Use a CDN for faster AMV delivery

This commit is contained in:
2019-08-28 10:07:50 +09:00
parent 1b0bb6fdbd
commit bc4e67f718
9 changed files with 91 additions and 90 deletions

@ -2,7 +2,6 @@ package episode
import (
"fmt"
"log"
"net/http"
"github.com/aerogo/aero"
@ -12,27 +11,6 @@ import (
minio "github.com/minio/minio-go/v6"
)
var spaces *minio.Client
func init() {
if arn.APIKeys.S3.ID == "" || arn.APIKeys.S3.Secret == "" {
return
}
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) error {
user := utils.GetUser(ctx)
@ -60,8 +38,8 @@ func Get(ctx aero.Context) error {
// 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{})
if arn.Spaces != nil {
stat, err := arn.Spaces.StatObject("arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episodeNumber), minio.StatObjectOptions{})
uploaded = (err == nil) && (stat.Size > 0)
}