mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 13:03:09 +08:00
c06656958c
* fix(offline): allow ED2K downloads through 115 tools - Treat 115 Cloud and 115 Open as ED2K-capable tools. - Keep automatic fallback limited to Thunder tools. - Add regression coverage for supported and unsupported tools. Co-authored-by: Codex <267193182+codex@users.noreply.github.com> * fix(offline): route ED2K to native 115 tools - Allow ED2K requests initially using SimpleHttp to enter tool routing. - Prefer the matching 115 tool for 115 Cloud and 115 Open destinations. - Add regression coverage for native storage tool selection. Co-authored-by: Codex <267193182+codex@users.noreply.github.com> * fix(offline): expose native tools for destination storage - Include the native destination tool in the path-aware tool list. - Keep existing ready-tool filtering for external destinations. - Add coverage for native storage to tool mapping. Co-authored-by: Codex <267193182+codex@users.noreply.github.com> --------- Co-authored-by: Codex <267193182+codex@users.noreply.github.com> Co-authored-by: Pikachu Ren <40362270+PIKACHUIM@users.noreply.github.com>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package tool
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
|
"github.com/OpenListTeam/OpenList/v4/internal/op"
|
|
)
|
|
|
|
var (
|
|
Tools = make(ToolsManager)
|
|
)
|
|
|
|
type ToolsManager map[string]Tool
|
|
|
|
func (t ToolsManager) Get(name string) (Tool, error) {
|
|
if tool, ok := t[name]; ok {
|
|
return tool, nil
|
|
}
|
|
return nil, fmt.Errorf("tool %s not found", name)
|
|
}
|
|
|
|
func (t ToolsManager) Add(tool Tool) {
|
|
t[tool.Name()] = tool
|
|
}
|
|
|
|
func (t ToolsManager) Names() []string {
|
|
names := make([]string, 0, len(t))
|
|
for name := range t {
|
|
if tool, err := t.Get(name); err == nil && tool.IsReady() {
|
|
names = append(names, name)
|
|
}
|
|
}
|
|
sort.Strings(names)
|
|
return names
|
|
}
|
|
|
|
// NamesForPath returns ready tools and the native tool for the destination storage.
|
|
// Native tools can write directly to their own storage even without a temporary path setting.
|
|
func (t ToolsManager) NamesForPath(path string) []string {
|
|
names := t.Names()
|
|
storage, _, err := op.GetStorageAndActualPath(path)
|
|
if err != nil {
|
|
return names
|
|
}
|
|
|
|
name := toolNameForStorage(storage)
|
|
if name == "" {
|
|
return names
|
|
}
|
|
for _, existing := range names {
|
|
if existing == name {
|
|
return names
|
|
}
|
|
}
|
|
if _, ok := t[name]; ok {
|
|
names = append(names, name)
|
|
sort.Strings(names)
|
|
}
|
|
return names
|
|
}
|
|
|
|
func (t ToolsManager) Items() []model.SettingItem {
|
|
var items []model.SettingItem
|
|
for _, tool := range t {
|
|
items = append(items, tool.Items()...)
|
|
}
|
|
return items
|
|
}
|