Compare commits
No commits in common. "720322bfd64a5e84f2ad0b4e48fa942b6baf2322" and "87ae7db41c241645c0f207e0c20bae4fe7a3ffcc" have entirely different histories.
720322bfd6
...
87ae7db41c
|
|
@ -18,11 +18,11 @@ 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, md5Str string, fileSize, authID int, NeedAuth bool) File {
|
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, Md5: md5Str}
|
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 File{}
|
return 0
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,6 @@ func UploadFile(c *gin.Context) {
|
||||||
//从请求头获取upload_type
|
//从请求头获取upload_type
|
||||||
uploadType := c.PostForm("upload_type")
|
uploadType := c.PostForm("upload_type")
|
||||||
authType := c.PostForm("auth_type")
|
authType := c.PostForm("auth_type")
|
||||||
md5_ := c.PostForm("md5")
|
|
||||||
if uploadType == "" {
|
if uploadType == "" {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "upload_type is empty", "code": proto.ParameterError, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "upload_type is empty", "code": proto.ParameterError, "message": "failed"})
|
||||||
return
|
return
|
||||||
|
|
@ -144,16 +143,14 @@ func UploadFile(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//计算文件md5值
|
//计算文件md5值
|
||||||
if md5_ == "" {
|
|
||||||
file_, _ := file.Open()
|
file_, _ := file.Open()
|
||||||
md5_ = service.CalculateFileMd5(file_)
|
md5Value := service.CalculateFileMd5(file_)
|
||||||
if md5_ == "" {
|
if md5Value == "" {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "计算文件MD5值失败", "code": proto.UploadFileFailed, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "计算文件MD5值失败", "code": proto.UploadFileFailed, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//查询文件是否已存在
|
//查询文件是否已存在
|
||||||
fileExist := dao.FindFileByMd5(md5_)
|
fileExist := dao.FindFileByMd5(md5Value)
|
||||||
if fileExist.ID != 0 {
|
if fileExist.ID != 0 {
|
||||||
fileExist.FilePath = ""
|
fileExist.FilePath = ""
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": fileExist})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": fileExist})
|
||||||
|
|
@ -176,7 +173,7 @@ 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, md5_, fileSize, id1, auth_type_)
|
file_record := dao.CreateFile(fileStoreName, fileName, fileType, filePath, fileSize, id1, auth_type_)
|
||||||
if file_record.ID == 0 {
|
if file_record.ID == 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue