修复文件保存已有文件名问题

This commit is contained in:
junleea 2025-04-05 13:57:15 +08:00
parent 61ff3b0547
commit f4925cf693
2 changed files with 28 additions and 2 deletions

View File

@ -282,3 +282,15 @@ func GetUserFileSpace(userID int) UserFileSpace {
}
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
}

View File

@ -15,6 +15,7 @@ import (
"os"
"path"
"regexp"
"strings"
"time"
)
@ -245,8 +246,17 @@ func DeleteUserFile(userID, fileAuthID int) error {
}
func CreateUserFile(userID int, fileAuthName string, fileID int, UploadType string) dao.FileAuth {
fileAuth := dao.CreateFileAuth(userID, fileID, fileAuthName, UploadType, 1, "")
return fileAuth
//先查fileAuthName是否存在
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 {
@ -264,3 +274,7 @@ func FindUserFileList(userID int, uploadType string) []dao.UserFileListResp {
log.Println("FindUserFileList res:", len(res))
return res
}
func CreateUserFileAfterUnique() {
}