feat: support alist as a storage

This commit is contained in:
Simon Ding
2024-11-17 21:21:21 +08:00
parent b136b9167f
commit 7d5ce8ba97
14 changed files with 536 additions and 121 deletions

View File

@@ -2,9 +2,11 @@ package server
import (
"fmt"
"os"
"polaris/db"
"polaris/log"
"polaris/pkg/alist"
"polaris/pkg/storage"
"polaris/pkg/utils"
"strconv"
@@ -39,6 +41,21 @@ func (s *Server) AddStorage(c *gin.Context) (interface{}, error) {
for _, f := range fs {
log.Infof("file name: %v", f.Name())
}
} else if in.Implementation == "alist" {
cfg := in.ToWebDavSetting()
_, err := storage.NewAlist(&alist.Config{URL: cfg.URL, Username: cfg.User, Password: cfg.Password}, in.TvPath)
if err != nil {
return nil, errors.Wrap(err, "alist")
}
} else if in.Implementation == "local" {
_, err := os.Stat(in.TvPath)
if err != nil {
return nil, err
}
_, err = os.Stat(in.MoviePath)
if err != nil {
return nil, err
}
}
log.Infof("received add storage input: %v", in)
err := s.db.AddStorage(&in)