Files
alist/server/controllers/meta.go

62 lines
1.2 KiB
Go
Raw Normal View History

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