A:增加照片任务管理

This commit is contained in:
jimmy committed 2025-06-28 11:13:52 +08:00
1 parent f1d9764d1d
commit 25cc429091
11 files changed
+512 -126

No files matched your search

+55 -3
View File
@@ -6,17 +6,19 @@ import (
"net/http"
"rear/internal/container"
"rear/internal/model"
"rear/pkg/utils"
"strings"
"github.com/gin-gonic/gin"
)
type LibraryHandler struct {
container *container.Container
container *container.Container
imgContain *container.TaskContainer
}
func NewLibraryHandler(container *container.Container) *LibraryHandler {
return &LibraryHandler{container: container}
func NewLibraryHandler(container *container.Container, imgContain *container.TaskContainer) *LibraryHandler {
return &LibraryHandler{container: container, imgContain: imgContain}
}
// GetLibrary 获取存储
@@ -57,6 +59,7 @@ func (h *LibraryHandler) AddLibrary(c *gin.Context) {
// 验证路径
path := strings.TrimSpace(req.Path)
log.Printf("Add library path: %s", path)
if path == "" {
c.JSON(http.StatusBadRequest, model.Response{
Code: http.StatusBadRequest,
@@ -139,3 +142,52 @@ func (h *LibraryHandler) DeleteLibrary(c *gin.Context) {
Message: "Library deleted successfully",
})
}
// LibraryIndex 开始图片检索【缩略图生成】
func (h *LibraryHandler) LibraryIndex(c *gin.Context) {
// 获取所有已添加路径
library, err := h.container.LibraryRepo.GetAllLibrary()
if err != nil {
c.JSON(http.StatusInternalServerError, model.Response{
Code: http.StatusInternalServerError,
Message: err.Error(),
})
return
}
if len(library) == 0 {
c.JSON(http.StatusInternalServerError, model.Response{
Code: http.StatusOK,
Message: "无可用路径, 任务取消!",
})
return
}
// 存在可用路径,检索开始
var dirs []string // 创建一个空的 string 切片
for i := range library {
path := library[i]
isDir := utils.FileUtils.IsDir(path.ImgPath)
log.Printf(path.ImgPath)
if isDir {
dirs = append(dirs, path.ImgPath)
}
}
if len(dirs) == 0 {
c.JSON(http.StatusInternalServerError, model.Response{
Code: http.StatusOK,
Message: "无可用路径, 任务结束!",
})
return
}
// 获取可用路径下所有的照片【指定类型】
//utils.FileUtils.GetAllFiles()
// 启动后台任务,开始处理
//h.imgContain.ImgTaskManager.AddTask()
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
Message: "索引任务已启动",
})
}