- feat: 新增续传表 scan_log,重扫跳过已归类文件(尺寸/头尾指纹校验) - fix: 色情识别记录批量入库超 SQLite 999 变量上限,改每 100 条一批 - perf: NudeNet 检测改为多线程推理池(每线程独立模型实例) - perf: 明暗分析 JPEG(YCbCr) 快路径;SQLite 读并发放开;加阶段耗时统计 - fix: 前端色情识别状态由后端如实上报(配置开关+检测服务是否起来) - feat: ffprobe 内嵌按平台拆分,Linux 构建回退系统 ffprobe,支持交叉编译 - docs: README 补充断点续传与 CentOS 交叉编译步骤 - chore: organize.workers 默认 8
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package organize
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"kenaito-media-picker/internal/digest"
|
|
"kenaito-media-picker/internal/scanner"
|
|
"kenaito-media-picker/internal/store"
|
|
)
|
|
|
|
func TestResumeMatchSize(t *testing.T) {
|
|
dir := t.TempDir()
|
|
p := filepath.Join(dir, "a.jpg")
|
|
os.WriteFile(p, []byte("hello world hello world"), 0644)
|
|
st, _ := os.Stat(p)
|
|
|
|
org := New(filepath.Join(dir, "out"), "", "", nil, nil)
|
|
org.resume = map[string]store.ScanLog{
|
|
p: {SourcePath: p, TargetDir: filepath.Join(dir, "out", "图片_测试"), FileSize: st.Size()},
|
|
}
|
|
f := scanner.File{Path: p, Name: "a.jpg", Ext: ".jpg", Mime: "image/jpeg"}
|
|
|
|
sl, ok := org.matchResume(f)
|
|
if !ok || sl.TargetDir != filepath.Join(dir, "out", "图片_测试") {
|
|
t.Fatalf("内容未变应命中续传, ok=%v", ok)
|
|
}
|
|
|
|
// 内容变大 → 大小不同 → 不命中
|
|
os.WriteFile(p, []byte("hello world hello world extra bytes"), 0644)
|
|
if _, ok := org.matchResume(f); ok {
|
|
t.Fatal("内容变了(大小不同)应不命中续传")
|
|
}
|
|
|
|
// 没记录 → 不命中
|
|
org.resume = nil
|
|
if _, ok := org.matchResume(f); ok {
|
|
t.Fatal("无续传记录应不命中")
|
|
}
|
|
}
|
|
|
|
func TestResumeMatchFingerprint(t *testing.T) {
|
|
dir := t.TempDir()
|
|
p := filepath.Join(dir, "big.bin")
|
|
data := make([]byte, 2<<20)
|
|
for i := range data {
|
|
data[i] = byte(i)
|
|
}
|
|
os.WriteFile(p, data, 0644)
|
|
st, _ := os.Stat(p)
|
|
head, tail, err := digest.CalcFileFingerprint(p, st.Size())
|
|
if err != nil {
|
|
t.Fatalf("fingerprint: %v", err)
|
|
}
|
|
|
|
org := New(filepath.Join(dir, "out"), "", "", nil, nil)
|
|
org.resume = map[string]store.ScanLog{
|
|
p: {SourcePath: p, TargetDir: filepath.Join(dir, "out", "视频_测试"), FileSize: st.Size(), HeadMd5: head, TailMd5: tail},
|
|
}
|
|
f := scanner.File{Path: p, Name: "big.bin", Ext: ".bin", Mime: "video/mp4"}
|
|
|
|
if _, ok := org.matchResume(f); !ok {
|
|
t.Fatal("指纹一致应命中续传")
|
|
}
|
|
|
|
// 改文件头里一个字节、大小不变 → 指纹不同 → 不命中
|
|
mod := append([]byte(nil), data...)
|
|
mod[1024] ^= 0xFF
|
|
os.WriteFile(p, mod, 0644)
|
|
if _, ok := org.matchResume(f); ok {
|
|
t.Fatal("内容变了(大小相同)应不命中续传")
|
|
}
|
|
} |