mirror of https://github.com/Xhofe/alist
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/alist-org/alist/v3/internal/db"
|
|
"github.com/alist-org/alist/v3/internal/model"
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
|
"github.com/alist-org/alist/v3/server/common"
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
"strconv"
|
|
)
|
|
|
|
func ListMetas(c *gin.Context) {
|
|
var req common.PageReq
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
common.ErrorResp(c, err, 400, true)
|
|
return
|
|
}
|
|
log.Debugf("%+v", req)
|
|
metas, total, err := db.GetMetas(req.PageIndex, req.PageSize)
|
|
if err != nil {
|
|
common.ErrorResp(c, err, 500)
|
|
return
|
|
}
|
|
common.SuccessResp(c, common.PageResp{
|
|
Content: metas,
|
|
Total: total,
|
|
})
|
|
}
|
|
|
|
func CreateMeta(c *gin.Context) {
|
|
var req model.Meta
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
common.ErrorResp(c, err, 400, true)
|
|
return
|
|
}
|
|
req.Path = utils.StandardizePath(req.Path)
|
|
if err := db.CreateMeta(&req); err != nil {
|
|
common.ErrorResp(c, err, 500)
|
|
} else {
|
|
common.SuccessResp(c)
|
|
}
|
|
}
|
|
|
|
func UpdateMeta(c *gin.Context) {
|
|
var req model.Meta
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
common.ErrorResp(c, err, 400, true)
|
|
return
|
|
}
|
|
req.Path = utils.StandardizePath(req.Path)
|
|
if err := db.UpdateMeta(&req); err != nil {
|
|
common.ErrorResp(c, err, 500)
|
|
} else {
|
|
common.SuccessResp(c)
|
|
}
|
|
}
|
|
|
|
func DeleteMeta(c *gin.Context) {
|
|
idStr := c.Query("id")
|
|
id, err := strconv.Atoi(idStr)
|
|
if err != nil {
|
|
common.ErrorResp(c, err, 400, true)
|
|
return
|
|
}
|
|
if err := db.DeleteMetaById(uint(id)); err != nil {
|
|
common.ErrorResp(c, err, 500)
|
|
return
|
|
}
|
|
common.SuccessResp(c)
|
|
}
|