🔹 删除list与get接口
This commit is contained in:
@ -8,41 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// get request bean
|
||||
type GetReq struct {
|
||||
Path string `json:"path" binding:"required"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// handle list request
|
||||
func Get(c *gin.Context) {
|
||||
var get GetReq
|
||||
if err := c.ShouldBindJSON(&get); err != nil {
|
||||
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
||||
return
|
||||
}
|
||||
log.Debugf("list:%+v", get)
|
||||
dir, name := filepath.Split(get.Path)
|
||||
file, err := models.GetFileByDirAndName(dir, name)
|
||||
if err != nil {
|
||||
if file == nil {
|
||||
c.JSON(200, MetaResponse(404, "Path not found."))
|
||||
return
|
||||
}
|
||||
c.JSON(200, MetaResponse(500, err.Error()))
|
||||
return
|
||||
}
|
||||
if file.Password != "" && file.Password != get.Password {
|
||||
if get.Password == "" {
|
||||
c.JSON(200, MetaResponse(401, "need password."))
|
||||
} else {
|
||||
c.JSON(200, MetaResponse(401, "wrong password."))
|
||||
}
|
||||
return
|
||||
}
|
||||
c.JSON(200, DataResponse(file))
|
||||
}
|
||||
|
||||
type DownReq struct {
|
||||
Password string `form:"pw"`
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/server/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// list request bean
|
||||
type ListReq struct {
|
||||
Dir string `json:"dir" binding:"required"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// handle list request
|
||||
func List(c *gin.Context) {
|
||||
var list ListReq
|
||||
if err := c.ShouldBindJSON(&list); err != nil {
|
||||
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
||||
return
|
||||
}
|
||||
log.Debugf("list:%+v", list)
|
||||
// find folder model
|
||||
dir, name := filepath.Split(list.Dir)
|
||||
file, err := models.GetFileByDirAndName(dir, name)
|
||||
if err != nil {
|
||||
// folder model not exist
|
||||
if file == nil {
|
||||
c.JSON(200, MetaResponse(404, "folder not found."))
|
||||
return
|
||||
}
|
||||
c.JSON(200, MetaResponse(500, err.Error()))
|
||||
return
|
||||
}
|
||||
// check password
|
||||
if file.Password != "" && file.Password != list.Password {
|
||||
if list.Password == "" {
|
||||
c.JSON(200, MetaResponse(401, "need password."))
|
||||
} else {
|
||||
c.JSON(200, MetaResponse(401, "wrong password."))
|
||||
}
|
||||
return
|
||||
}
|
||||
files, err := models.GetFilesByDir(list.Dir + "/")
|
||||
if err != nil {
|
||||
c.JSON(200, MetaResponse(500, err.Error()))
|
||||
return
|
||||
}
|
||||
// delete password
|
||||
for i, _ := range *files {
|
||||
(*files)[i].Password = ""
|
||||
}
|
||||
c.JSON(200, DataResponse(files))
|
||||
}
|
@ -24,8 +24,6 @@ func InitApiRouter(engine *gin.Engine) {
|
||||
apiV2 := engine.Group("/api")
|
||||
{
|
||||
apiV2.GET("/info", controllers.Info)
|
||||
apiV2.POST("/list", controllers.List)
|
||||
apiV2.POST("/get", controllers.Get)
|
||||
apiV2.POST("/path", controllers.Path)
|
||||
apiV2.POST("/office_preview", controllers.OfficePreview)
|
||||
apiV2.POST("/local_search", controllers.LocalSearch)
|
||||
|
Reference in New Issue
Block a user