feat: 媒体库添加手动色情标记功能,默认分页改为10条
This commit is contained in:
@@ -137,6 +137,34 @@ func (c *MediaController) Preview(ctx *gin.Context) {
|
||||
ctx.File(path)
|
||||
}
|
||||
|
||||
// UpdateManualNsfw 处理 PUT /api/media/:id/manual-nsfw:更新手动色情标记。
|
||||
func (c *MediaController) UpdateManualNsfw(ctx *gin.Context) {
|
||||
idStr := ctx.Param("id")
|
||||
var id int64
|
||||
if _, err := fmt.Sscanf(idStr, "%d", &id); err != nil || id <= 0 {
|
||||
Error(ctx, http.StatusBadRequest, "无效的 ID")
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Value string `json:"value"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
Error(ctx, http.StatusBadRequest, "请求参数错误:"+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Value != "Y" && req.Value != "N" {
|
||||
Error(ctx, http.StatusBadRequest, "值必须是 Y 或 N")
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.store.UpdateManualNsfw(id, req.Value); err != nil {
|
||||
Error(ctx, http.StatusInternalServerError, "更新失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
Success(ctx, nil)
|
||||
}
|
||||
|
||||
// toMediaView 给一条数据库记录补上展示用的派生字段。
|
||||
func toMediaView(m store.MediaInfo) mediaView {
|
||||
v := mediaView{MediaInfo: m}
|
||||
|
||||
@@ -33,6 +33,7 @@ func NewRouter(st *store.Store) *gin.Engine {
|
||||
apiGroup.POST("/media/list", mc.List)
|
||||
apiGroup.POST("/media/stats", mc.Stats)
|
||||
apiGroup.GET("/media/preview", mc.Preview)
|
||||
apiGroup.PUT("/media/:id/manual-nsfw", mc.UpdateManualNsfw)
|
||||
|
||||
// 扫描整理(开始 / 中止 / 移动 / 查进度 / 实时进度)
|
||||
sc := NewScanController(service.NewScanService(st))
|
||||
|
||||
@@ -49,6 +49,7 @@ type MediaInfo struct {
|
||||
TailMd5 string `xorm:"char(32) index('idx_fp') 'tail_md5'" json:"tailMd5"` // 文件尾 256KB 的 MD5(指纹用)
|
||||
NsfwScore float64 `xorm:"real 'nsfw_score'" json:"nsfwScore"` // NSFW 检测分 0~1(0 表示未检测或非图片)
|
||||
NsfwThreshold float64 `xorm:"real 'nsfw_threshold'" json:"nsfwThreshold"` // NSFW 判定阈值
|
||||
ManualNsfw string `xorm:"varchar(1) 'manual_nsfw'" json:"manualNsfw"` // 手动标记是否色情:Y/N,默认 N
|
||||
CreatedAt time.Time `xorm:"created 'created_at'" json:"createdAt"` // 首次入库时间
|
||||
UpdatedAt time.Time `xorm:"updated 'updated_at'" json:"updatedAt"` // 最近更新时间
|
||||
}
|
||||
@@ -219,6 +220,15 @@ func (s *Store) UpdateMediaFilePaths(moved map[string]string) error {
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// UpdateManualNsfw 更新单条记录的手动色情标记。
|
||||
func (s *Store) UpdateManualNsfw(id int64, value string) error {
|
||||
if s == nil || s.engine == nil {
|
||||
return nil
|
||||
}
|
||||
_, err := s.engine.ID(id).Update(&MediaInfo{ManualNsfw: value})
|
||||
return err
|
||||
}
|
||||
|
||||
// ============================ 媒体记录的新增/更新 ============================
|
||||
|
||||
// SaveMedia 保存/更新一条媒体记录:按 MD5 找,有就更新,没有就新增。
|
||||
|
||||
Reference in New Issue
Block a user