refactor: 移除二次元识别功能,增强 NSFW 检测
This commit is contained in:
+2
-77
@@ -75,20 +75,6 @@ type NsfwRecord struct {
|
||||
CreatedAt time.Time `xorm:"created 'created_at'" json:"createdAt"` // 检测时间
|
||||
}
|
||||
|
||||
// HentaiRecord 一条"二次元图片识别"的记录:哪张图、分级结果、标签、现在在哪。
|
||||
// 前端「二次元识别」页面查这张表展示检测结果,方便人工复核。
|
||||
type HentaiRecord struct {
|
||||
Id int64 `xorm:"pk autoincr 'id'" json:"id"` // 自增主键
|
||||
FilePath string `xorm:"text 'file_path'" json:"filePath"` // 检测时的源路径
|
||||
FileName string `xorm:"varchar(255) 'file_name'" json:"fileName"` // 文件名(含扩展名)
|
||||
Score float64 `xorm:"real 'score'" json:"score"` // 最高非 safe 分数 0~1
|
||||
Rating string `xorm:"varchar(32) 'rating'" json:"rating"` // 分级标签:safe / questionable / explicit
|
||||
Threshold float64 `xorm:"real 'threshold'" json:"threshold"` // 判定阈值
|
||||
TopTags string `xorm:"text 'top_tags'" json:"topTags"` // 高置信度标签(JSON 数组)
|
||||
MovedPath string `xorm:"text 'moved_path'" json:"movedPath"` // 整理后实际位置(预览用)
|
||||
CreatedAt time.Time `xorm:"created 'created_at'" json:"createdAt"` // 检测时间
|
||||
}
|
||||
|
||||
// ScanLog 一条"续传"记录:某个源文件上次被归类到了哪个目录。
|
||||
// 用途:扫描中断/出错后重跑时,已经归类过的文件直接复用上次的目标目录,
|
||||
// 不再重新探测尺寸 / 算 MD5 / 分析明暗 / 色情识别,省下几小时的重扫时间。
|
||||
@@ -120,8 +106,8 @@ func Open(dbPath string) (*Store, error) {
|
||||
_ = e.Close()
|
||||
return nil, err
|
||||
}
|
||||
// 自动创建/补全五张表(媒体记录表、配置表、色情识别记录表、二次元识别记录表、续传表)
|
||||
if err := e.Sync(new(MediaInfo), new(AppConfig), new(NsfwRecord), new(HentaiRecord), new(ScanLog)); err != nil {
|
||||
// 自动创建/补全四张表(媒体记录表、配置表、色情识别记录表、续传表)
|
||||
if err := e.Sync(new(MediaInfo), new(AppConfig), new(NsfwRecord), new(ScanLog)); err != nil {
|
||||
_ = e.Close()
|
||||
return nil, err
|
||||
}
|
||||
@@ -209,67 +195,6 @@ func (s *Store) ClearNsfw() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ============================ 二次元识别记录 ============================
|
||||
|
||||
// SaveHentaiBatch 批量保存二次元识别记录(一次扫描攒一批,最后统一写入)。
|
||||
func (s *Store) SaveHentaiBatch(records []*HentaiRecord) error {
|
||||
if s == nil || s.engine == nil || len(records) == 0 {
|
||||
return nil
|
||||
}
|
||||
const chunkSize = 100
|
||||
sess := s.engine.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(records); i += chunkSize {
|
||||
end := i + chunkSize
|
||||
if end > len(records) {
|
||||
end = len(records)
|
||||
}
|
||||
if _, err := sess.Insert(records[i:end]); err != nil {
|
||||
_ = sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// ClearHentai 清空二次元识别记录。每次开启二次元识别的扫描开始时调用。
|
||||
func (s *Store) ClearHentai() error {
|
||||
if s == nil || s.engine == nil {
|
||||
return nil
|
||||
}
|
||||
_, err := s.engine.Where("1 = 1").Delete(new(HentaiRecord))
|
||||
return err
|
||||
}
|
||||
|
||||
// ListHentai 查全部二次元识别记录,按检测分从高到低排。
|
||||
func (s *Store) ListHentai() ([]HentaiRecord, error) {
|
||||
if s == nil || s.engine == nil {
|
||||
return nil, nil
|
||||
}
|
||||
list := make([]HentaiRecord, 0)
|
||||
err := s.engine.Desc("score").Find(&list)
|
||||
return list, err
|
||||
}
|
||||
|
||||
// GetHentaiById 按 ID 查一条二次元识别记录。
|
||||
func (s *Store) GetHentaiById(id int64) (*HentaiRecord, error) {
|
||||
if s == nil || s.engine == nil {
|
||||
return nil, nil
|
||||
}
|
||||
record := new(HentaiRecord)
|
||||
has, err := s.engine.ID(id).Get(record)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !has {
|
||||
return nil, nil
|
||||
}
|
||||
return record, nil
|
||||
}
|
||||
|
||||
// ============================ 续传表 ============================
|
||||
|
||||
// LoadScanLog 把全部续传记录读出来,按源路径建索引,供扫描时快速判断"这个文件上次归到哪了"。
|
||||
|
||||
Reference in New Issue
Block a user