feat: add pikpak offline download function (#6648)

* add pikpak offline download function

* 完善PikPak离线下载功能

* 删除多余的代码

* add task cache to avoid too many requests about API

* 优化Status函数

* 完善所有功能,目前测试无BUG

* 减少缓存时间,优化添加离线任务的参数
This commit is contained in:
Muione
2024-07-07 16:50:05 +08:00
committed by GitHub
parent ca30849e24
commit 3a3d0adfa0
7 changed files with 339 additions and 3 deletions

View File

@ -2,13 +2,14 @@ package tool
import (
"context"
"path/filepath"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/op"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/xhofe/tache"
"path/filepath"
)
type DeletePolicy string
@ -64,11 +65,17 @@ func AddURL(ctx context.Context, args *AddURLArgs) (tache.TaskWithInfo, error) {
uid := uuid.NewString()
tempDir := filepath.Join(conf.Conf.TempDir, args.Tool, uid)
deletePolicy := args.DeletePolicy
if args.Tool == "pikpak" {
tempDir = args.DstDirPath
// 防止将下载好的文件删除
deletePolicy = DeleteNever
}
t := &DownloadTask{
Url: args.URL,
DstDirPath: args.DstDirPath,
TempDir: tempDir,
DeletePolicy: args.DeletePolicy,
DeletePolicy: deletePolicy,
tool: tool,
}
DownloadTaskManager.Add(t)

View File

@ -71,6 +71,9 @@ outer:
if err != nil {
return err
}
if t.tool.Name() == "pikpak" {
return nil
}
t.Status = "offline download completed, maybe transferring"
// hack for qBittorrent
if t.tool.Name() == "qBittorrent" {
@ -123,6 +126,9 @@ func (t *DownloadTask) Complete() error {
files []File
err error
)
if t.tool.Name() == "pikpak" {
return nil
}
if getFileser, ok := t.tool.(GetFileser); ok {
files = getFileser.GetFiles(t)
} else {
@ -132,7 +138,7 @@ func (t *DownloadTask) Complete() error {
}
}
// upload files
for i, _ := range files {
for i := range files {
file := files[i]
TransferTaskManager.Add(&TransferTask{
file: file,