feat: 目录层级变更
This commit is contained in:
@@ -13,14 +13,12 @@ import (
|
||||
|
||||
// 配置键名(存储在 AppConfig 表中)
|
||||
const (
|
||||
ConfigKeyNsfwType = "nsfw.type" // 检测类型:"" / "human" / "anime"
|
||||
ConfigKeyNsfwThreshold = "nsfw.threshold" // 人类检测阈值
|
||||
ConfigKeyAnimeNsfwThreshold = "anime.threshold" // 二次元检测阈值
|
||||
ConfigKeyNsfwWorkers = "nsfw.workers" // 人类检测 worker 数量
|
||||
ConfigKeyAnimeNsfwWorkers = "anime.workers" // 二次元检测 worker 数量
|
||||
ConfigKeyOrganizeWorkers = "organize.workers" // Go 端探测/MIME/移动 worker 数量
|
||||
ConfigKeyScanDir = "scan.scanDir" // 扫描目录
|
||||
ConfigKeyDestDir = "scan.destDir" // 存放目录
|
||||
ConfigKeyNsfwType = "nsfw.type" // 检测类型:"" / "human" / "anime"
|
||||
ConfigKeyNsfwWorkers = "nsfw.workers" // 人类检测 worker 数量
|
||||
ConfigKeyAnimeNsfwWorkers = "anime.workers" // 二次元检测 worker 数量
|
||||
ConfigKeyOrganizeWorkers = "organize.workers" // Go 端探测/MIME/移动 worker 数量
|
||||
ConfigKeyScanDir = "scan.scanDir" // 扫描目录
|
||||
ConfigKeyDestDir = "scan.destDir" // 存放目录
|
||||
)
|
||||
|
||||
// ConfigController 配置相关接口。
|
||||
@@ -35,32 +33,16 @@ func NewConfigController(st *store.Store) *ConfigController {
|
||||
|
||||
// NsfwConfig NSFW 配置响应。
|
||||
type NsfwConfig struct {
|
||||
Type string `json:"type"` // 检测类型:"" / "human" / "anime"
|
||||
HumanThreshold float64 `json:"humanThreshold"` // 人类检测阈值
|
||||
AnimeThreshold float64 `json:"animeThreshold"` // 二次元检测阈值
|
||||
HumanWorkers int `json:"humanWorkers"` // 人类检测 worker 数量
|
||||
AnimeWorkers int `json:"animeWorkers"` // 二次元检测 worker 数量
|
||||
GoWorkers int `json:"goWorkers"` // Go 端 worker 数量
|
||||
Type string `json:"type"` // 检测类型:"" / "human" / "anime"
|
||||
HumanWorkers int `json:"humanWorkers"` // 人类检测 worker 数量
|
||||
AnimeWorkers int `json:"animeWorkers"` // 二次元检测 worker 数量
|
||||
GoWorkers int `json:"goWorkers"` // Go 端 worker 数量
|
||||
}
|
||||
|
||||
// GetNsfwConfig 处理 GET /api/config/nsfw:获取 NSFW 配置。
|
||||
func (c *ConfigController) GetNsfwConfig(ctx *gin.Context) {
|
||||
nsfwType := c.store.GetConfig(ConfigKeyNsfwType)
|
||||
|
||||
humanThreshold := 0.5
|
||||
if v := c.store.GetConfig(ConfigKeyNsfwThreshold); v != "" {
|
||||
if t, err := strconv.ParseFloat(v, 64); err == nil && t > 0 && t < 1 {
|
||||
humanThreshold = t
|
||||
}
|
||||
}
|
||||
|
||||
animeThreshold := 0.5
|
||||
if v := c.store.GetConfig(ConfigKeyAnimeNsfwThreshold); v != "" {
|
||||
if t, err := strconv.ParseFloat(v, 64); err == nil && t > 0 && t < 1 {
|
||||
animeThreshold = t
|
||||
}
|
||||
}
|
||||
|
||||
humanWorkers := 4
|
||||
if v := c.store.GetConfig(ConfigKeyNsfwWorkers); v != "" {
|
||||
if w, err := strconv.Atoi(v); err == nil && w > 0 {
|
||||
@@ -83,23 +65,19 @@ func (c *ConfigController) GetNsfwConfig(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
Success(ctx, NsfwConfig{
|
||||
Type: nsfwType,
|
||||
HumanThreshold: humanThreshold,
|
||||
AnimeThreshold: animeThreshold,
|
||||
HumanWorkers: humanWorkers,
|
||||
AnimeWorkers: animeWorkers,
|
||||
GoWorkers: goWorkers,
|
||||
Type: nsfwType,
|
||||
HumanWorkers: humanWorkers,
|
||||
AnimeWorkers: animeWorkers,
|
||||
GoWorkers: goWorkers,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateNsfwConfigReq 更新 NSFW 配置请求。
|
||||
type UpdateNsfwConfigReq struct {
|
||||
Type string `json:"type"` // 检测类型:"" / "human" / "anime"
|
||||
HumanThreshold float64 `json:"humanThreshold"` // 人类检测阈值
|
||||
AnimeThreshold float64 `json:"animeThreshold"` // 二次元检测阈值
|
||||
HumanWorkers int `json:"humanWorkers"` // 人类检测 worker 数量
|
||||
AnimeWorkers int `json:"animeWorkers"` // 二次元检测 worker 数量
|
||||
GoWorkers int `json:"goWorkers"` // Go 端 worker 数量(0 表示使用文件配置)
|
||||
Type string `json:"type"` // 检测类型:"" / "human" / "anime"
|
||||
HumanWorkers int `json:"humanWorkers"` // 人类检测 worker 数量
|
||||
AnimeWorkers int `json:"animeWorkers"` // 二次元检测 worker 数量
|
||||
GoWorkers int `json:"goWorkers"` // Go 端 worker 数量(0 表示使用文件配置)
|
||||
}
|
||||
|
||||
// UpdateNsfwConfig 处理 PUT /api/config/nsfw:更新 NSFW 配置。
|
||||
@@ -116,14 +94,6 @@ func (c *ConfigController) UpdateNsfwConfig(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 校验阈值范围
|
||||
if req.HumanThreshold <= 0 || req.HumanThreshold >= 1 {
|
||||
req.HumanThreshold = 0.5
|
||||
}
|
||||
if req.AnimeThreshold <= 0 || req.AnimeThreshold >= 1 {
|
||||
req.AnimeThreshold = 0.5
|
||||
}
|
||||
|
||||
// 校验 worker 数量
|
||||
if req.HumanWorkers <= 0 {
|
||||
req.HumanWorkers = 4
|
||||
@@ -140,14 +110,6 @@ func (c *ConfigController) UpdateNsfwConfig(ctx *gin.Context) {
|
||||
Error(ctx, http.StatusInternalServerError, "保存配置失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
if err := c.store.SaveConfig(ConfigKeyNsfwThreshold, strconv.FormatFloat(req.HumanThreshold, 'f', 2, 64)); err != nil {
|
||||
Error(ctx, http.StatusInternalServerError, "保存配置失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
if err := c.store.SaveConfig(ConfigKeyAnimeNsfwThreshold, strconv.FormatFloat(req.AnimeThreshold, 'f', 2, 64)); err != nil {
|
||||
Error(ctx, http.StatusInternalServerError, "保存配置失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
if err := c.store.SaveConfig(ConfigKeyNsfwWorkers, strconv.Itoa(req.HumanWorkers)); err != nil {
|
||||
Error(ctx, http.StatusInternalServerError, "保存配置失败:"+err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user