mirror of https://github.com/Xhofe/alist
feat(offline-download): support for Thunder Expert driver
parent
11b6a6012f
commit
4532b429a8
|
@ -45,11 +45,14 @@ func (t *Thunder) IsReady() bool {
|
|||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if _, ok := storage.(*thunder.Thunder); !ok {
|
||||
return false
|
||||
}
|
||||
if _, ok := storage.(*thunder.Thunder); ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := storage.(*thunder.ThunderExpert); ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *Thunder) AddURL(args *tool.AddUrlArgs) (string, error) {
|
||||
// 添加新任务刷新缓存
|
||||
|
@ -58,11 +61,6 @@ func (t *Thunder) AddURL(args *tool.AddUrlArgs) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
thunderDriver, ok := storage.(*thunder.Thunder)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unsupported storage driver for offline download, only Thunder is supported")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if err := op.MakeDir(ctx, storage, actualPath); err != nil {
|
||||
|
@ -74,7 +72,15 @@ func (t *Thunder) AddURL(args *tool.AddUrlArgs) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
task, err := thunderDriver.OfflineDownload(ctx, args.Url, parentDir, "")
|
||||
var task *thunder.OfflineTask
|
||||
if thunderDriver, ok := storage.(*thunder.Thunder); ok {
|
||||
task, err = thunderDriver.OfflineDownload(ctx, args.Url, parentDir, "")
|
||||
} else if expertDriver, ok := storage.(*thunder.ThunderExpert); ok {
|
||||
task, err = expertDriver.OfflineDownload(ctx, args.Url, parentDir, "")
|
||||
} else {
|
||||
return "", fmt.Errorf("unsupported storage driver for offline download, only Thunder or Thunder Expert is supported")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to add offline download task: %w", err)
|
||||
}
|
||||
|
@ -87,28 +93,29 @@ func (t *Thunder) Remove(task *tool.DownloadTask) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
thunderDriver, ok := storage.(*thunder.Thunder)
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported storage driver for offline download, only Thunder is supported")
|
||||
if thunderDriver, ok := storage.(*thunder.Thunder); ok {
|
||||
err = thunderDriver.DeleteOfflineTasks(context.Background(), []string{task.GID}, false)
|
||||
} else if expertDriver, ok := storage.(*thunder.ThunderExpert); ok {
|
||||
err = expertDriver.DeleteOfflineTasks(context.Background(), []string{task.GID}, false)
|
||||
} else {
|
||||
return fmt.Errorf("unsupported storage driver for offline download, only Thunder or Thunder Expert is supported")
|
||||
}
|
||||
ctx := context.Background()
|
||||
err = thunderDriver.DeleteOfflineTasks(ctx, []string{task.GID}, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Thunder) Status(task *tool.DownloadTask) (*tool.Status, error) {
|
||||
storage, _, err := op.GetStorageAndActualPath(task.TempDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
thunderDriver, ok := storage.(*thunder.Thunder)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported storage driver for offline download, only Thunder is supported")
|
||||
var tasks []thunder.OfflineTask
|
||||
if thunderDriver, ok := storage.(*thunder.Thunder); ok {
|
||||
tasks, err = t.GetTasks(thunderDriver)
|
||||
} else if expertDriver, ok := storage.(*thunder.ThunderExpert); ok {
|
||||
tasks, err = t.GetTasks(expertDriver)
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported storage driver for offline download, only Thunder or Thunder Expert is supported")
|
||||
}
|
||||
tasks, err := t.GetTasks(thunderDriver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package thunder
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"time"
|
||||
|
||||
"github.com/Xhofe/go-cache"
|
||||
|
@ -13,8 +14,8 @@ import (
|
|||
var taskCache = cache.NewMemCache(cache.WithShards[[]thunder.OfflineTask](16))
|
||||
var taskG singleflight.Group[[]thunder.OfflineTask]
|
||||
|
||||
func (t *Thunder) GetTasks(thunderDriver *thunder.Thunder) ([]thunder.OfflineTask, error) {
|
||||
key := op.Key(thunderDriver, "/drive/v1/task")
|
||||
func (t *Thunder) GetTasks(storage driver.Driver) ([]thunder.OfflineTask, error) {
|
||||
key := op.Key(storage, "/drive/v1/task")
|
||||
if !t.refreshTaskCache {
|
||||
if tasks, ok := taskCache.Get(key); ok {
|
||||
return tasks, nil
|
||||
|
@ -22,8 +23,13 @@ func (t *Thunder) GetTasks(thunderDriver *thunder.Thunder) ([]thunder.OfflineTas
|
|||
}
|
||||
t.refreshTaskCache = false
|
||||
tasks, err, _ := taskG.Do(key, func() ([]thunder.OfflineTask, error) {
|
||||
ctx := context.Background()
|
||||
tasks, err := thunderDriver.OfflineList(ctx, "")
|
||||
var tasks []thunder.OfflineTask
|
||||
var err error
|
||||
if thunderDriver, ok := storage.(*thunder.Thunder); ok {
|
||||
tasks, err = thunderDriver.OfflineList(context.Background(), "")
|
||||
} else if expertDriver, ok := storage.(*thunder.ThunderExpert); ok {
|
||||
tasks, err = expertDriver.OfflineList(context.Background(), "")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@ package tool
|
|||
|
||||
import (
|
||||
"context"
|
||||
_115 "github.com/alist-org/alist/v3/drivers/115"
|
||||
"github.com/alist-org/alist/v3/drivers/pikpak"
|
||||
"github.com/alist-org/alist/v3/drivers/thunder"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/setting"
|
||||
|
@ -81,24 +78,18 @@ func AddURL(ctx context.Context, args *AddURLArgs) (task.TaskExtensionInfo, erro
|
|||
deletePolicy := args.DeletePolicy
|
||||
|
||||
// 如果当前 storage 是对应网盘,则直接下载到目标路径,无需转存
|
||||
switch args.Tool {
|
||||
case "115 Cloud":
|
||||
if _, ok := storage.(*_115.Pan115); ok {
|
||||
tempDir = args.DstDirPath
|
||||
} else {
|
||||
tempDir = filepath.Join(setting.GetStr(conf.Pan115TempDir), uid)
|
||||
tempDirConfMap := map[string]string{
|
||||
"115 Cloud": conf.Pan115TempDir,
|
||||
"PikPak": conf.PikPakTempDir,
|
||||
"Thunder": conf.ThunderTempDir,
|
||||
}
|
||||
case "PikPak":
|
||||
if _, ok := storage.(*pikpak.PikPak); ok {
|
||||
if tempDirConf, ok := tempDirConfMap[args.Tool]; ok {
|
||||
tempDir = setting.GetStr(tempDirConf)
|
||||
tempDirStorage, _, _ := op.GetStorageAndActualPath(tempDir)
|
||||
if storage == tempDirStorage {
|
||||
tempDir = args.DstDirPath
|
||||
} else {
|
||||
tempDir = filepath.Join(setting.GetStr(conf.PikPakTempDir), uid)
|
||||
}
|
||||
case "Thunder":
|
||||
if _, ok := storage.(*thunder.Thunder); ok {
|
||||
tempDir = args.DstDirPath
|
||||
} else {
|
||||
tempDir = filepath.Join(setting.GetStr(conf.ThunderTempDir), uid)
|
||||
tempDir = filepath.Join(tempDir, uid)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -216,10 +216,12 @@ func SetThunder(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
if _, ok := storage.(*thunder.Thunder); !ok {
|
||||
common.ErrorStrResp(c, "unsupported storage driver for offline download, only Thunder is supported", 400)
|
||||
if _, ok := storage.(*thunder.ThunderExpert); !ok {
|
||||
common.ErrorStrResp(c, "unsupported storage driver for offline download, only Thunder or Thunder Expert is supported", 400)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
items := []model.SettingItem{
|
||||
{Key: conf.ThunderTempDir, Value: req.TempDir, Type: conf.TypeString, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue