mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🐛 PDF files with too long file names cannot generate annotated images https://github.com/siyuan-note/siyuan/issues/15739 https://github.com/siyuan-note/siyuan/issues/10666
This commit is contained in:
parent
1e95b68df6
commit
cfb976eb89
7 changed files with 34 additions and 15 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
|
@ -93,7 +94,7 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa
|
|||
// 已经存在同样数据的资源文件的话不重复保存
|
||||
succMap[baseName] = existAsset.Path
|
||||
} else {
|
||||
fName = util.AssetName(fName)
|
||||
fName = util.AssetName(fName, ast.NewNodeID())
|
||||
writePath := filepath.Join(assetsDirPath, fName)
|
||||
if _, err = f.Seek(0, io.SeekStart); err != nil {
|
||||
f.Close()
|
||||
|
|
@ -163,6 +164,10 @@ func Upload(c *gin.Context) {
|
|||
|
||||
for _, file := range files {
|
||||
baseName := file.Filename
|
||||
_, lastID := util.LastID(baseName)
|
||||
if !ast.IsNodeIDPattern(lastID) {
|
||||
lastID = ""
|
||||
}
|
||||
|
||||
needUnzip2Dir := false
|
||||
if gulu.OS.IsDarwin() {
|
||||
|
|
@ -198,7 +203,16 @@ func Upload(c *gin.Context) {
|
|||
} else {
|
||||
if skipIfDuplicated {
|
||||
// 复制 PDF 矩形注解时不再重复插入图片 No longer upload image repeatedly when copying PDF rectangle annotation https://github.com/siyuan-note/siyuan/issues/10666
|
||||
matches, globErr := filepath.Glob(assetsDirPath + string(os.PathSeparator) + strings.TrimSuffix(fName, ext) + "*" + ext)
|
||||
pattern := assetsDirPath + string(os.PathSeparator) + strings.TrimSuffix(fName, ext)
|
||||
_, patternLastID := util.LastID(fName)
|
||||
if lastID != "" && lastID != patternLastID {
|
||||
// 文件名太长被截断了,通过之前的 lastID 来匹配 PDF files with too long file names cannot generate annotated images https://github.com/siyuan-note/siyuan/issues/15739
|
||||
pattern = assetsDirPath + string(os.PathSeparator) + "*" + lastID + ext
|
||||
} else {
|
||||
pattern += "*" + ext
|
||||
}
|
||||
|
||||
matches, globErr := filepath.Glob(pattern)
|
||||
if nil != globErr {
|
||||
logging.LogErrorf("glob failed: %s", globErr)
|
||||
} else {
|
||||
|
|
@ -211,7 +225,10 @@ func Upload(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
fName = util.AssetName(fName)
|
||||
if "" == lastID {
|
||||
lastID = ast.NewNodeID()
|
||||
}
|
||||
fName = util.AssetName(fName, lastID)
|
||||
writePath := filepath.Join(assetsDirPath, fName)
|
||||
tmpDir := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
||||
if needUnzip2Dir {
|
||||
|
|
@ -248,7 +265,7 @@ func Upload(c *gin.Context) {
|
|||
fName = strings.TrimSuffix(fName, ext)
|
||||
ext = strings.ToLower(ext)
|
||||
fName += ext
|
||||
fName = util.AssetName(fName)
|
||||
fName = util.AssetName(fName, ast.NewNodeID())
|
||||
tmpDir2 := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
||||
if err = gulu.Zip.Unzip(writePath, tmpDir2); err != nil {
|
||||
errFiles = append(errFiles, fName)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue