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