Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-12-14 11:36:02 +08:00
parent 1acbb7d06d
commit ea925aff32
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -84,14 +84,26 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa
err = openErr
return
}
hash, hashErr := util.GetEtagByHandle(f, fi.Size())
if nil != hashErr {
f.Close()
return
}
if existAssetPath := GetAssetPathByHash(hash); "" != existAssetPath {
// 已经存在同样数据的资源文件的话不重复保存
if 1 > fi.Size() {
hash = "random_1_" + gulu.Rand.String(12)
}
existAssetPath := GetAssetPathByHash(hash)
if "" != existAssetPath {
originalName := util.RemoveID(filepath.Base(existAssetPath))
if fName != originalName {
hash = "random_2_" + gulu.Rand.String(12)
}
}
if "" != existAssetPath && !strings.HasPrefix(hash, "random_") {
succMap[baseName] = existAssetPath
} else {
fName = util.AssetName(fName, ast.NewNodeID())
@ -200,8 +212,19 @@ func Upload(c *gin.Context) {
break
}
if existAssetPath := GetAssetPathByHash(hash); "" != existAssetPath {
// 已经存在同样数据的资源文件的话不重复保存
if 1 > file.Size {
hash = "empty_" + gulu.Rand.String(12)
}
existAssetPath := GetAssetPathByHash(hash)
if "" != existAssetPath {
originalName := util.RemoveID(filepath.Base(existAssetPath))
if fName != originalName {
hash = "random_2_" + gulu.Rand.String(12)
}
}
if "" != existAssetPath && !strings.HasPrefix(hash, "random_") {
succMap[baseName] = existAssetPath
} else {
if skipIfDuplicated {