mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-05 04:56:37 +08:00
bug处理
This commit is contained in:
@@ -6,10 +6,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -37,10 +37,10 @@ type strmSyncState struct {
|
||||
syncType string
|
||||
|
||||
mu sync.Mutex
|
||||
processed int // 已处理文件计数(用于定期落库进度)
|
||||
lastProgressFlush time.Time // 上次进度落库时间
|
||||
seenVideo map[string]bool // "v:"+去掉扩展名的相对路径 → 远端存在该视频
|
||||
seenMeta map[string]bool // "m:"+相对路径 → 远端存在该元数据
|
||||
processed int // 已处理文件计数(用于定期落库进度)
|
||||
lastProgressFlush time.Time // 上次进度落库时间
|
||||
seenVideo map[string]bool // "v:"+去掉扩展名的相对路径 → 远端存在该视频
|
||||
seenMeta map[string]bool // "m:"+相对路径 → 远端存在该元数据
|
||||
remoteMeta map[string]int64 // 远端元数据大小(上传比对用)
|
||||
remoteMetaRef map[string]string // "m:"+相对路径 → 远端元数据文件引用(115 文件 ID,覆盖上传前删除旧文件用)
|
||||
remoteMetaSha1 map[string]string // "m:"+相对路径 → 远端元数据内容 SHA1(115 列表返回;上传/下载精确比对用,其他网盘为空)
|
||||
@@ -184,6 +184,66 @@ func (s *StrmService) ListRemoteDir(ctx context.Context, accountID, dir string)
|
||||
return provider.List(ctx, dir)
|
||||
}
|
||||
|
||||
// ResolveRemoteDirPath 解析远端目录的完整展示路径。115 的目录以 ID 存储,
|
||||
// 用户无法辨认,这里按 ID 反查 115 返回的祖先链拼出人类可读路径;路径型
|
||||
// 网盘(CD2/OpenList)与本地目录的 remote_path 本身就是路径,原样返回。
|
||||
func (s *StrmService) ResolveRemoteDirPath(ctx context.Context, accountID, dir string) (string, error) {
|
||||
acct, err := s.repo.StrmAccount.FindByID(ctx, accountID)
|
||||
if err != nil || acct == nil {
|
||||
return "", errNotFoundOr(err, "网盘账号不存在")
|
||||
}
|
||||
dir = strings.TrimSpace(dir)
|
||||
if dir == "" {
|
||||
return "", nil
|
||||
}
|
||||
if acct.Provider != model.StrmProvider115 {
|
||||
return dir, nil
|
||||
}
|
||||
if dir == "0" {
|
||||
return "", nil
|
||||
}
|
||||
provider, err := s.providerFor(ctx, acct)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
oc, ok := provider.(interface{ OpenClient() *cloud115.OpenClient })
|
||||
if !ok {
|
||||
return "", fmt.Errorf("115: 客户端初始化失败")
|
||||
}
|
||||
detail, err := oc.OpenClient().GetFsDetailByCid(ctx, dir)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("115: 解析目录路径失败:%w", err)
|
||||
}
|
||||
return cloud115FullPath(detail), nil
|
||||
}
|
||||
|
||||
// cloud115FullPath 把 115 目录详情的祖先链拼成以 / 开头的完整路径。
|
||||
func cloud115FullPath(detail *cloud115.RemoteFileDetail) string {
|
||||
if detail == nil {
|
||||
return ""
|
||||
}
|
||||
segments := make([]string, 0, len(detail.Paths)+1)
|
||||
hasSelf := false
|
||||
for _, p := range detail.Paths {
|
||||
if p.FileId == "0" || p.FileId == "" {
|
||||
continue
|
||||
}
|
||||
if p.FileId == detail.FileId {
|
||||
hasSelf = true
|
||||
}
|
||||
if name := strings.TrimSpace(p.Name); name != "" {
|
||||
segments = append(segments, name)
|
||||
}
|
||||
}
|
||||
if !hasSelf && strings.TrimSpace(detail.FileName) != "" {
|
||||
segments = append(segments, strings.TrimSpace(detail.FileName))
|
||||
}
|
||||
if len(segments) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "/" + strings.Join(segments, "/")
|
||||
}
|
||||
|
||||
// runSync 执行同步主体;结束时更新记录与目录状态。
|
||||
func (s *StrmService) runSync(ctx context.Context, p *model.StrmSyncPath, rec *model.StrmSyncRecord, cancel context.CancelFunc) {
|
||||
defer s.clearRunning(p.ID, cancel)
|
||||
@@ -819,9 +879,9 @@ func (st *strmSyncState) walk115Flat(open115 *cloud115.OpenClient) error {
|
||||
}
|
||||
fileCh := make(chan strmFileTask)
|
||||
var (
|
||||
procWg sync.WaitGroup
|
||||
procWg sync.WaitGroup
|
||||
procErrMu sync.Mutex
|
||||
procErr error
|
||||
procErr error
|
||||
)
|
||||
for i := 0; i < strmProcessWorkers; i++ {
|
||||
procWg.Add(1)
|
||||
|
||||
@@ -1161,3 +1161,48 @@ func TestWalk115FlatConcurrentProcessing(t *testing.T) {
|
||||
t.Fatalf("incremental sync should skip all, new = %d skipped = %d", st2.rec.NewStrm, st2.rec.Skipped)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloud115FullPath(t *testing.T) {
|
||||
paths := func(ids, names []string) []struct {
|
||||
FileId string `json:"file_id"`
|
||||
Name string `json:"file_name"`
|
||||
} {
|
||||
out := make([]struct {
|
||||
FileId string `json:"file_id"`
|
||||
Name string `json:"file_name"`
|
||||
}, 0, len(ids))
|
||||
for i := range ids {
|
||||
out = append(out, struct {
|
||||
FileId string `json:"file_id"`
|
||||
Name string `json:"file_name"`
|
||||
}{FileId: ids[i], Name: names[i]})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// 祖先链已包含当前目录自身(115 常规返回)
|
||||
d := &cloud115.RemoteFileDetail{
|
||||
FileId: "330",
|
||||
FileName: "剧集",
|
||||
Paths: paths([]string{"0", "100", "330"}, []string{"", "电影", "剧集"}),
|
||||
}
|
||||
if got := cloud115FullPath(d); got != "/电影/剧集" {
|
||||
t.Fatalf("full path = %q, want /电影/剧集", got)
|
||||
}
|
||||
|
||||
// 祖先链不含当前目录自身,用 FileName 兜底
|
||||
d = &cloud115.RemoteFileDetail{
|
||||
FileId: "330",
|
||||
FileName: "剧集",
|
||||
Paths: paths([]string{"0", "100"}, []string{"", "电影"}),
|
||||
}
|
||||
if got := cloud115FullPath(d); got != "/电影/剧集" {
|
||||
t.Fatalf("full path = %q, want /电影/剧集", got)
|
||||
}
|
||||
|
||||
// 根目录:无有效祖先段
|
||||
d = &cloud115.RemoteFileDetail{FileId: "0"}
|
||||
if got := cloud115FullPath(d); got != "" {
|
||||
t.Fatalf("root full path = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user