Files
OpenList/server/meta.go

40 lines
722 B
Go
Raw Normal View History

2021-11-02 19:25:54 +08:00
package server
import (
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
2021-11-13 15:53:26 +08:00
"github.com/gin-gonic/gin"
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-11-13 15:53:26 +08:00
ErrorResp(c,err,500)
return
2021-11-02 19:25:54 +08:00
}
2021-11-13 15:53:26 +08:00
SuccessResp(c, metas)
2021-11-02 19:25:54 +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 {
ErrorResp(c, err, 400)
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-11-13 15:53:26 +08:00
ErrorResp(c, err, 500)
2021-11-02 19:25:54 +08:00
} else {
2021-11-13 15:53:26 +08:00
SuccessResp(c)
2021-11-02 19:25:54 +08:00
}
}
2021-11-13 15:53:26 +08:00
func DeleteMeta(c *gin.Context) {
path := c.Query("path")
2021-11-04 23:25:53 +08:00
//path = utils.ParsePath(path)
2021-11-02 19:25:54 +08:00
if err := model.DeleteMeta(path); err != nil {
2021-11-13 15:53:26 +08:00
ErrorResp(c, err, 500)
2021-11-02 19:25:54 +08:00
}
2021-11-13 15:53:26 +08:00
SuccessResp(c)
2021-11-02 19:25:54 +08:00
}