mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
This commit is contained in:
parent
b9b1436572
commit
580209b165
1 changed files with 19 additions and 0 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue