Removed Spaces CDN

This commit is contained in:
2024-08-09 12:09:51 +02:00
parent aa87e8c65f
commit f1697323fc
11 changed files with 106 additions and 150 deletions

View File

@ -1,16 +1,14 @@
package arn
import (
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"github.com/aerogo/nano"
"github.com/animenotifier/notify.moe/arn/video"
"github.com/minio/minio-go/v7"
)
// AMV is an anime music video.
@ -39,13 +37,7 @@ func (amv *AMV) Link() string {
// VideoLink returns the permalink for the video file.
func (amv *AMV) VideoLink() string {
domain := "arn.sfo2.cdn"
if amv.IsDraft {
domain = "arn.sfo2"
}
return fmt.Sprintf("https://%s.digitaloceanspaces.com/videos/amvs/%s", domain, amv.File)
return fmt.Sprintf("https://notify.moe/videos/amvs/%s", amv.File)
}
// TitleByUser returns the preferred title for the given user.
@ -56,17 +48,13 @@ func (amv *AMV) TitleByUser(user *User) string {
// SetVideoReader sets the bytes for the video file by reading them from the reader.
func (amv *AMV) SetVideoReader(reader io.Reader) error {
fileName := amv.ID + ".webm"
pattern := amv.ID + ".*.webm"
file, err := os.CreateTemp("", pattern)
file, err := os.Create(filepath.Join(Root, "videos", "amvs", fileName))
if err != nil {
return err
}
filePath := file.Name()
defer os.Remove(filePath)
// Write file contents
defer file.Close()
_, err = io.Copy(file, reader)
if err != nil {
@ -74,56 +62,59 @@ func (amv *AMV) SetVideoReader(reader io.Reader) error {
}
// Run mkclean
optimizedFile := filePath + ".optimized"
defer os.Remove(optimizedFile)
// optimizedFile := filePath + ".optimized"
// defer os.Remove(optimizedFile)
cmd := exec.Command(
"mkclean",
"--doctype", "4",
"--keep-cues",
"--optimize",
filePath,
optimizedFile,
)
// cmd := exec.Command(
// "mkclean",
// "--doctype", "4",
// "--keep-cues",
// "--optimize",
// filePath,
// optimizedFile,
// )
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
// cmd.Stdin = os.Stdin
err = cmd.Start()
// err = cmd.Start()
if err != nil {
return err
}
// if err != nil {
// return err
// }
err = cmd.Wait()
// err = cmd.Wait()
if err != nil {
return err
}
// if err != nil {
// return err
// }
// Refresh video file info
info, err := video.GetInfo(optimizedFile)
// info, err := video.GetInfo(optimizedFile)
if err != nil {
return err
}
// if err != nil {
// return err
// }
// Is our storage server available?
if Spaces == nil {
return errors.New("File storage client has not been initialized")
}
// // Is our storage server available?
// if Spaces == nil {
// return errors.New("File storage client has not been initialized")
// }
// Make sure the file is public
userMetaData := map[string]string{
"x-amz-acl": "public-read",
}
// // Make sure the file is public
// userMetaData := map[string]string{
// "x-amz-acl": "public-read",
// }
// Upload the file to our storage server
_, err = Spaces.FPutObject(context.TODO(), "arn", fmt.Sprintf("videos/amvs/%s.webm", amv.ID), optimizedFile, minio.PutObjectOptions{
ContentType: "video/webm",
UserMetadata: userMetaData,
})
// // Upload the file to our storage server
// _, err = Spaces.FPutObject(context.TODO(), "arn", , optimizedFile, minio.PutObjectOptions{
// ContentType: "video/webm",
// UserMetadata: userMetaData,
// })
// Refresh video file info
info, err := video.GetInfo(fileName)
if err != nil {
return err
@ -190,7 +181,7 @@ func (amv *AMV) Publish() error {
}
// No file uploaded
_, err := Spaces.StatObject(context.TODO(), "arn", fmt.Sprintf("videos/amvs/%s", amv.File), minio.StatObjectOptions{})
_, err := os.Stat(filepath.Join(Root, "videos", "amvs", amv.File))
if err != nil {
return errors.New("You need to upload a WebM file for this AMV")

View File

@ -1,14 +1,14 @@
package arn
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"reflect"
"github.com/aerogo/aero"
"github.com/aerogo/api"
"github.com/minio/minio-go/v7"
)
// Force interface implementations
@ -104,8 +104,8 @@ func (amv *AMV) Delete() error {
}
// Remove file
if amv.File != "" && Spaces != nil {
err := Spaces.RemoveObject(context.TODO(), "arn", fmt.Sprintf("videos/amvs/%s", amv.File), minio.RemoveObjectOptions{})
if amv.File != "" {
err := os.Remove(filepath.Join(Root, "videos", "amvs", amv.File))
if err != nil {
return err

View File

@ -110,5 +110,5 @@ func init() {
anilist.APIKeySecret = APIKeys.AniList.Secret
// Initialize file storage
initSpaces()
// initSpaces()
}

View File

@ -1,33 +1,33 @@
package arn
import (
"log"
// import (
// "log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
// "github.com/minio/minio-go/v7"
// "github.com/minio/minio-go/v7/pkg/credentials"
// )
// Spaces represents our file storage server.
var Spaces *minio.Client
// // Spaces represents our file storage server.
// var Spaces *minio.Client
// initSpaces starts our file storage client.
func initSpaces() {
if APIKeys.S3.ID == "" || APIKeys.S3.Secret == "" {
return
}
// // initSpaces starts our file storage client.
// func initSpaces() {
// if APIKeys.S3.ID == "" || APIKeys.S3.Secret == "" {
// return
// }
go func() {
var err error
endpoint := "sfo2.digitaloceanspaces.com"
// go func() {
// var err error
// endpoint := "sfo2.digitaloceanspaces.com"
// Initiate a client using DigitalOcean Spaces.
Spaces, err = minio.New(endpoint, &minio.Options{
Secure: true,
Creds: credentials.NewStaticV4(APIKeys.S3.ID, APIKeys.S3.Secret, ""),
})
// // Initiate a client using DigitalOcean Spaces.
// Spaces, err = minio.New(endpoint, &minio.Options{
// Secure: true,
// Creds: credentials.NewStaticV4(APIKeys.S3.ID, APIKeys.S3.Secret, ""),
// })
if err != nil {
log.Fatal(err)
}
}()
}
// if err != nil {
// log.Fatal(err)
// }
// }()
// }