From c9620b64dc809be6c6fc2d97449284b0bc7e63b4 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 27 Dec 2024 20:30:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/file.go | 4 ++-- handler/tool.go | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/dao/file.go b/dao/file.go index 96e4428..c44c1f0 100644 --- a/dao/file.go +++ b/dao/file.go @@ -18,13 +18,13 @@ type File struct { Md5 string `gorm:"column:md5;type:varchar(255);uniqueIndex:idx_file_name"` } -func CreateFile(fileStoreName, fileName, fileType, filePath string, fileSize, authID int, NeedAuth bool) uint { +func CreateFile(fileStoreName, fileName, fileType, filePath string, fileSize, authID int, NeedAuth bool) File { file := File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize, AuthID: authID, NeedAuth: NeedAuth} result := DB.Create(&file) if result.Error != nil { return 0 } - return file.ID + return file } func DeleteFileByID(id, user int) bool { diff --git a/handler/tool.go b/handler/tool.go index 9b75745..42a387c 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -173,19 +173,13 @@ func UploadFile(c *gin.Context) { } else if authType == "private" { auth_type_ = true } - fileID := dao.CreateFile(fileStoreName, fileName, fileType, filePath, fileSize, id1, auth_type_) - if fileID == 0 { + file_record := dao.CreateFile(fileStoreName, fileName, fileType, filePath, fileSize, id1, auth_type_) + if file_record.ID == 0 { c.JSON(http.StatusOK, gin.H{"error": "save file info failed", "code": proto.SaveFileInfoFailed, "message": "failed"}) return } - ret := map[string]interface{}{ - "file_id": fileID, - "file_store_name": fileStoreName, - "file_name": fileName, - "file_size": fileSize, - "file_type": fileType, - } - c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": ret}) + file_record.FilePath = "" + c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": file_record}) }