🚧 check upload file

pull/548/head
微凉 2021-12-31 14:05:35 +08:00
parent 6f0959a98e
commit 939c9cd5ac
12 changed files with 60 additions and 13 deletions

View File

@ -364,6 +364,9 @@ type UploadResp struct {
}
func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
const DEFAULT uint64 = 10485760
var count = int64(math.Ceil(float64(file.GetSize()) / float64(DEFAULT)))
var finish uint64 = 0

View File

@ -5,6 +5,7 @@ import (
_ "github.com/Xhofe/alist/drivers/189"
_ "github.com/Xhofe/alist/drivers/alidrive"
_ "github.com/Xhofe/alist/drivers/alist"
"github.com/Xhofe/alist/drivers/base"
_ "github.com/Xhofe/alist/drivers/ftp"
_ "github.com/Xhofe/alist/drivers/google"
_ "github.com/Xhofe/alist/drivers/lanzou"
@ -14,4 +15,27 @@ import (
_ "github.com/Xhofe/alist/drivers/s3"
_ "github.com/Xhofe/alist/drivers/shandian"
_ "github.com/Xhofe/alist/drivers/webdav"
log "github.com/sirupsen/logrus"
"strings"
)
var NoCors string
var NoUpload string
func GetConfig() {
for k, v := range base.GetDriversMap() {
if v.Config().NoCors {
NoCors += k + ","
}
if v.Upload(nil, nil) != base.ErrEmptyFile {
NoUpload += k + ","
}
}
NoCors = strings.Trim(NoCors, ",")
NoUpload = strings.Trim(NoUpload, ",")
}
func init() {
log.Debug("all init")
GetConfig()
}

View File

@ -6,7 +6,6 @@ import (
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"net/http"
"strings"
)
type DriverConfig struct {
@ -78,14 +77,8 @@ func GetDriver(name string) (driver Driver, ok bool) {
return
}
func GetNoCors() string {
res := make([]string, 0)
for k, v := range driversMap {
if v.Config().NoCors {
res = append(res, k)
}
}
return strings.Join(res, ",")
func GetDriversMap() map[string]Driver {
return driversMap
}
func GetDrivers() map[string][]Item {

View File

@ -11,6 +11,7 @@ var (
ErrNotImplement = errors.New("not implement")
ErrNotSupport = errors.New("not support")
ErrNotFolder = errors.New("not a folder")
ErrEmptyFile = errors.New("empty file")
)
const (

View File

@ -240,6 +240,9 @@ func (driver FTP) Delete(path string, account *model.Account) error {
}
func (driver FTP) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
realPath := utils.Join(account.RootFolder, file.ParentPath, file.Name)
conn, err := driver.Login(account)
if err != nil {

View File

@ -250,6 +250,9 @@ func (driver GoogleDrive) Delete(path string, account *model.Account) error {
}
func (driver GoogleDrive) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
parentFile, err := driver.File(file.ParentPath, account)
if err != nil {
return err

View File

@ -196,6 +196,9 @@ func (driver Native) Delete(path string, account *model.Account) error {
}
func (driver Native) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
fullPath := filepath.Join(account.RootFolder, file.ParentPath, file.Name)
_, err := driver.File(filepath.Join(file.ParentPath, file.Name), account)
if err == nil {

View File

@ -280,6 +280,9 @@ func (driver Onedrive) Delete(path string, account *model.Account) error {
}
func (driver Onedrive) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
var err error
if file.GetSize() <= 4*1024*1024 {
err = driver.UploadSmall(file, account)

View File

@ -232,6 +232,9 @@ func (driver S3) Delete(path string, account *model.Account) error {
}
func (driver S3) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
s, ok := sessionsMap[account.Name]
if !ok {
return fmt.Errorf("can't find [%s] session", account.Name)

View File

@ -227,6 +227,9 @@ func (driver Shandian) Delete(path string, account *model.Account) error {
}
func (driver Shandian) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
parentFile, err := driver.File(file.ParentPath, account)
if err != nil {
return err

View File

@ -182,6 +182,9 @@ func (driver WebDav) Delete(path string, account *model.Account) error {
}
func (driver WebDav) Upload(file *model.FileStream, account *model.Account) error {
if file == nil {
return base.ErrEmptyFile
}
c := driver.NewClient(account)
path := utils.Join(file.ParentPath, file.Name)
err := c.WriteStream(driver.WebDavPath(path), file, 0644)

View File

@ -1,7 +1,7 @@
package controllers
import (
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server/common"
"github.com/gin-gonic/gin"
@ -47,12 +47,17 @@ func GetSettingsPublic(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
settings = append(settings, model.SettingItem{
settings = append(settings, []model.SettingItem{{
Key: "no cors",
Value: base.GetNoCors(),
Value: drivers.NoCors,
Description: "",
Type: "string",
})
}, {
Key: "no upload",
Value: drivers.NoUpload,
Description: "",
Type: "string",
}}...)
common.SuccessResp(c, settings)
}