fix: translate qBittorrent container paths for auto-organize

- Add path translation for cross-container download paths
- Map common qBittorrent container paths to /downloads
- Fixes 'payload path is not accessible' warnings in logs
- Enables auto-organize to work when qBittorrent runs in separate container
This commit is contained in:
ShukeBta
2026-06-11 11:38:08 +08:00
parent fab2b98096
commit 39144d70ba
2 changed files with 41 additions and 4 deletions
+11 -4
View File
@@ -20,7 +20,6 @@ import (
"errors"
"math"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
@@ -895,6 +894,12 @@ func (d *DownloadService) onTorrentComplete(ctx context.Context, torrent QBitTor
}
func (d *DownloadService) completedTorrentSource(torrent QBitTorrent) string {
// 常见路径映射:qBittorrent容器路径 -> MediaStationGo容器路径
mappings := map[string]string{
"/var/apps/qBittorrent/shares/qBittorrent/Download": "/downloads",
"/data/qBittorrent/downloads": "/downloads",
"/downloads/qBittorrent": "/downloads",
}
for _, candidate := range []string{
torrent.ContentPath,
filepath.Join(torrent.SavePath, torrent.Name),
@@ -904,10 +909,12 @@ func (d *DownloadService) completedTorrentSource(torrent QBitTorrent) string {
if clean == "" || clean == "." {
continue
}
clean = filepath.Clean(clean)
if _, err := os.Stat(clean); err == nil {
return clean
// 尝试直接访问或路径映射
if translated := translateClientPath(clean, mappings); translated != "" {
return translated
}
}
return ""
}
+30
View File
@@ -0,0 +1,30 @@
package service
import (
"os"
"path/filepath"
"strings"
)
// translateClientPath 将下载客户端报告的路径转换为容器内可访问的路径。
// 常见场景:qBittorrent在另一个容器,报告的路径是其容器内路径,需要映射到当前容器。
func translateClientPath(clientPath string, mappings map[string]string) string {
if clientPath == "" {
return ""
}
clean := filepath.Clean(clientPath)
// 尝试直接访问
if _, err := os.Stat(clean); err == nil {
return clean
}
// 尝试路径映射
for clientPrefix, localPrefix := range mappings {
if strings.HasPrefix(clean, clientPrefix) {
translated := filepath.Join(localPrefix, strings.TrimPrefix(clean, clientPrefix))
if _, err := os.Stat(translated); err == nil {
return translated
}
}
}
return ""
}