Removed Spaces CDN

This commit is contained in:
Eduard Urbach 2024-08-09 12:09:51 +02:00
parent aa87e8c65f
commit f1697323fc
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
11 changed files with 106 additions and 150 deletions

28
.gitignore vendored
View File

@ -1,24 +1,16 @@
# General ignore patterns
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
*.prof
# Log files
*.log
# JS files are generated from TS files
*.js
*
!*/
!*.go
!*.mod
!*.sum
!*.md
!*.pixy
!*.scarlet
!*.ts
!.gitignore
# Components are generated by the "pack" tool
/components
# Personal startup settings for each contributor
/custom.go
# Server binary
/notify.moe

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)
// }
// }()
// }

9
go.mod
View File

@ -37,7 +37,6 @@ require (
github.com/itchyny/gojq v0.12.16
github.com/json-iterator/go v1.1.12
github.com/logpacker/PayPal-Go-SDK v1.1.4
github.com/minio/minio-go/v7 v7.0.74
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/mssola/user_agent v0.6.0
github.com/pariz/gountries v0.1.6
@ -62,23 +61,18 @@ require (
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/russross/blackfriday v2.0.0+incompatible // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
@ -86,6 +80,5 @@ require (
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

17
go.sum
View File

@ -128,21 +128,15 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gojp/kana v0.0.0-20190509023103-3514925d577b/go.mod h1:kWp5hDdJQqnZ2E3SQNQe+iejY63SZ+JdlbnW+qn7vxY=
github.com/gomodule/oauth1 v0.2.0 h1:/nNHAD99yipOEspQFbAnNmwGTZ1UNXiD/+JLxwx79fo=
github.com/gomodule/oauth1 v0.2.0/go.mod h1:4r/a8/3RkhMBxJQWL5qzbOEcaQmNPIkNoI7P8sXeI08=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@ -158,9 +152,6 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
@ -181,10 +172,6 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.74 h1:fTo/XlPBTSpo3BAMshlwKL5RspXRv9us5UeHEGYCFe0=
github.com/minio/minio-go/v7 v7.0.74/go.mod h1:qydcVzV8Hqtj1VtEocfxbmVFa2siu6HGa+LDEPogjD8=
github.com/mmcloughlin/avo v0.0.0-20190731014047-bb615f61ce85/go.mod h1:lf5GMZxA5kz8dnCweJuER5Rmbx6dDu6qvw0fO3uYKK8=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
@ -203,8 +190,6 @@ github.com/pkg/profile v1.3.0/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/russross/blackfriday v2.0.0+incompatible h1:cBXrhZNUf9C+La9/YpS+UHpUT8YD6Td9ZMSU9APFcsk=
github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
@ -304,8 +289,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190106171756-3ef68632349c/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

View File

@ -1,13 +1,11 @@
package episode
import (
"fmt"
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/components"
minio "github.com/minio/minio-go/v7"
)
// Get renders the anime episode.
@ -32,10 +30,10 @@ func Get(ctx aero.Context) error {
// Does the episode exist?
uploaded := false
if arn.Spaces != nil {
stat, err := arn.Spaces.StatObject(ctx.Request().Context(), "arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episode.Number), minio.StatObjectOptions{})
uploaded = (err == nil) && (stat.Size > 0)
}
// if arn.Spaces != nil {
// stat, err := arn.Spaces.StatObject(ctx.Request().Context(), "arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episode.Number), minio.StatObjectOptions{})
// uploaded = (err == nil) && (stat.Size > 0)
// }
_, episodeIndex := anime.Episodes().Find(episode.Number)

View File

@ -12,7 +12,7 @@ component Episode(anime *arn.Anime, episode *arn.Episode, episodeIndex int, uplo
if uploaded
.video-container(id="stream-test")
video.video.lazy.action(data-action="toggleFullscreen", data-trigger="dblclick", data-id="stream-test")
source(data-src=fmt.Sprintf("https://arn.sfo2.cdn.digitaloceanspaces.com/videos/anime/%s/%d.webm", anime.ID, episode.Number), data-type="video/webm")
source(data-src=fmt.Sprintf("https://notify.moe/videos/anime/%s/%d.webm", anime.ID, episode.Number), data-type="video/webm")
track(label="English", kind="subtitles", srclang="en", src=fmt.Sprintf("/anime/%s/episode/%d/subtitles/en", anime.ID, episode.Number), default)
VideoControls("stream-test", time.Duration(0))

View File

@ -1,18 +1,16 @@
package episode
import (
"fmt"
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn"
minio "github.com/minio/minio-go/v7"
)
// Subtitles returns the subtitles.
func Subtitles(ctx aero.Context) error {
id := ctx.Get("id")
language := ctx.Get("language")
// language := ctx.Get("language")
// Get episode
episode, err := arn.GetEpisode(id)
@ -31,12 +29,13 @@ func Subtitles(ctx aero.Context) error {
ctx.Response().SetHeader("Access-Control-Allow-Origin", "*")
ctx.Response().SetHeader("Content-Type", "text/vtt; charset=utf-8")
obj, err := arn.Spaces.GetObject(ctx.Request().Context(), "arn", fmt.Sprintf("videos/anime/%s/%d.%s.vtt", anime.ID, episode.Number, language), minio.GetObjectOptions{})
// obj, err := arn.Spaces.GetObject(ctx.Request().Context(), "arn", fmt.Sprintf("videos/anime/%s/%d.%s.vtt", anime.ID, episode.Number, language), minio.GetObjectOptions{})
if err != nil {
return ctx.Error(http.StatusInternalServerError, err)
}
// if err != nil {
// return ctx.Error(http.StatusInternalServerError, err)
// }
defer obj.Close()
return ctx.ReadAll(obj)
// defer obj.Close()
// return ctx.ReadAll(obj)
return nil
}

View File

@ -9,7 +9,7 @@ component FrontPage
.bg-video-container
video.bg-video(muted, autoplay, loop)
source(src="https://arn.sfo2.cdn.digitaloceanspaces.com/videos/others/violet.webm", type="video/webm")
source(src="https://notify.moe/videos/others/violet.webm", type="video/webm")
component Footer
footer.footer.mountable