Files
OpenList/internal/fs/put.go

29 lines
927 B
Go
Raw Normal View History

2022-06-17 21:35:46 +08:00
package fs
import (
"context"
"fmt"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/pkg/errors"
)
var UploadTaskManager = task.NewTaskManager()
2022-06-17 21:35:46 +08:00
// Put add as a put task
func Put(ctx context.Context, account driver.Driver, parentPath string, file model.FileStreamer) error {
account, actualParentPath, err := operations.GetAccountAndActualPath(parentPath)
if account.Config().NoUpload {
return errors.New("upload is not supported")
}
2022-06-17 21:35:46 +08:00
if err != nil {
return errors.WithMessage(err, "failed get account")
}
2022-06-18 20:38:14 +08:00
UploadTaskManager.Submit(fmt.Sprintf("upload %s to [%s](%s)", file.GetName(), account.GetAccount().VirtualPath, actualParentPath), func(task *task.Task) error {
2022-06-17 21:35:46 +08:00
return operations.Put(task.Ctx, account, actualParentPath, file, nil)
})
return nil
}