Daniel 2024-03-20 23:18:32 +08:00
parent b9b1436572
commit 580209b165
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -147,6 +147,11 @@ func Upload(c *gin.Context) {
var errFiles []string
succMap := map[string]interface{}{}
files := form.File["file[]"]
skipIfDuplicated := false // 默认不跳过重复文件,但是有的场景需要跳过,比如上传 PDF 标注图片 https://github.com/siyuan-note/siyuan/issues/10666
if nil != form.Value["skipIfDuplicated"] {
skipIfDuplicated = "true" == form.Value["skipIfDuplicated"][0]
}
for _, file := range files {
baseName := file.Filename
@ -182,6 +187,20 @@ func Upload(c *gin.Context) {
// 已经存在同样数据的资源文件的话不重复保存
succMap[baseName] = existAsset.Path
} else {
if skipIfDuplicated {
matches, globErr := filepath.Glob(assetsDirPath + string(os.PathSeparator) + strings.TrimSuffix(fName, ext) + "*")
if nil != globErr {
logging.LogErrorf("glob failed: %s", globErr)
} else {
if 0 < len(matches) {
fName = filepath.Base(matches[0])
succMap[baseName] = strings.TrimPrefix(path.Join(relAssetsDirPath, fName), "/")
f.Close()
break
}
}
}
fName = util.AssetName(fName)
writePath := filepath.Join(assetsDirPath, fName)
tmpDir := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))