修复文件保存已有文件名问题
This commit is contained in:
parent
61ff3b0547
commit
f4925cf693
12
dao/file.go
12
dao/file.go
|
|
@ -282,3 +282,15 @@ func GetUserFileSpace(userID int) UserFileSpace {
|
||||||
}
|
}
|
||||||
return space
|
return space
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindFileAuthByName(fileName string, userID int) FileAuth {
|
||||||
|
var file FileAuth
|
||||||
|
var db2 *gorm.DB
|
||||||
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
|
db2 = DB.Debug()
|
||||||
|
} else {
|
||||||
|
db2 = DB
|
||||||
|
}
|
||||||
|
db2.Where("user_file_name = ? and auth_id = ?", fileName, userID).First(&file)
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -245,8 +246,17 @@ func DeleteUserFile(userID, fileAuthID int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUserFile(userID int, fileAuthName string, fileID int, UploadType string) dao.FileAuth {
|
func CreateUserFile(userID int, fileAuthName string, fileID int, UploadType string) dao.FileAuth {
|
||||||
fileAuth := dao.CreateFileAuth(userID, fileID, fileAuthName, UploadType, 1, "")
|
//先查fileAuthName是否存在
|
||||||
return fileAuth
|
fileAuth := dao.FindFileAuthByName(fileAuthName, userID)
|
||||||
|
if fileAuth.ID != 0 {
|
||||||
|
log.Println("file auth name already exist, please change another name: ", fileAuthName)
|
||||||
|
//将要保存的文件名改为fileAuthName+uuid
|
||||||
|
strs := strings.Split(fileAuthName, ".")
|
||||||
|
fileAuthName = strs[0] + "_1." + strs[1]
|
||||||
|
//return fileAuth
|
||||||
|
}
|
||||||
|
fileAuth_ := dao.CreateFileAuth(userID, fileID, fileAuthName, UploadType, 1, "")
|
||||||
|
return fileAuth_
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp {
|
func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp {
|
||||||
|
|
@ -264,3 +274,7 @@ func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp {
|
||||||
log.Println("FindUserFileList res:", len(res))
|
log.Println("FindUserFileList res:", len(res))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateUserFileAfterUnique() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue