Prechádzať zdrojové kódy

:art: The images in the databases are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/11948

Daniel 11 mesiacov pred
rodič
commit
c9462f691d
2 zmenil súbory, kde vykonal 45 pridanie a 0 odobranie
  1. 43 0
      kernel/model/assets.go
  2. 2 0
      kernel/model/export.go

+ 43 - 0
kernel/model/assets.go

@@ -43,6 +43,7 @@ import (
 	"github.com/siyuan-note/filelock"
 	"github.com/siyuan-note/httpclient"
 	"github.com/siyuan-note/logging"
+	"github.com/siyuan-note/siyuan/kernel/av"
 	"github.com/siyuan-note/siyuan/kernel/cache"
 	"github.com/siyuan-note/siyuan/kernel/filesys"
 	"github.com/siyuan-note/siyuan/kernel/search"
@@ -555,6 +556,8 @@ func UploadAssets2Cloud(rootID string) (count int, err error) {
 	assets := assetsLinkDestsInTree(tree)
 	embedAssets := assetsLinkDestsInQueryEmbedNodes(tree)
 	assets = append(assets, embedAssets...)
+	avAssets := assetsLinkDestsInAttributeViewNodes(tree)
+	assets = append(assets, avAssets...)
 	assets = gulu.Str.RemoveDuplicatedElem(assets)
 	count, err = uploadAssets2Cloud(assets, bizTypeUploadAssets)
 	if nil != err {
@@ -1097,6 +1100,46 @@ func emojisInTree(tree *parse.Tree) (ret []string) {
 	return
 }
 
+func assetsLinkDestsInAttributeViewNodes(tree *parse.Tree) (ret []string) {
+	// The images in the databases are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/11948
+
+	ret = []string{}
+	ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
+		if !entering || ast.NodeAttributeView != n.Type {
+			return ast.WalkContinue
+		}
+
+		attrView, _ := av.ParseAttributeView(n.AttributeViewID)
+		if nil == attrView {
+			return ast.WalkContinue
+		}
+
+		for _, keyValues := range attrView.KeyValues {
+			if av.KeyTypeMAsset != keyValues.Key.Type {
+				continue
+			}
+
+			for _, value := range keyValues.Values {
+				if 1 > len(value.MAsset) {
+					continue
+				}
+
+				for _, asset := range value.MAsset {
+					dest := asset.Content
+					if !treenode.IsRelativePath([]byte(dest)) {
+						continue
+					}
+
+					ret = append(ret, strings.TrimSpace(dest))
+				}
+			}
+		}
+		return ast.WalkContinue
+	})
+	ret = gulu.Str.RemoveDuplicatedElem(ret)
+	return
+}
+
 func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) {
 	// The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042
 

+ 2 - 0
kernel/model/export.go

@@ -217,6 +217,8 @@ func Export2Liandi(id string) (err error) {
 	assets := assetsLinkDestsInTree(tree)
 	embedAssets := assetsLinkDestsInQueryEmbedNodes(tree)
 	assets = append(assets, embedAssets...)
+	avAssets := assetsLinkDestsInAttributeViewNodes(tree)
+	assets = append(assets, avAssets...)
 	assets = gulu.Str.RemoveDuplicatedElem(assets)
 	_, err = uploadAssets2Cloud(assets, bizTypeExport2Liandi)
 	if nil != err {