Compare commits
No commits in common. "87ae7db41c241645c0f207e0c20bae4fe7a3ffcc" and "50fef88276b9b228047db1ab519e8567de395bef" have entirely different histories.
87ae7db41c
...
50fef88276
|
|
@ -18,13 +18,13 @@ type File struct {
|
||||||
Md5 string `gorm:"column:md5;type:varchar(255);uniqueIndex:idx_file_name"`
|
Md5 string `gorm:"column:md5;type:varchar(255);uniqueIndex:idx_file_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFile(fileStoreName, fileName, fileType, filePath string, fileSize, authID int, NeedAuth bool) File {
|
func CreateFile(fileStoreName, fileName, fileType, filePath string, fileSize, authID int, NeedAuth bool) uint {
|
||||||
file := File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize, AuthID: authID, NeedAuth: NeedAuth}
|
file := File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize, AuthID: authID, NeedAuth: NeedAuth}
|
||||||
result := DB.Create(&file)
|
result := DB.Create(&file)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return file
|
return file.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteFileByID(id, user int) bool {
|
func DeleteFileByID(id, user int) bool {
|
||||||
|
|
|
||||||
|
|
@ -173,13 +173,19 @@ func UploadFile(c *gin.Context) {
|
||||||
} else if authType == "private" {
|
} else if authType == "private" {
|
||||||
auth_type_ = true
|
auth_type_ = true
|
||||||
}
|
}
|
||||||
file_record := dao.CreateFile(fileStoreName, fileName, fileType, filePath, fileSize, id1, auth_type_)
|
fileID := dao.CreateFile(fileStoreName, fileName, fileType, filePath, fileSize, id1, auth_type_)
|
||||||
if file_record.ID == 0 {
|
if fileID == 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "save file info failed", "code": proto.SaveFileInfoFailed, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "save file info failed", "code": proto.SaveFileInfoFailed, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
file_record.FilePath = ""
|
ret := map[string]interface{}{
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": file_record})
|
"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})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue