A:增加默认资料库写入

This commit is contained in:
jimmy committed 2025-06-15 22:44:48 +08:00
1 parent 592b01a89b
commit 76d747bbd9
6 files changed
+36 -13

No files matched your search

+8 -5
View File
@@ -19,14 +19,17 @@ func HealthCheck(c *gin.Context) {
})
}
// BasicResponse 健康检查
func BasicResponse(c *gin.Context) {
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
Message: "OK",
Data: map[string]interface{}{
"timestamp": time.Now().Unix(),
"version": "1.0.0",
},
Data: "hi",
})
}
func BasicResponseV1(c *gin.Context) {
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
Message: "OK",
Data: "hi, this is v1",
})
}
+20 -2
View File
@@ -1,7 +1,9 @@
package handler
import (
"bytes"
"github.com/gin-gonic/gin"
"io"
"log"
"net/http"
"rear/internal/container"
@@ -38,14 +40,30 @@ func (h *Handler) GetLibrary(c *gin.Context) {
}
func (h *Handler) AddLibrary(c *gin.Context) {
var path string
if err := c.ShouldBindJSON(&path); err != nil {
// 定义请求体结构
type AddLibraryRequest struct {
Path string `json:"path"`
}
var req AddLibraryRequest
// 读取原始JSON数据(用于调试)
rawData, _ := c.GetRawData()
// 重新设置请求体,因为GetRawData()会消耗掉body
c.Request.Body = io.NopCloser(bytes.NewBuffer(rawData))
// 绑定JSON到结构体
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, model.Response{
Code: http.StatusBadRequest,
Message: "Invalid request body",
})
return
}
// 现在可以使用 req.Path
path := req.Path
library := &model.LibraryTable{
ImgPath: path,
IsEnable: true,