mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +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
|
|
@ -363,7 +363,7 @@ ${padHTML}
|
|||
click() {
|
||||
if (!needSubscribe()) {
|
||||
confirmDialog("📦 " + window.siyuan.languages.uploadAssets2CDN, window.siyuan.languages.uploadAssets2CDNConfirmTip, () => {
|
||||
fetchPost("/api/asset/uploadCloud", {id: protyle.block.parentID});
|
||||
fetchPost("/api/asset/uploadCloud", {id: protyle.block.id});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -386,8 +386,8 @@ func uploadCloud(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
rootID := arg["id"].(string)
|
||||
count, err := model.UploadAssets2Cloud(rootID)
|
||||
id := arg["id"].(string)
|
||||
count, err := model.UploadAssets2Cloud(id)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ func Export2Liandi(id string) (err error) {
|
|||
return errors.New(Conf.Language(204))
|
||||
}
|
||||
|
||||
assets := assetsLinkDestsInTree(tree)
|
||||
embedAssets := assetsLinkDestsInQueryEmbedNodes(tree)
|
||||
assets := getAssetsLinkDests(tree.Root)
|
||||
embedAssets := getQueryEmbedNodesAssetsLinkDests(tree.Root)
|
||||
assets = append(assets, embedAssets...)
|
||||
assets = gulu.Str.RemoveDuplicatedElem(assets)
|
||||
_, err = uploadAssets2Cloud(assets, bizTypeExport2Liandi)
|
||||
|
|
@ -716,7 +716,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
return
|
||||
}
|
||||
|
||||
assets := assetsLinkDestsInTree(tree)
|
||||
assets := getAssetsLinkDests(tree.Root)
|
||||
for _, asset := range assets {
|
||||
if strings.HasPrefix(asset, "assets/") {
|
||||
if strings.Contains(asset, "?") {
|
||||
|
|
@ -879,7 +879,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|||
return
|
||||
}
|
||||
|
||||
assets := assetsLinkDestsInTree(tree)
|
||||
assets := getAssetsLinkDests(tree.Root)
|
||||
for _, asset := range assets {
|
||||
if strings.Contains(asset, "?") {
|
||||
asset = asset[:strings.LastIndex(asset, "?")]
|
||||
|
|
@ -1037,7 +1037,7 @@ func ProcessPDF(id, p string, merge, removeAssets, watermark bool) (err error) {
|
|||
}
|
||||
|
||||
var headings []*ast.Node
|
||||
assetDests := assetsLinkDestsInTree(tree)
|
||||
assetDests := getAssetsLinkDests(tree.Root)
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering {
|
||||
return ast.WalkContinue
|
||||
|
|
@ -1741,7 +1741,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
copiedAssets := hashset.New()
|
||||
for _, tree := range trees {
|
||||
var assets []string
|
||||
assets = append(assets, assetsLinkDestsInTree(tree)...)
|
||||
assets = append(assets, getAssetsLinkDests(tree.Root)...)
|
||||
titleImgPath := treenode.GetDocTitleImgPath(tree.Root) // Export .sy.zip doc title image is not exported https://github.com/siyuan-note/siyuan/issues/8748
|
||||
if "" != titleImgPath {
|
||||
if util.IsAssetLinkDest([]byte(titleImgPath)) {
|
||||
|
|
@ -3183,7 +3183,7 @@ func exportPandocConvertZip(baseFolderName string, docPaths, defBlockIDs []strin
|
|||
// 解析导出后的标准 Markdown,汇总 assets
|
||||
tree = parse.Parse("", gulu.Str.ToBytes(md), luteEngine.ParseOptions)
|
||||
var assets []string
|
||||
assets = append(assets, assetsLinkDestsInTree(tree)...)
|
||||
assets = append(assets, getAssetsLinkDests(tree.Root)...)
|
||||
for _, asset := range assets {
|
||||
asset = string(html.DecodeDestination([]byte(asset)))
|
||||
if strings.Contains(asset, "?") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue