Skip to content

Commit c098f97

Browse files
committed
fix(123_open): wire the offline download temp dir like the other cloud tools
The tool registered its scratch directory as a settings item under its own key in the tool package, so the row existed but nothing could write it: the admin UI reaches these settings through a dedicated endpoint per tool, not through the generic settings form. Move the key to internal/conf next to its siblings and add POST /api/admin/setting/set_123_open, which validates that the target is a working 123 Open storage before saving and re-initialises the tool, mirroring set_115/set_pikpak/set_thunder/set_guangyapan.
1 parent 513a80c commit c098f97

7 files changed

Lines changed: 60 additions & 25 deletions

File tree

internal/conf/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ const (
8181
// guangyapan
8282
GuangYaPanTempDir = "guangyapan_temp_dir"
8383

84+
// 123 open
85+
Open123TempDir = "123_open_temp_dir"
86+
8487
// single
8588
Token = "token"
8689
IndexProgress = "index_progress"

internal/offline_download/123_open/123_open.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ func (o *Open123) Name() string {
2727
return tool.Open123ToolName
2828
}
2929

30-
// Items registers the scratch directory the tool downloads into when the
31-
// destination is not a 123 Open storage.
30+
// Items registers no settings: the scratch directory is written by the
31+
// dedicated set_123_open endpoint, like the other cloud tools.
3232
func (o *Open123) Items() []model.SettingItem {
33-
return []model.SettingItem{
34-
{Key: tool.Open123TempDir, Value: "", Type: conf.TypeString, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
35-
}
33+
return nil
3634
}
3735

3836
// Run reports NotSupport so the framework drives the task through AddURL and
@@ -46,7 +44,7 @@ func (o *Open123) Init() (string, error) {
4644
}
4745

4846
func (o *Open123) IsReady() bool {
49-
tempDir := setting.GetStr(tool.Open123TempDir)
47+
tempDir := setting.GetStr(conf.Open123TempDir)
5048
if tempDir == "" {
5149
return false
5250
}

internal/offline_download/123_open/123_open_test.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/alist-org/alist/v3/internal/errs"
8-
"github.com/alist-org/alist/v3/internal/model"
98
"github.com/alist-org/alist/v3/internal/offline_download/tool"
109
pan123 "github.com/okatu-loli/go-123pan"
1110
)
@@ -20,18 +19,12 @@ func TestToolIsRegistered(t *testing.T) {
2019
}
2120
}
2221

23-
// TestItemsRegisterTempDir keeps the setting the tool needs discoverable in the
24-
// offline download settings group.
25-
func TestItemsRegisterTempDir(t *testing.T) {
26-
items := (&Open123{}).Items()
27-
if len(items) != 1 {
28-
t.Fatalf("got %d setting items, want 1", len(items))
29-
}
30-
if items[0].Key != tool.Open123TempDir {
31-
t.Errorf("setting key = %q, want %q", items[0].Key, tool.Open123TempDir)
32-
}
33-
if items[0].Group != model.OFFLINE_DOWNLOAD {
34-
t.Errorf("setting group = %d, want the offline download group", items[0].Group)
22+
// TestItemsRegistersNothing pins the convention shared with the other cloud
23+
// tools: the scratch directory is written by the dedicated set_123_open
24+
// endpoint, not seeded as a settings item.
25+
func TestItemsRegistersNothing(t *testing.T) {
26+
if items := (&Open123{}).Items(); len(items) != 0 {
27+
t.Fatalf("got %d setting items, want none", len(items))
3528
}
3629
}
3730

internal/offline_download/tool/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func AddURL(ctx context.Context, args *AddURLArgs) (task.TaskExtensionInfo, erro
109109
if _, ok := storage.(*_123Open.Open123); ok {
110110
tempDir = args.DstDirPath
111111
} else {
112-
tempBase := setting.GetStr(Open123TempDir)
112+
tempBase := setting.GetStr(conf.Open123TempDir)
113113
if tempBase == "" {
114114
return nil, errors.New("123 Open temp dir is not set")
115115
}

internal/offline_download/tool/base.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ const (
88
// Open123ToolName is the name the 123 Open offline download tool registers
99
// itself under.
1010
Open123ToolName = "123 Open"
11-
// Open123TempDir is the setting key holding the scratch directory the 123
12-
// Open tool downloads into when the destination is another storage. It
13-
// lives here rather than in internal/conf because the tool registers the
14-
// setting itself, through Tool.Items.
15-
Open123TempDir = "123_open_temp_dir"
1611
)
1712

1813
type AddUrlArgs struct {

server/handles/offline_download.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package handles
22

33
import (
44
_115 "github.com/alist-org/alist/v3/drivers/115"
5+
_123Open "github.com/alist-org/alist/v3/drivers/123_open"
56
guangyapandriver "github.com/alist-org/alist/v3/drivers/guangyapan"
67
"github.com/alist-org/alist/v3/drivers/pikpak"
78
"github.com/alist-org/alist/v3/drivers/thunder"
@@ -285,6 +286,50 @@ func SetGuangYaPan(c *gin.Context) {
285286
common.SuccessResp(c, "ok")
286287
}
287288

289+
type SetOpen123Req struct {
290+
TempDir string `json:"temp_dir" form:"temp_dir"`
291+
}
292+
293+
func SetOpen123(c *gin.Context) {
294+
var req SetOpen123Req
295+
if err := c.ShouldBind(&req); err != nil {
296+
common.ErrorResp(c, err, 400)
297+
return
298+
}
299+
if req.TempDir != "" {
300+
storage, _, err := op.GetStorageAndActualPath(req.TempDir)
301+
if err != nil {
302+
common.ErrorStrResp(c, "storage does not exists", 400)
303+
return
304+
}
305+
if storage.Config().CheckStatus && storage.GetStorage().Status != op.WORK {
306+
common.ErrorStrResp(c, "storage not init: "+storage.GetStorage().Status, 400)
307+
return
308+
}
309+
if _, ok := storage.(*_123Open.Open123); !ok {
310+
common.ErrorStrResp(c, "unsupported storage driver for offline download, only 123 Open is supported", 400)
311+
return
312+
}
313+
}
314+
items := []model.SettingItem{
315+
{Key: conf.Open123TempDir, Value: req.TempDir, Type: conf.TypeString, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
316+
}
317+
if err := op.SaveSettingItems(items); err != nil {
318+
common.ErrorResp(c, err, 500)
319+
return
320+
}
321+
_tool, err := tool.Tools.Get(tool.Open123ToolName)
322+
if err != nil {
323+
common.ErrorResp(c, err, 500)
324+
return
325+
}
326+
if _, err := _tool.Init(); err != nil {
327+
common.ErrorResp(c, err, 500)
328+
return
329+
}
330+
common.SuccessResp(c, "ok")
331+
}
332+
288333
func OfflineDownloadTools(c *gin.Context) {
289334
tools := tool.Tools.Names()
290335
common.SuccessResp(c, tools)

server/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func admin(g *gin.RouterGroup) {
182182
setting.POST("/set_pikpak", handles.SetPikPak)
183183
setting.POST("/set_thunder", handles.SetThunder)
184184
setting.POST("/set_guangyapan", handles.SetGuangYaPan)
185+
setting.POST("/set_123_open", handles.SetOpen123)
185186
setting.POST("/set_frp", handles.SetFRP)
186187
setting.POST("/stop_frp", handles.StopFRP)
187188
setting.GET("/frp_runtime", handles.GetFRPRuntime)

0 commit comments

Comments
 (0)