2020-12-29 13:37:58 +08:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Xhofe/alist/conf"
|
2021-03-05 21:07:45 +08:00
|
|
|
"github.com/Xhofe/alist/server/models"
|
2020-12-29 13:37:58 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2021-04-14 13:34:14 +08:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-12-29 13:37:58 +08:00
|
|
|
)
|
|
|
|
|
2021-02-04 10:02:34 +08:00
|
|
|
// handle info request
|
2020-12-29 13:37:58 +08:00
|
|
|
func Info(c *gin.Context) {
|
2021-01-11 16:53:48 +08:00
|
|
|
c.JSON(200, DataResponse(conf.Conf.Info))
|
2020-12-29 13:37:58 +08:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:34:14 +08:00
|
|
|
type RebuildReq struct {
|
|
|
|
Path string `json:"path" binding:"required"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Depth int `json:"depth"`
|
|
|
|
}
|
|
|
|
|
2021-03-05 21:07:45 +08:00
|
|
|
// rebuild tree
|
|
|
|
func RebuildTree(c *gin.Context) {
|
2021-04-14 13:34:14 +08:00
|
|
|
var req RebuildReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
2021-03-16 21:25:16 +08:00
|
|
|
return
|
|
|
|
}
|
2021-04-14 13:34:14 +08:00
|
|
|
log.Debugf("rebuild:%+v", req)
|
|
|
|
password := req.Password
|
2021-03-08 20:26:02 +08:00
|
|
|
if password != conf.Conf.Server.Password {
|
|
|
|
if password == "" {
|
|
|
|
c.JSON(200, MetaResponse(401, "need password."))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.JSON(200, MetaResponse(401, "wrong password."))
|
|
|
|
return
|
|
|
|
}
|
2021-04-14 13:34:14 +08:00
|
|
|
if err := models.BuildTreeWithPath(req.Path, req.Depth); err != nil {
|
2021-03-05 21:25:44 +08:00
|
|
|
c.JSON(200, MetaResponse(500, err.Error()))
|
2021-03-05 21:07:45 +08:00
|
|
|
return
|
|
|
|
}
|
2021-03-05 21:25:44 +08:00
|
|
|
c.JSON(200, MetaResponse(200, "success."))
|
2021-03-05 21:07:45 +08:00
|
|
|
return
|
2021-03-05 21:25:44 +08:00
|
|
|
}
|