feat(115): add offline download tool (close #6888 in #6954)

This commit is contained in:
Shelton Zhu
2024-08-10 20:59:07 +08:00
committed by GitHub
parent 2d77db6bc2
commit 29165d8e60
7 changed files with 166 additions and 13 deletions

View File

@ -66,11 +66,18 @@ 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" {
switch args.Tool {
case "115 Cloud":
tempDir = args.DstDirPath
// 防止将下载好的文件删除
deletePolicy = DeleteNever
case "pikpak":
tempDir = args.DstDirPath
// 防止将下载好的文件删除
deletePolicy = DeleteNever
}
t := &DownloadTask{
Url: args.URL,
DstDirPath: args.DstDirPath,

View File

@ -54,9 +54,7 @@ func (t *DownloadTask) Run() error {
return err
}
t.GID = gid
var (
ok bool
)
var ok bool
outer:
for {
select {
@ -81,6 +79,15 @@ outer:
if t.tool.Name() == "pikpak" {
return nil
}
if t.tool.Name() == "115 Cloud" {
// hack for 115
<-time.After(time.Second * 1)
err := t.tool.Remove(t)
if err != nil {
log.Errorln(err.Error())
}
return nil
}
t.Status = "offline download completed, maybe transferring"
// hack for qBittorrent
if t.tool.Name() == "qBittorrent" {
@ -136,6 +143,9 @@ func (t *DownloadTask) Complete() error {
if t.tool.Name() == "pikpak" {
return nil
}
if t.tool.Name() == "115 Cloud" {
return nil
}
if getFileser, ok := t.tool.(GetFileser); ok {
files = getFileser.GetFiles(t)
} else {
@ -166,6 +176,4 @@ func (t *DownloadTask) GetStatus() string {
return t.Status
}
var (
DownloadTaskManager *tache.Manager[*DownloadTask]
)
var DownloadTaskManager *tache.Manager[*DownloadTask]