🎇 指定路径与深度rebuild

This commit is contained in:
微凉
2021-04-14 13:34:14 +08:00
parent b613598c2b
commit 427244d8d5
9 changed files with 123 additions and 25 deletions

View File

@ -3,8 +3,8 @@ package controllers
import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/server/models"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
// handle info request
@ -12,14 +12,21 @@ func Info(c *gin.Context) {
c.JSON(200, DataResponse(conf.Conf.Info))
}
type RebuildReq struct {
Path string `json:"path" binding:"required"`
Password string `json:"password"`
Depth int `json:"depth"`
}
// rebuild tree
func RebuildTree(c *gin.Context) {
drive := utils.GetDriveByName(c.Param("drive"))
if drive == nil {
c.JSON(200, MetaResponse(400, "drive isn't exist."))
var req RebuildReq
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
return
}
password := c.Param("password")
log.Debugf("rebuild:%+v", req)
password := req.Password
if password != conf.Conf.Server.Password {
if password == "" {
c.JSON(200, MetaResponse(401, "need password."))
@ -28,11 +35,7 @@ func RebuildTree(c *gin.Context) {
c.JSON(200, MetaResponse(401, "wrong password."))
return
}
if err := models.Clear(drive); err != nil {
c.JSON(200, MetaResponse(500, err.Error()))
return
}
if err := models.BuildTree(drive); err != nil {
if err := models.BuildTreeWithPath(req.Path, req.Depth); err != nil {
c.JSON(200, MetaResponse(500, err.Error()))
return
}