feat: 目录选择后自动保存配置到数据库

This commit is contained in:
2025-09-10 21:17:10 +08:00
parent dd2bb8fd50
commit 5b95f778c9
3 changed files with 45 additions and 2 deletions
+13 -2
View File
@@ -466,8 +466,8 @@ export default {
this.dirLoading = false this.dirLoading = false
} }
}, },
// 点"选中此目录":把选中的目录填到对应的输入框里 // 点"选中此目录":把选中的目录填到对应的输入框里,并保存配置
confirmDir() { async confirmDir() {
if (!this.fsData.current) return if (!this.fsData.current) return
if (this.pickerTarget === 'dest') { if (this.pickerTarget === 'dest') {
this.destDir = this.fsData.current this.destDir = this.fsData.current
@@ -475,6 +475,17 @@ export default {
this.scanDir = this.fsData.current this.scanDir = this.fsData.current
} }
this.dirPickerVisible = false this.dirPickerVisible = false
// 保存目录配置到数据库
try {
await request.put('/api/config/scan-dir', {
scanDir: this.scanDir.trim(),
destDir: this.destDir.trim()
})
} catch (e) {
// 保存失败不影响使用,只是下次进来不会自动回填
console.warn('保存目录配置失败', e)
}
}, },
// ==================== 小工具 ==================== // ==================== 小工具 ====================
+31
View File
@@ -15,6 +15,8 @@ const (
ConfigKeyNsfwType = "nsfw.type" // 检测类型:"" / "human" / "anime" ConfigKeyNsfwType = "nsfw.type" // 检测类型:"" / "human" / "anime"
ConfigKeyNsfwThreshold = "nsfw.threshold" // 人类检测阈值 ConfigKeyNsfwThreshold = "nsfw.threshold" // 人类检测阈值
ConfigKeyAnimeNsfwThreshold = "anime.threshold" // 二次元检测阈值 ConfigKeyAnimeNsfwThreshold = "anime.threshold" // 二次元检测阈值
ConfigKeyScanDir = "scan.scanDir" // 扫描目录
ConfigKeyDestDir = "scan.destDir" // 存放目录
) )
// ConfigController 配置相关接口。 // ConfigController 配置相关接口。
@@ -104,3 +106,32 @@ func (c *ConfigController) UpdateNsfwConfig(ctx *gin.Context) {
Success(ctx, nil) Success(ctx, nil)
} }
// UpdateScanDirReq 更新扫描目录配置请求。
type UpdateScanDirReq struct {
ScanDir string `json:"scanDir"` // 扫描目录
DestDir string `json:"destDir"` // 存放目录
}
// UpdateScanDir 处理 PUT /api/config/scan-dir:更新扫描目录配置。
func (c *ConfigController) UpdateScanDir(ctx *gin.Context) {
var req UpdateScanDirReq
if err := ctx.ShouldBindJSON(&req); err != nil {
Error(ctx, http.StatusBadRequest, "请求参数错误:"+err.Error())
return
}
// 保存扫描目录
if err := c.store.SaveConfig(ConfigKeyScanDir, req.ScanDir); err != nil {
Error(ctx, http.StatusInternalServerError, "保存扫描目录失败:"+err.Error())
return
}
// 保存存放目录
if err := c.store.SaveConfig(ConfigKeyDestDir, req.DestDir); err != nil {
Error(ctx, http.StatusInternalServerError, "保存存放目录失败:"+err.Error())
return
}
Success(ctx, nil)
}
+1
View File
@@ -52,6 +52,7 @@ func NewRouter(st *store.Store) *gin.Engine {
cc := NewConfigController(st) cc := NewConfigController(st)
apiGroup.GET("/config/nsfw", cc.GetNsfwConfig) apiGroup.GET("/config/nsfw", cc.GetNsfwConfig)
apiGroup.PUT("/config/nsfw", cc.UpdateNsfwConfig) apiGroup.PUT("/config/nsfw", cc.UpdateNsfwConfig)
apiGroup.PUT("/config/scan-dir", cc.UpdateScanDir)
} }
return r return r
} }