refactor: 将文件移动改为独立接口,扫描完成后手动触发

This commit is contained in:
2025-07-29 21:18:35 +08:00
parent 59b0206cf1
commit 2e01f6c3c9
7 changed files with 193 additions and 35 deletions
+2 -1
View File
@@ -34,10 +34,11 @@ func NewRouter(st *store.Store) *gin.Engine {
apiGroup.POST("/media/stats", mc.Stats)
apiGroup.GET("/media/preview", mc.Preview)
// 扫描整理(开始 / 中止 / 查进度 / 实时进度)
// 扫描整理(开始 / 中止 / 移动 / 查进度 / 实时进度)
sc := NewScanController(service.NewScanService(st))
apiGroup.POST("/scan/start", sc.Start)
apiGroup.POST("/scan/cancel", sc.Cancel)
apiGroup.POST("/scan/move", sc.Move)
apiGroup.GET("/scan/status", sc.Status)
apiGroup.GET("/scan/ws", sc.Ws)
+11
View File
@@ -57,3 +57,14 @@ func (c *ScanController) Cancel(ctx *gin.Context) {
}
Success(ctx, c.service.Status())
}
// Move 处理 POST /api/scan/move:触发文件移动操作。
// 根据扫描时记录的分类结果,将文件从源路径移动到目标目录。
// 只有在扫描完成后才能调用。
func (c *ScanController) Move(ctx *gin.Context) {
if err := c.service.Move(); err != nil {
Error(ctx, http.StatusBadRequest, err.Error())
return
}
Success(ctx, c.service.Status())
}