From e4d206d59c7866cdf5c94228186497018204e1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <36558727+Xhofe@users.noreply.github.com> Date: Mon, 8 Mar 2021 20:28:44 +0800 Subject: [PATCH] =?UTF-8?q?:small=5Fblue=5Fdiamond:=20=E5=88=A0=E9=99=A4li?= =?UTF-8?q?st=E4=B8=8Eget=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/{get.go => down.go} | 35 ---------------- server/controllers/list.go | 55 -------------------------- server/router.go | 2 - 3 files changed, 92 deletions(-) rename server/controllers/{get.go => down.go} (59%) delete mode 100644 server/controllers/list.go diff --git a/server/controllers/get.go b/server/controllers/down.go similarity index 59% rename from server/controllers/get.go rename to server/controllers/down.go index 67a9198c..3f2ac7fb 100644 --- a/server/controllers/get.go +++ b/server/controllers/down.go @@ -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"` } diff --git a/server/controllers/list.go b/server/controllers/list.go deleted file mode 100644 index 08ac97e8..00000000 --- a/server/controllers/list.go +++ /dev/null @@ -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)) -} diff --git a/server/router.go b/server/router.go index f1e37e6a..0391a0f3 100644 --- a/server/router.go +++ b/server/router.go @@ -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)