chore: aria2 related function
This commit is contained in:
35
internal/aria2/add.go
Normal file
35
internal/aria2/add.go
Normal file
@ -0,0 +1,35 @@
|
||||
package aria2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func AddURI(ctx context.Context, uri []string, dstPath string, parentPath string) error {
|
||||
// check account
|
||||
account, actualParentPath, err := operations.GetAccountAndActualPath(parentPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get account")
|
||||
}
|
||||
// check is it could upload
|
||||
if account.Config().NoUpload {
|
||||
return errors.WithStack(fs.ErrUploadNotSupported)
|
||||
}
|
||||
// check path is valid
|
||||
obj, err := operations.Get(ctx, account, actualParentPath)
|
||||
if err != nil {
|
||||
if !errors.Is(errors.Cause(err), driver.ErrorObjectNotFound) {
|
||||
return errors.WithMessage(err, "failed get object")
|
||||
}
|
||||
} else {
|
||||
if !obj.IsDir() {
|
||||
// can't add to a file
|
||||
return errors.WithStack(fs.ErrNotFolder)
|
||||
}
|
||||
}
|
||||
// add aria2 task
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user