Skip to content

Commit

Permalink
🚧 参数校验
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Mar 7, 2021
1 parent b677d6a commit c0f50ff
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions server/controllers/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

// get request bean
type GetReq struct {
File string `json:"file"`
File string `json:"file" 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."))
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
return
}
log.Debugf("list:%+v", get)
Expand Down
8 changes: 6 additions & 2 deletions server/controllers/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

// list request bean
type ListReq struct {
Path string `json:"path"`
Path string `json:"path" 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."))
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
return
}
log.Debugf("list:%+v", list)
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions server/controllers/offie_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions server/controllers/search.go
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
package controllers

import "github.com/gin-gonic/gin"

func LocalSearch(c *gin.Context) {

}

func GlobalSearch(c *gin.Context) {

}
2 changes: 2 additions & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c0f50ff

Please sign in to comment.