wip: use items in offline_download

This commit is contained in:
Andy Hsu 2023-10-05 13:38:35 +08:00
parent 0acb2d6073
commit 0380d7fff9
11 changed files with 36 additions and 15 deletions

View File

@ -5,6 +5,8 @@ import (
"os" "os"
"github.com/alist-org/alist/v3/cmd/flags" "github.com/alist-org/alist/v3/cmd/flags"
_ "github.com/alist-org/alist/v3/drivers"
_ "github.com/alist-org/alist/v3/internal/offline_download"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -13,7 +13,6 @@ import (
"time" "time"
"github.com/alist-org/alist/v3/cmd/flags" "github.com/alist-org/alist/v3/cmd/flags"
_ "github.com/alist-org/alist/v3/drivers"
"github.com/alist-org/alist/v3/internal/bootstrap" "github.com/alist-org/alist/v3/internal/bootstrap"
"github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"

View File

@ -4,6 +4,7 @@ import (
"github.com/alist-org/alist/v3/cmd/flags" "github.com/alist-org/alist/v3/cmd/flags"
"github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/offline_download/tool"
"github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/internal/op"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/pkg/utils/random" "github.com/alist-org/alist/v3/pkg/utils/random"
@ -168,6 +169,7 @@ func InitialSettings() []model.SettingItem {
{Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE}, {Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
{Key: conf.QbittorrentSeedtime, Value: "0", Type: conf.TypeNumber, Group: model.SINGLE, Flag: model.PRIVATE}, {Key: conf.QbittorrentSeedtime, Value: "0", Type: conf.TypeNumber, Group: model.SINGLE, Flag: model.PRIVATE},
} }
initialSettingItems = append(initialSettingItems, tool.Tools.Items()...)
if flags.Dev { if flags.Dev {
initialSettingItems = append(initialSettingItems, []model.SettingItem{ initialSettingItems = append(initialSettingItems, []model.SettingItem{
{Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED}, {Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED},

View File

@ -0,0 +1,5 @@
package offline_download
import (
_ "github.com/alist-org/alist/v3/internal/offline_download/aria2"
)

View File

@ -8,7 +8,7 @@ import (
"github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/offline_download" "github.com/alist-org/alist/v3/internal/offline_download/tool"
"github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/pkg/aria2/rpc" "github.com/alist-org/alist/v3/pkg/aria2/rpc"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -50,7 +50,7 @@ func (a *Aria2) IsReady() bool {
return a.client != nil return a.client != nil
} }
func (a *Aria2) AddURI(args *offline_download.AddUriArgs) (string, error) { func (a *Aria2) AddURI(args *tool.AddUriArgs) (string, error) {
options := map[string]interface{}{ options := map[string]interface{}{
"dir": args.TempDir, "dir": args.TempDir,
} }
@ -66,7 +66,7 @@ func (a *Aria2) Remove(tid string) error {
return err return err
} }
func (a *Aria2) Status(tid string) (*offline_download.Status, error) { func (a *Aria2) Status(tid string) (*tool.Status, error) {
info, err := a.client.TellStatus(tid) info, err := a.client.TellStatus(tid)
if err != nil { if err != nil {
return nil, err return nil, err
@ -79,7 +79,7 @@ func (a *Aria2) Status(tid string) (*offline_download.Status, error) {
if err != nil { if err != nil {
downloaded = 0 downloaded = 0
} }
s := &offline_download.Status{ s := &tool.Status{
Completed: info.Status == "complete", Completed: info.Status == "complete",
Err: err, Err: err,
} }
@ -109,8 +109,12 @@ func (a *Aria2) Status(tid string) (*offline_download.Status, error) {
return s, nil return s, nil
} }
func (a *Aria2) GetFile(tid string) *offline_download.File { func (a *Aria2) GetFile(tid string) *tool.File {
return nil return nil
} }
var _ offline_download.Tool = (*Aria2)(nil) var _ tool.Tool = (*Aria2)(nil)
func init() {
tool.Tools.Add("aria2", &Aria2{})
}

View File

@ -1,4 +1,4 @@
package offline_download package tool
import ( import (
"context" "context"

View File

@ -1,13 +1,13 @@
package offline_download_test package tool_test
import ( import (
"testing" "testing"
"github.com/alist-org/alist/v3/internal/offline_download" "github.com/alist-org/alist/v3/internal/offline_download/tool"
) )
func TestGetFiles(t *testing.T) { func TestGetFiles(t *testing.T) {
files, err := offline_download.GetFiles("..") files, err := tool.GetFiles("..")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -1,4 +1,4 @@
package offline_download package tool
import ( import (
"io" "io"

View File

@ -1,4 +1,4 @@
package offline_download package tool
import ( import (
"fmt" "fmt"

View File

@ -1,8 +1,9 @@
package offline_download package tool
import ( import (
"fmt" "fmt"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/task" "github.com/alist-org/alist/v3/pkg/task"
) )
@ -31,3 +32,11 @@ func (t ToolsManager) Names() []string {
} }
return names return names
} }
func (t ToolsManager) Items() []model.SettingItem {
var items []model.SettingItem
for _, tool := range t {
items = append(items, tool.Items()...)
}
return items
}

View File

@ -1,4 +1,4 @@
package offline_download package tool
import ( import (
"os" "os"