chore: aria2 notifier

This commit is contained in:
Noah Hsu
2022-06-20 22:29:52 +08:00
parent 6c552a9d62
commit 1b3387ca1a
10 changed files with 92 additions and 29 deletions

View File

@ -2,13 +2,16 @@ package aria2
import (
"context"
"github.com/alist-org/alist/v3/conf"
"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/google/uuid"
"github.com/pkg/errors"
"path/filepath"
)
func AddURI(ctx context.Context, uri []string, dstPath string, parentPath string) error {
func AddURI(ctx context.Context, uri string, dstPath string, parentPath string) error {
// check account
account, actualParentPath, err := operations.GetAccountAndActualPath(parentPath)
if err != nil {
@ -30,6 +33,14 @@ func AddURI(ctx context.Context, uri []string, dstPath string, parentPath string
return errors.WithStack(fs.ErrNotFolder)
}
}
// add aria2 task
// call aria2 rpc
options := map[string]interface{}{
"dir": filepath.Join(conf.Conf.TempDir, "aria2", uuid.NewString()),
}
gid, err := client.AddURI([]string{uri}, options)
if err != nil {
return errors.Wrapf(err, "failed to add uri %s", uri)
}
// TODO add to task manager
return nil
}