Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-02-17 12:27:41 +08:00
commit e8de30d2a2
4 changed files with 41 additions and 49 deletions

File diff suppressed because one or more lines are too long

View file

@ -10,7 +10,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec
github.com/88250/lute v1.7.7-0.20250213081327-5ddd3fb96d0e
github.com/88250/lute v1.7.7-0.20250217041919-58a466e777a4
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
github.com/ConradIrwin/font v0.2.1

View file

@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec h1:YsUSpByWJP+x8C+IT+C3QlFvU7ZQ6+E95SFd9+zy6QU=
github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec/go.mod h1:c8uVw25vW2W4dhJ/j4iYsX5H1hc19spim266jO5x2hU=
github.com/88250/lute v1.7.7-0.20250213081327-5ddd3fb96d0e h1:oEAhoLd2eU9Qsqjos34rjccC3d93pB4ULEYqaDZnmBw=
github.com/88250/lute v1.7.7-0.20250213081327-5ddd3fb96d0e/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
github.com/88250/lute v1.7.7-0.20250217041919-58a466e777a4 h1:6+lg4V6VIZpGUPPIRlDoVeVgfiKo0KW7CUE0318iFiE=
github.com/88250/lute v1.7.7-0.20250217041919-58a466e777a4/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01 h1:AcFe63RXjIh1XtX/dc4Es3U8bYKjlEkvavHd1nFBOHM=
github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -721,7 +721,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
hPathsIDs := map[string]string{}
idPaths := map[string]string{}
moveIDs := map[string]string{}
assetsDone := map[string]string{}
if gulu.File.IsDir(localPath) { // 导入文件夹
// 收集所有资源文件
assets := map[string]string{}
@ -744,7 +744,6 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
})
targetPaths := map[string]string{}
assetsDone := map[string]string{}
count := 0
// md 转换 sy
filelock.Walk(localPath, func(currentPath string, d fs.DirEntry, err error) error {
@ -866,15 +865,11 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
return ast.WalkContinue
}
absolutePath := filepath.Join(currentDir, dest)
newAbsolutePath := absolutePath
decodedDest := string(html.DecodeDestination([]byte(dest)))
if decodedDest != dest {
dest = decodedDest
newAbsolutePath = filepath.Join(currentDir, dest)
gulu.File.Copy(absolutePath, newAbsolutePath)
}
absolutePath := filepath.Join(currentDir, dest)
if ast.NodeLinkDest == n.Type {
n.Tokens = []byte(dest)
@ -889,36 +884,29 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
return ast.WalkContinue
}
if !gulu.File.IsExist(newAbsolutePath) {
if !gulu.File.IsExist(absolutePath) {
return ast.WalkContinue
}
absDest := filepath.Join(currentDir, dest)
fullPath, exist := assets[absDest]
if !exist {
absDest = filepath.Join(currentDir, string(html.DecodeDestination([]byte(dest))))
existName := assetsDone[absolutePath]
var name string
if "" == existName {
name = filepath.Base(absolutePath)
name = util.FilterUploadFileName(name)
name = util.AssetName(name)
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)
return ast.WalkContinue
}
assetsDone[absolutePath] = name
} else {
name = existName
}
fullPath, exist = assets[absDest]
if exist {
existName := assetsDone[absDest]
var name string
if "" == existName {
name = filepath.Base(fullPath)
name = util.AssetName(name)
assetTargetPath := filepath.Join(assetDirPath, name)
if err = filelock.Copy(fullPath, assetTargetPath); err != nil {
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", fullPath, assetTargetPath, err)
return ast.WalkContinue
}
assetsDone[absDest] = name
} else {
name = existName
}
if ast.NodeLinkDest == n.Type {
n.Tokens = []byte("assets/" + name)
} else {
n.TextMarkAHref = "assets/" + name
}
if ast.NodeLinkDest == n.Type {
n.Tokens = []byte("assets/" + name)
} else {
n.TextMarkAHref = "assets/" + name
}
return ast.WalkContinue
})
@ -1000,15 +988,11 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
return ast.WalkContinue
}
absolutePath := filepath.Join(filepath.Dir(localPath), dest)
newAbsolutePath := absolutePath
decodedDest := string(html.DecodeDestination([]byte(dest)))
if decodedDest != dest {
dest = decodedDest
newAbsolutePath = filepath.Join(filepath.Dir(localPath), dest)
gulu.File.Copy(absolutePath, newAbsolutePath)
}
absolutePath := filepath.Join(filepath.Dir(localPath), dest)
if ast.NodeLinkDest == n.Type {
n.Tokens = []byte(dest)
@ -1023,16 +1007,24 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
return ast.WalkContinue
}
if !gulu.File.IsExist(newAbsolutePath) {
if !gulu.File.IsExist(absolutePath) {
return ast.WalkContinue
}
name := filepath.Base(newAbsolutePath)
name = util.AssetName(name)
assetTargetPath := filepath.Join(assetDirPath, name)
if err = filelock.Copy(newAbsolutePath, assetTargetPath); err != nil {
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", newAbsolutePath, assetTargetPath, err)
return ast.WalkContinue
existName := assetsDone[absolutePath]
var name string
if "" == existName {
name = filepath.Base(absolutePath)
name = util.FilterUploadFileName(name)
name = util.AssetName(name)
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)
return ast.WalkContinue
}
assetsDone[absolutePath] = name
} else {
name = existName
}
if ast.NodeLinkDest == n.Type {
n.Tokens = []byte("assets/" + name)