From d601fcd2108e8b35ed7e6ba463e51cba81dac901 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 28 Dec 2024 13:29:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEmd5=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/tool.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/handler/tool.go b/handler/tool.go index b1de959..e8a2de5 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -26,6 +26,11 @@ type SetDeviceStatusReq struct { Status string `json:"status" form:"status"` //设备状态 } +type GetFileListReq struct { + Type string `json:"type" form:"type"` //请求类型,1:按md5查询,2:按文件名查询;3:查询待删除文件 + Md5 string `json:"md5" form:"md5"` +} + func SetUpToolGroup(router *gin.Engine) { toolGroup := router.Group("/tool") toolGroup.POST("/set_redis", SetRedis) @@ -35,6 +40,7 @@ func SetUpToolGroup(router *gin.Engine) { toolGroup.POST("/upload", UploadFile) toolGroup.GET("/download", DownloadFile) toolGroup.GET("/file/:filename", GetFile) + toolGroup.POST("/file_list", GetFileList) //文件管理 toolGroup.POST("/file_del", DelFile) //服务器、设备状态接口 @@ -71,6 +77,29 @@ func SetDeviceStatusV2(c *gin.Context) { } +func GetFileList(c *gin.Context) { + //解析请求参数 + var req GetFileListReq + if err := c.ShouldBind(&req); err == nil { + if req.Type == "1" { + //按md5查询 + if req.Md5 == "" { + c.JSON(http.StatusOK, gin.H{"error": "md5 is empty", "code": proto.ParameterError, "message": "failed"}) + return + } + file := dao.FindFileByMd5(req.Md5) + if file.ID == 0 { + c.JSON(http.StatusOK, gin.H{"error": "file not found", "code": proto.FileNotFound, "message": "failed"}) + return + } + c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": file}) + } + } else { + c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"}) + return + } +} + func DelFile(c *gin.Context) { //先查看是否有权限 id, _ := c.Get("id")