alist/server/controllers/meta.go

62 lines
1.2 KiB
Go
Raw Normal View History

2021-12-07 07:56:43 +00:00
package controllers
2021-11-02 11:25:54 +00:00
import (
"github.com/Xhofe/alist/model"
2021-12-07 07:56:43 +00:00
"github.com/Xhofe/alist/server/common"
2021-11-02 11:25:54 +00:00
"github.com/Xhofe/alist/utils"
2021-11-13 07:53:26 +00:00
"github.com/gin-gonic/gin"
2021-11-13 09:10:44 +00:00
"strconv"
2021-11-02 11:25:54 +00:00
)
2021-11-13 07:53:26 +00:00
func GetMetas(c *gin.Context) {
2021-11-02 11:25:54 +00:00
metas,err := model.GetMetas()
if err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c,err,500)
2021-11-13 07:53:26 +00:00
return
2021-11-02 11:25:54 +00:00
}
2021-12-07 07:56:43 +00:00
common.SuccessResp(c, metas)
2021-11-02 11:25:54 +00:00
}
2021-11-13 08:49:03 +00:00
func CreateMeta(c *gin.Context) {
var req model.Meta
if err := c.ShouldBind(&req); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 400)
2021-11-13 08:49:03 +00:00
return
}
req.Path = utils.ParsePath(req.Path)
if err := model.CreateMeta(req); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 500)
2021-11-13 08:49:03 +00:00
} else {
2021-12-07 07:56:43 +00:00
common.SuccessResp(c)
2021-11-13 08:49:03 +00:00
}
}
2021-11-13 07:53:26 +00:00
func SaveMeta(c *gin.Context) {
2021-11-02 11:25:54 +00:00
var req model.Meta
2021-11-13 07:53:26 +00:00
if err := c.ShouldBind(&req); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 400)
2021-11-13 07:53:26 +00:00
return
2021-11-02 11:25:54 +00:00
}
2021-11-03 15:30:44 +00:00
req.Path = utils.ParsePath(req.Path)
2021-11-02 11:25:54 +00:00
if err := model.SaveMeta(req); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 500)
2021-11-02 11:25:54 +00:00
} else {
2021-12-07 07:56:43 +00:00
common.SuccessResp(c)
2021-11-02 11:25:54 +00:00
}
}
2021-11-13 07:53:26 +00:00
func DeleteMeta(c *gin.Context) {
2021-11-13 09:10:44 +00:00
idStr := c.Query("id")
id, err := strconv.Atoi(idStr)
if err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 400)
2021-11-13 09:10:44 +00:00
return
}
2021-11-04 15:25:53 +00:00
//path = utils.ParsePath(path)
2021-11-13 09:10:44 +00:00
if err := model.DeleteMeta(uint(id)); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 500)
2021-11-13 08:49:03 +00:00
return
2021-11-02 11:25:54 +00:00
}
2021-12-07 07:56:43 +00:00
common.SuccessResp(c)
2021-11-02 11:25:54 +00:00
}