mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +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
|
|
@ -154,7 +154,7 @@ func extensionCopy(c *gin.Context) {
|
||||||
fName += ext
|
fName += ext
|
||||||
}
|
}
|
||||||
|
|
||||||
fName = util.AssetName(fName)
|
fName = util.AssetName(fName, ast.NewNodeID())
|
||||||
writePath := filepath.Join(assets, fName)
|
writePath := filepath.Join(assets, fName)
|
||||||
if err = filelock.WriteFile(writePath, data); err != nil {
|
if err = filelock.WriteFile(writePath, data); err != nil {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/88250/lute/ast"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/httpclient"
|
"github.com/siyuan-note/httpclient"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
|
@ -289,5 +290,5 @@ func FilterUploadFileName(name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssetName(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 := filepath.Base(u)
|
||||||
name = util.FilterUploadFileName(name)
|
name = util.FilterUploadFileName(name)
|
||||||
name = "network-asset-" + name
|
name = "network-asset-" + name
|
||||||
name = util.AssetName(name)
|
name = util.AssetName(name, ast.NewNodeID())
|
||||||
writePath := filepath.Join(assetsDirPath, name)
|
writePath := filepath.Join(assetsDirPath, name)
|
||||||
if err = filelock.Copy(u, writePath); err != nil {
|
if err = filelock.Copy(u, writePath); err != nil {
|
||||||
logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err)
|
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 += ext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name = util.AssetName(name)
|
name = util.AssetName(name, ast.NewNodeID())
|
||||||
name = "network-asset-" + name
|
name = "network-asset-" + name
|
||||||
writePath := filepath.Join(assetsDirPath, name)
|
writePath := filepath.Join(assetsDirPath, name)
|
||||||
if err = filelock.WriteFile(writePath, data); err != nil {
|
if err = filelock.WriteFile(writePath, data); err != nil {
|
||||||
|
|
@ -737,7 +737,7 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newName = util.AssetName(newName + filepath.Ext(oldPath))
|
newName = util.AssetName(newName+filepath.Ext(oldPath), ast.NewNodeID())
|
||||||
parentDir := path.Dir(oldPath)
|
parentDir := path.Dir(oldPath)
|
||||||
newPath = path.Join(parentDir, newName)
|
newPath = path.Join(parentDir, newName)
|
||||||
oldAbsPath, getErr := GetAssetAbsPath(oldPath)
|
oldAbsPath, getErr := GetAssetAbsPath(oldPath)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/88250/lute/ast"
|
||||||
"github.com/emersion/go-vcard"
|
"github.com/emersion/go-vcard"
|
||||||
"github.com/emersion/go-webdav/carddav"
|
"github.com/emersion/go-webdav/carddav"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
|
@ -640,7 +641,7 @@ func (b *AddressBook) load() error {
|
||||||
addressesWaitGroup.Add(1)
|
addressesWaitGroup.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer addressesWaitGroup.Done()
|
defer addressesWaitGroup.Done()
|
||||||
filename_ := util.AssetName(filename)
|
filename_ := util.AssetName(filename, ast.NewNodeID())
|
||||||
address := &AddressObject{
|
address := &AddressObject{
|
||||||
FilePath: path.Join(b.DirectoryPath, filename_),
|
FilePath: path.Join(b.DirectoryPath, filename_),
|
||||||
BookPath: b.MetaData.Path,
|
BookPath: b.MetaData.Path,
|
||||||
|
|
|
||||||
|
|
@ -981,7 +981,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
||||||
if "" == existName {
|
if "" == existName {
|
||||||
name = filepath.Base(absolutePath)
|
name = filepath.Base(absolutePath)
|
||||||
name = util.FilterUploadFileName(name)
|
name = util.FilterUploadFileName(name)
|
||||||
name = util.AssetName(name)
|
name = util.AssetName(name, ast.NewNodeID())
|
||||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||||
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
||||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
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 {
|
if "" == existName {
|
||||||
name = filepath.Base(absolutePath)
|
name = filepath.Base(absolutePath)
|
||||||
name = util.FilterUploadFileName(name)
|
name = util.FilterUploadFileName(name)
|
||||||
name = util.AssetName(name)
|
name = util.AssetName(name, ast.NewNodeID())
|
||||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||||
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
||||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
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 = alt.TokensStr() + ext
|
||||||
}
|
}
|
||||||
name = util.FilterUploadFileName(name)
|
name = util.FilterUploadFileName(name)
|
||||||
name = util.AssetName(name)
|
name = util.AssetName(name, ast.NewNodeID())
|
||||||
|
|
||||||
tmp := filepath.Join(base64TmpDir, name)
|
tmp := filepath.Join(base64TmpDir, name)
|
||||||
tmpFile, openErr := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE, 0644)
|
tmpFile, openErr := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/88250/lute/ast"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
|
@ -93,7 +94,7 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa
|
||||||
// 已经存在同样数据的资源文件的话不重复保存
|
// 已经存在同样数据的资源文件的话不重复保存
|
||||||
succMap[baseName] = existAsset.Path
|
succMap[baseName] = existAsset.Path
|
||||||
} else {
|
} else {
|
||||||
fName = util.AssetName(fName)
|
fName = util.AssetName(fName, ast.NewNodeID())
|
||||||
writePath := filepath.Join(assetsDirPath, fName)
|
writePath := filepath.Join(assetsDirPath, fName)
|
||||||
if _, err = f.Seek(0, io.SeekStart); err != nil {
|
if _, err = f.Seek(0, io.SeekStart); err != nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
@ -163,6 +164,10 @@ func Upload(c *gin.Context) {
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
baseName := file.Filename
|
baseName := file.Filename
|
||||||
|
_, lastID := util.LastID(baseName)
|
||||||
|
if !ast.IsNodeIDPattern(lastID) {
|
||||||
|
lastID = ""
|
||||||
|
}
|
||||||
|
|
||||||
needUnzip2Dir := false
|
needUnzip2Dir := false
|
||||||
if gulu.OS.IsDarwin() {
|
if gulu.OS.IsDarwin() {
|
||||||
|
|
@ -198,7 +203,16 @@ func Upload(c *gin.Context) {
|
||||||
} else {
|
} else {
|
||||||
if skipIfDuplicated {
|
if skipIfDuplicated {
|
||||||
// 复制 PDF 矩形注解时不再重复插入图片 No longer upload image repeatedly when copying PDF rectangle annotation https://github.com/siyuan-note/siyuan/issues/10666
|
// 复制 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 {
|
if nil != globErr {
|
||||||
logging.LogErrorf("glob failed: %s", globErr)
|
logging.LogErrorf("glob failed: %s", globErr)
|
||||||
} else {
|
} 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)
|
writePath := filepath.Join(assetsDirPath, fName)
|
||||||
tmpDir := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
tmpDir := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
||||||
if needUnzip2Dir {
|
if needUnzip2Dir {
|
||||||
|
|
@ -248,7 +265,7 @@ func Upload(c *gin.Context) {
|
||||||
fName = strings.TrimSuffix(fName, ext)
|
fName = strings.TrimSuffix(fName, ext)
|
||||||
ext = strings.ToLower(ext)
|
ext = strings.ToLower(ext)
|
||||||
fName += ext
|
fName += ext
|
||||||
fName = util.AssetName(fName)
|
fName = util.AssetName(fName, ast.NewNodeID())
|
||||||
tmpDir2 := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
tmpDir2 := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
||||||
if err = gulu.Zip.Unzip(writePath, tmpDir2); err != nil {
|
if err = gulu.Zip.Unzip(writePath, tmpDir2); err != nil {
|
||||||
errFiles = append(errFiles, fName)
|
errFiles = append(errFiles, fName)
|
||||||
|
|
|
||||||
|
|
@ -172,12 +172,12 @@ func Ext(name string) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssetName(name string) string {
|
func AssetName(name, newID string) string {
|
||||||
_, id := LastID(name)
|
_, id := LastID(name)
|
||||||
ext := Ext(name)
|
ext := Ext(name)
|
||||||
name = name[0 : len(name)-len(ext)]
|
name = name[0 : len(name)-len(ext)]
|
||||||
if !ast.IsNodeIDPattern(id) {
|
if !ast.IsNodeIDPattern(id) {
|
||||||
id = ast.NewNodeID()
|
id = newID
|
||||||
name = name + "-" + id + ext
|
name = name + "-" + id + ext
|
||||||
} else {
|
} else {
|
||||||
if !ast.IsNodeIDPattern(name) {
|
if !ast.IsNodeIDPattern(name) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue