alist/server/meta.go

61 lines
1.1 KiB
Go
Raw Normal View History

2021-11-02 11:25:54 +00:00
package server
import (
"github.com/Xhofe/alist/model"
"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-11-13 07:53:26 +00:00
ErrorResp(c,err,500)
return
2021-11-02 11:25:54 +00:00
}
2021-11-13 07:53:26 +00:00
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 {
ErrorResp(c, err, 400)
return
}
req.Path = utils.ParsePath(req.Path)
if err := model.CreateMeta(req); err != nil {
ErrorResp(c, err, 500)
} else {
SuccessResp(c)
}
}
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 {
ErrorResp(c, err, 400)
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-11-13 07:53:26 +00:00
ErrorResp(c, err, 500)
2021-11-02 11:25:54 +00:00
} else {
2021-11-13 07:53:26 +00:00
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 {
ErrorResp(c, err, 400)
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-11-13 07:53:26 +00:00
ErrorResp(c, err, 500)
2021-11-13 08:49:03 +00:00
return
2021-11-02 11:25:54 +00:00
}
2021-11-13 07:53:26 +00:00
SuccessResp(c)
2021-11-02 11:25:54 +00:00
}