mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02: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
|
@ -154,7 +154,7 @@ func extensionCopy(c *gin.Context) {
|
|||
fName += ext
|
||||
}
|
||||
|
||||
fName = util.AssetName(fName)
|
||||
fName = util.AssetName(fName, ast.NewNodeID())
|
||||
writePath := filepath.Join(assets, fName)
|
||||
if err = filelock.WriteFile(writePath, data); err != nil {
|
||||
ret.Code = -1
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
@ -289,5 +290,5 @@ func FilterUploadFileName(name string) string {
|
|||
}
|
||||
|
||||
func AssetName(name string) string {
|
||||
return util.AssetName(name)
|
||||
return util.AssetName(name, ast.NewNodeID())
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
name := filepath.Base(u)
|
||||
name = util.FilterUploadFileName(name)
|
||||
name = "network-asset-" + name
|
||||
name = util.AssetName(name)
|
||||
name = util.AssetName(name, ast.NewNodeID())
|
||||
writePath := filepath.Join(assetsDirPath, name)
|
||||
if err = filelock.Copy(u, writePath); err != nil {
|
||||
logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err)
|
||||
|
@ -303,7 +303,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
name += ext
|
||||
}
|
||||
}
|
||||
name = util.AssetName(name)
|
||||
name = util.AssetName(name, ast.NewNodeID())
|
||||
name = "network-asset-" + name
|
||||
writePath := filepath.Join(assetsDirPath, name)
|
||||
if err = filelock.WriteFile(writePath, data); err != nil {
|
||||
|
@ -737,7 +737,7 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
newName = util.AssetName(newName + filepath.Ext(oldPath))
|
||||
newName = util.AssetName(newName+filepath.Ext(oldPath), ast.NewNodeID())
|
||||
parentDir := path.Dir(oldPath)
|
||||
newPath = path.Join(parentDir, newName)
|
||||
oldAbsPath, getErr := GetAssetAbsPath(oldPath)
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/emersion/go-vcard"
|
||||
"github.com/emersion/go-webdav/carddav"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
@ -640,7 +641,7 @@ func (b *AddressBook) load() error {
|
|||
addressesWaitGroup.Add(1)
|
||||
go func() {
|
||||
defer addressesWaitGroup.Done()
|
||||
filename_ := util.AssetName(filename)
|
||||
filename_ := util.AssetName(filename, ast.NewNodeID())
|
||||
address := &AddressObject{
|
||||
FilePath: path.Join(b.DirectoryPath, filename_),
|
||||
BookPath: b.MetaData.Path,
|
||||
|
|
|
@ -981,7 +981,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
if "" == existName {
|
||||
name = filepath.Base(absolutePath)
|
||||
name = util.FilterUploadFileName(name)
|
||||
name = util.AssetName(name)
|
||||
name = util.AssetName(name, ast.NewNodeID())
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
|
@ -1104,7 +1104,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
if "" == existName {
|
||||
name = filepath.Base(absolutePath)
|
||||
name = util.FilterUploadFileName(name)
|
||||
name = util.AssetName(name)
|
||||
name = util.AssetName(name, ast.NewNodeID())
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
|
@ -1249,7 +1249,7 @@ func processBase64Img(n *ast.Node, dest string, assetDirPath string) {
|
|||
name = alt.TokensStr() + ext
|
||||
}
|
||||
name = util.FilterUploadFileName(name)
|
||||
name = util.AssetName(name)
|
||||
name = util.AssetName(name, ast.NewNodeID())
|
||||
|
||||
tmp := filepath.Join(base64TmpDir, name)
|
||||
tmpFile, openErr := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE, 0644)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -172,12 +172,12 @@ func Ext(name string) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func AssetName(name string) string {
|
||||
func AssetName(name, newID string) string {
|
||||
_, id := LastID(name)
|
||||
ext := Ext(name)
|
||||
name = name[0 : len(name)-len(ext)]
|
||||
if !ast.IsNodeIDPattern(id) {
|
||||
id = ast.NewNodeID()
|
||||
id = newID
|
||||
name = name + "-" + id + ext
|
||||
} else {
|
||||
if !ast.IsNodeIDPattern(name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue