🎇 指定路径与深度rebuild
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user