🎨 Improve handling of assets when exporting to Word .docx format https://github.com/siyuan-note/siyuan/issues/15253

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-12 11:56:16 +08:00
parent 2e9ef1e028
commit 4bc9d9496e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 29 additions and 30 deletions

View file

@ -187,10 +187,6 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
return
}
var files int
var size int64
msgId := gulu.Rand.String(7)
docDirLocalPath := filepath.Join(util.DataDir, tree.Box, path.Dir(tree.Path))
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, tree.Box), docDirLocalPath)
if !gulu.File.IsExist(assetsDirPath) {
@ -199,6 +195,15 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
}
}
err = netAssets2LocalAssets0(tree, onlyImg, originalURL, assetsDirPath, true)
return
}
func netAssets2LocalAssets0(tree *parse.Tree, onlyImg bool, originalURL string, assetsDirPath string, needWriteTree bool) (err error) {
var files int
var size int64
msgId := gulu.Rand.String(7)
browserClient := util.NewCustomReqClient() // 自定义了 TLS 指纹,增加下载成功率
forbiddenCount := 0
@ -284,6 +289,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
if 64 < len(displayU) {
displayU = displayU[:64] + "..."
}
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(119), displayU), 15000)
request := browserClient.R()
request.SetRetryCount(1).SetRetryFixedInterval(3 * time.Second)
@ -365,21 +371,24 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
}
util.PushClearMsg(msgId)
if 0 < files {
msgId = util.PushMsg(Conf.Language(113), 7000)
if err = writeTreeUpsertQueue(tree); err != nil {
return
}
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(120), files, humanize.BytesCustomCeil(uint64(size), 2)), 5000)
if 0 < forbiddenCount {
util.PushErrMsg(fmt.Sprintf(Conf.Language(255), forbiddenCount), 5000)
}
} else {
if 0 < forbiddenCount {
util.PushErrMsg(fmt.Sprintf(Conf.Language(255), forbiddenCount), 5000)
if needWriteTree {
if 0 < files {
msgId = util.PushMsg(Conf.Language(113), 7000)
if err = writeTreeUpsertQueue(tree); err != nil {
return
}
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(120), files, humanize.BytesCustomCeil(uint64(size), 2)), 5000)
if 0 < forbiddenCount {
util.PushErrMsg(fmt.Sprintf(Conf.Language(255), forbiddenCount), 5000)
}
} else {
util.PushMsg(Conf.Language(121), 3000)
if 0 < forbiddenCount {
util.PushErrMsg(fmt.Sprintf(Conf.Language(255), forbiddenCount), 5000)
} else {
util.PushMsg(Conf.Language(121), 3000)
}
}
}
return