🚧 参数校验
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// get request bean
|
// get request bean
|
||||||
type GetReq struct {
|
type GetReq struct {
|
||||||
File string `json:"file"`
|
File string `json:"file" binding:"required"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ type GetReq struct {
|
|||||||
func Get(c *gin.Context) {
|
func Get(c *gin.Context) {
|
||||||
var get GetReq
|
var get GetReq
|
||||||
if err := c.ShouldBindJSON(&get); err != nil {
|
if err := c.ShouldBindJSON(&get); err != nil {
|
||||||
c.JSON(200, MetaResponse(400, "Bad Request."))
|
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("list:%+v", get)
|
log.Debugf("list:%+v", get)
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
// list request bean
|
// list request bean
|
||||||
type ListReq struct {
|
type ListReq struct {
|
||||||
Path string `json:"path"`
|
Path string `json:"path" binding:"required"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ type ListReq struct {
|
|||||||
func List(c *gin.Context) {
|
func List(c *gin.Context) {
|
||||||
var list ListReq
|
var list ListReq
|
||||||
if err := c.ShouldBindJSON(&list); err != nil {
|
if err := c.ShouldBindJSON(&list); err != nil {
|
||||||
c.JSON(200, MetaResponse(400, "Bad Request."))
|
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("list:%+v", list)
|
log.Debugf("list:%+v", list)
|
||||||
@@ -43,6 +43,10 @@ func List(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
files, err := models.GetFilesByParentPath(list.Path + "/")
|
files, err := models.GetFilesByParentPath(list.Path + "/")
|
||||||
|
// delete password
|
||||||
|
for i, _ := range *files {
|
||||||
|
(*files)[i].Password = ""
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, MetaResponse(500, err.Error()))
|
c.JSON(200, MetaResponse(500, err.Error()))
|
||||||
return
|
return
|
||||||
|
@@ -6,11 +6,15 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type OfficePreviewReq struct {
|
||||||
|
FileId string `json:"file_id" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// handle office_preview request
|
// handle office_preview request
|
||||||
func OfficePreview(c *gin.Context) {
|
func OfficePreview(c *gin.Context) {
|
||||||
var req alidrive.OfficePreviewUrlReq
|
var req OfficePreviewReq
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(200, MetaResponse(400, "Bad Request"))
|
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("preview_req:%+v", req)
|
log.Debugf("preview_req:%+v", req)
|
||||||
|
@@ -1 +1,11 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
func LocalSearch(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GlobalSearch(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
@@ -27,6 +27,8 @@ func InitApiRouter(engine *gin.Engine) {
|
|||||||
apiV2.POST("/list", controllers.List)
|
apiV2.POST("/list", controllers.List)
|
||||||
apiV2.POST("/get", controllers.Get)
|
apiV2.POST("/get", controllers.Get)
|
||||||
apiV2.POST("/office_preview", controllers.OfficePreview)
|
apiV2.POST("/office_preview", controllers.OfficePreview)
|
||||||
|
apiV2.POST("/local_search", controllers.LocalSearch)
|
||||||
|
apiV2.POST("/global_search", controllers.GlobalSearch)
|
||||||
}
|
}
|
||||||
engine.GET("/d/*file", controllers.Down)
|
engine.GET("/d/*file", controllers.Down)
|
||||||
engine.GET("/rebuild", controllers.RebuildTree)
|
engine.GET("/rebuild", controllers.RebuildTree)
|
||||||
|
Reference in New Issue
Block a user