mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
🎨 Upload asset files to cloud supports focus use https://github.com/siyuan-note/siyuan/issues/15462
This commit is contained in:
parent
0d3a2479cb
commit
3fda003401
4 changed files with 35 additions and 27 deletions
|
|
@ -148,7 +148,7 @@ func DocAssets(rootID string) (ret []string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
ret = assetsLinkDestsInTree(tree)
|
||||
ret = getAssetsLinkDests(tree.Root)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -469,19 +469,32 @@ func GetAssetAbsPath(relativePath string) (ret string, err error) {
|
|||
return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
|
||||
}
|
||||
|
||||
func UploadAssets2Cloud(rootID string) (count int, err error) {
|
||||
func UploadAssets2Cloud(id string) (count int, err error) {
|
||||
if !IsSubscriber() {
|
||||
return
|
||||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(rootID)
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
assets := assetsLinkDestsInTree(tree)
|
||||
embedAssets := assetsLinkDestsInQueryEmbedNodes(tree)
|
||||
assets = append(assets, embedAssets...)
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
if nil == node {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
|
||||
nodes := []*ast.Node{node}
|
||||
if ast.NodeHeading == node.Type {
|
||||
nodes = append(nodes, treenode.HeadingChildren(node)...)
|
||||
}
|
||||
|
||||
var assets []string
|
||||
for _, n := range nodes {
|
||||
assets = append(assets, getAssetsLinkDests(n)...)
|
||||
assets = append(assets, getQueryEmbedNodesAssetsLinkDests(n)...)
|
||||
}
|
||||
assets = gulu.Str.RemoveDuplicatedElem(assets)
|
||||
count, err = uploadAssets2Cloud(assets, bizTypeUploadAssets)
|
||||
if err != nil {
|
||||
|
|
@ -864,7 +877,7 @@ func UnusedAssets() (ret []string) {
|
|||
trees = append(trees, tree)
|
||||
}
|
||||
for _, tree := range trees {
|
||||
for _, d := range assetsLinkDestsInTree(tree) {
|
||||
for _, d := range getAssetsLinkDests(tree.Root) {
|
||||
dests[d] = true
|
||||
}
|
||||
|
||||
|
|
@ -1027,7 +1040,7 @@ func MissingAssets() (ret []string) {
|
|||
trees = append(trees, tree)
|
||||
}
|
||||
for _, tree := range trees {
|
||||
for _, d := range assetsLinkDestsInTree(tree) {
|
||||
for _, d := range getAssetsLinkDests(tree.Root) {
|
||||
dests[d] = true
|
||||
}
|
||||
|
||||
|
|
@ -1108,11 +1121,11 @@ func emojisInTree(tree *parse.Tree) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) {
|
||||
func getQueryEmbedNodesAssetsLinkDests(node *ast.Node) (ret []string) {
|
||||
// The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042
|
||||
|
||||
ret = []string{}
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || ast.NodeBlockQueryEmbedScript != n.Type {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
|
@ -1131,7 +1144,7 @@ func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) {
|
|||
continue
|
||||
}
|
||||
|
||||
ret = append(ret, assetsLinkDestsInNode(embedNode)...)
|
||||
ret = append(ret, getAssetsLinkDests(embedNode)...)
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
|
@ -1139,12 +1152,7 @@ func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) {
|
||||
ret = assetsLinkDestsInNode(tree.Root)
|
||||
return
|
||||
}
|
||||
|
||||
func assetsLinkDestsInNode(node *ast.Node) (ret []string) {
|
||||
func getAssetsLinkDests(node *ast.Node) (ret []string) {
|
||||
ret = []string{}
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if n.IsBlock() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue