refactor: 将文件移动改为独立接口,扫描完成后手动触发

This commit is contained in:
2025-07-29 21:18:35 +08:00
parent 59b0206cf1
commit 2e01f6c3c9
7 changed files with 193 additions and 35 deletions
-16
View File
@@ -72,7 +72,6 @@ type Organizer struct {
ctx context.Context // 中止信号;ctx 被取消时探测/归类立即停下
nsfw *nsfw.Detector // 色情检测器;为 nil 表示没启用,图片不检测
rotateImages bool // 是否处理 EXIF 旋转(转正/按显示方向归类);false 则完全不动,按存储方向归类
moveFiles bool // 扫描完成后是否移动文件;false 时禁用续传跳过,每次都完整探测
buckets map[string][]string // 目标目录 → 里面该放哪些文件(只记源路径)
order []string // 目标目录的先后顺序(保证输出稳定、不来回跳)
onProgress func(phase string, done, total int)
@@ -136,13 +135,6 @@ func (o *Organizer) SetRotateImages(b bool) {
o.rotateImages = b
}
// SetMoveFiles 设置扫描完成后是否移动文件(默认 true)。
// - true:文件会被移动到分类目录,启用续传优化
// - false:文件留在原位,禁用续传跳过,每次都完整探测并记录到媒体库
func (o *Organizer) SetMoveFiles(b bool) {
o.moveFiles = b
}
// report 上报进度。total 为 0 表示这一步没活干,就不用报了。
func (o *Organizer) report(phase string, done, total int) {
if o.onProgress != nil && total > 0 {
@@ -218,12 +210,8 @@ func (o *Organizer) addToDir(f scanner.File, dir string) {
// addClassified 归档一个文件并记进续传表:把"源路径 → 目标目录"写进 scan_log,
// 这样下次重扫时这个文件直接复用目标目录,不再重新探测/识别。
// 注意:moveFiles=false 时不写续传记录,因为文件没有真正移动。
func (o *Organizer) addClassified(f scanner.File, subDir string, size int64, headMd5, tailMd5 string) {
o.add(f, subDir)
if !o.moveFiles {
return // 不移动文件时不写续传记录
}
if o.store == nil {
return
}
@@ -241,11 +229,7 @@ func (o *Organizer) addClassified(f scanner.File, subDir string, size int64, hea
// matchResume 判断一个文件上次是否已归类过,且内容没变。
// 命中返回上次的目标目录和 ok=true;内容变了/没记录则 ok=false(要重新探测)。
// 注意:moveFiles=false 时禁用续传跳过,每次都完整探测。
func (o *Organizer) matchResume(f scanner.File) (store.ScanLog, bool) {
if !o.moveFiles {
return store.ScanLog{}, false // 不移动文件时禁用续传
}
if o.resume == nil {
return store.ScanLog{}, false
}