Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/10666

Daniel580209b165b5
diff --git a/kernel/model/upload.go b/kernel/model/upload.go
index 405dd4170b..acd2291b2e 100644
--- a/kernel/model/upload.go
+++ b/kernel/model/upload.go
@@ -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))