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"
)
2022-06-17 21:38:37 +08:00
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 )
2022-06-20 17:14:08 +08:00
if account . Config ( ) . NoUpload {
2022-06-20 20:34:58 +08:00
return errors . WithStack ( ErrUploadNotSupported )
2022-06-20 17:14:08 +08:00
}
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
}