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

This commit is contained in:
Vanessa 2026-01-12 12:22:12 +08:00
commit f17c094e7d
4 changed files with 39 additions and 37 deletions

View file

@ -410,11 +410,12 @@ type Viewable interface {
func NewAttributeView(id string) (ret *AttributeView) {
view, blockKey, selectKey := NewTableViewWithBlockKey(ast.NewNodeID())
ret = &AttributeView{
Spec: CurrentSpec,
ID: id,
KeyValues: []*KeyValues{{Key: blockKey}, {Key: selectKey}},
ViewID: view.ID,
Views: []*View{view},
Spec: CurrentSpec,
ID: id,
KeyValues: []*KeyValues{{Key: blockKey}, {Key: selectKey}},
ViewID: view.ID,
Views: []*View{view},
RenderedViewables: map[string]Viewable{},
}
return
}

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

View file

@ -502,7 +502,7 @@ func RenderRepoSnapshotAttributeView(indexID, avID string) (viewable av.Viewable
return
}
attrView = &av.AttributeView{RenderedViewables: map[string]av.Viewable{}}
attrView = av.NewAttributeView(avID)
if err = gulu.JSON.UnmarshalJSON(data, attrView); err != nil {
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
return
@ -547,7 +547,7 @@ func RenderHistoryAttributeView(blockID, avID, viewID, query string, page, pageS
return
}
attrView = &av.AttributeView{RenderedViewables: map[string]av.Viewable{}}
attrView = av.NewAttributeView(avID)
if err = gulu.JSON.UnmarshalJSON(data, attrView); err != nil {
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
return

View file

@ -95,6 +95,8 @@ func ExportCodeBlock(blockID string) (filePath string, err error) {
return
}
code.Tokens = bytes.ReplaceAll(code.Tokens, []byte(editor.Zwj+"```"), []byte("```"))
writePath := filepath.Join(exportFolder, name)
err = filelock.WriteFile(writePath, code.Tokens)
if nil != err {
@ -716,7 +718,7 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
content = strings.ReplaceAll(content, " \n", "<br>\n")
tmpDocxPath := filepath.Join(tmpDir, name+".docx")
args := []string{ // pandoc -f html --resource-path=请从这里开始 请从这里开始\index.html -o test.docx
args := []string{
"-f", "html+tex_math_dollars",
"--resource-path", tmpDir,
"-o", tmpDocxPath,
@ -796,17 +798,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
}
if docx {
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if ast.NodeLinkDest == n.Type {
if bytes.HasPrefix(n.Tokens, []byte("file://")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"), []byte("/"))
if !bytes.HasPrefix(n.Tokens, []byte("file:///")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("file://"), []byte("file:///"))
}
}
}
return ast.WalkContinue
})
netAssets2LocalAssets0(tree, true, "", filepath.Join(savePath, "assets"), false)
}
assets := getAssetsLinkDests(tree.Root, docx)
@ -814,7 +806,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
if !util.IsAssetLinkDest([]byte(asset), docx) {
continue
}
if strings.Contains(asset, "?") {
asset = asset[:strings.LastIndex(asset, "?")]
}