mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
1acbb7d06d
commit
ea925aff32
1 changed files with 27 additions and 4 deletions
|
|
@ -84,14 +84,26 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa
|
||||||
err = openErr
|
err = openErr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hash, hashErr := util.GetEtagByHandle(f, fi.Size())
|
hash, hashErr := util.GetEtagByHandle(f, fi.Size())
|
||||||
if nil != hashErr {
|
if nil != hashErr {
|
||||||
f.Close()
|
f.Close()
|
||||||
return
|
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
|
succMap[baseName] = existAssetPath
|
||||||
} else {
|
} else {
|
||||||
fName = util.AssetName(fName, ast.NewNodeID())
|
fName = util.AssetName(fName, ast.NewNodeID())
|
||||||
|
|
@ -200,8 +212,19 @@ func Upload(c *gin.Context) {
|
||||||
break
|
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
|
succMap[baseName] = existAssetPath
|
||||||
} else {
|
} else {
|
||||||
if skipIfDuplicated {
|
if skipIfDuplicated {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue