mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 09:30:48 +08:00
🎨 Supports converting network assets in the database to local https://github.com/siyuan-note/siyuan/issues/12096
This commit is contained in:
parent
df8d70995c
commit
b4ece87cc0
@ -100,11 +100,12 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||||||
|
|
||||||
destNodes := getRemoteAssetsLinkDestsInTree(tree, onlyImg)
|
destNodes := getRemoteAssetsLinkDestsInTree(tree, onlyImg)
|
||||||
for _, destNode := range destNodes {
|
for _, destNode := range destNodes {
|
||||||
dest := getRemoteAssetsLinkDest(destNode, onlyImg)
|
dests := getRemoteAssetsLinkDests(destNode, onlyImg)
|
||||||
if "" == dest {
|
if 1 > len(dests) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, dest := range dests {
|
||||||
if strings.HasPrefix(strings.ToLower(dest), "file://") { // 处理本地文件链接
|
if strings.HasPrefix(strings.ToLower(dest), "file://") { // 处理本地文件链接
|
||||||
u := dest[7:]
|
u := dest[7:]
|
||||||
unescaped, _ := url.PathUnescape(u)
|
unescaped, _ := url.PathUnescape(u)
|
||||||
@ -157,7 +158,12 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||||||
// u = strings.Replace(u, "/0?", "/640?", 1)
|
// u = strings.Replace(u, "/0?", "/640?", 1)
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(119), u), 15000)
|
|
||||||
|
displayU := u
|
||||||
|
if 64 < len(displayU) {
|
||||||
|
displayU = displayU[:64] + "..."
|
||||||
|
}
|
||||||
|
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(119), displayU), 15000)
|
||||||
request := browserClient.R()
|
request := browserClient.R()
|
||||||
request.SetRetryCount(1).SetRetryFixedInterval(3 * time.Second)
|
request.SetRetryCount(1).SetRetryFixedInterval(3 * time.Second)
|
||||||
if "" != originalURL {
|
if "" != originalURL {
|
||||||
@ -227,6 +233,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if 0 < files {
|
if 0 < files {
|
||||||
util.PushUpdateMsg(msgId, Conf.Language(113), 7000)
|
util.PushUpdateMsg(msgId, Conf.Language(113), 7000)
|
||||||
@ -1051,23 +1058,83 @@ func setAssetsLinkDest(node *ast.Node, oldDest, dest string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRemoteAssetsLinkDest(node *ast.Node, onlyImg bool) (ret string) {
|
func getRemoteAssetsLinkDests(node *ast.Node, onlyImg bool) (ret []string) {
|
||||||
if onlyImg {
|
if onlyImg {
|
||||||
if ast.NodeLinkDest == node.Type && node.ParentIs(ast.NodeImage) {
|
if ast.NodeLinkDest == node.Type {
|
||||||
ret = string(node.Tokens)
|
if node.ParentIs(ast.NodeImage) {
|
||||||
|
if !util.IsAssetLinkDest(node.Tokens) {
|
||||||
|
ret = append(ret, string(node.Tokens))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if ast.NodeAttributeView == node.Type {
|
||||||
|
attrView, _ := av.ParseAttributeView(node.AttributeViewID)
|
||||||
|
if nil == attrView {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
if av.AssetTypeImage != asset.Type {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dest := asset.Content
|
||||||
|
if !util.IsAssetLinkDest([]byte(dest)) {
|
||||||
|
ret = append(ret, strings.TrimSpace(dest))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ast.NodeLinkDest == node.Type {
|
if ast.NodeLinkDest == node.Type {
|
||||||
ret = string(node.Tokens)
|
if !util.IsAssetLinkDest(node.Tokens) {
|
||||||
} else if node.IsTextMarkType("a") {
|
ret = append(ret, string(node.Tokens))
|
||||||
ret = node.TextMarkAHref
|
|
||||||
} else if ast.NodeAudio == node.Type || ast.NodeVideo == node.Type {
|
|
||||||
ret = treenode.GetNodeSrcTokens(node)
|
|
||||||
}
|
}
|
||||||
|
} else if node.IsTextMarkType("a") {
|
||||||
|
if !util.IsAssetLinkDest([]byte(node.TextMarkAHref)) {
|
||||||
|
ret = append(ret, node.TextMarkAHref)
|
||||||
|
}
|
||||||
|
} else if ast.NodeAudio == node.Type || ast.NodeVideo == node.Type {
|
||||||
|
src := treenode.GetNodeSrcTokens(node)
|
||||||
|
if !util.IsAssetLinkDest([]byte(src)) {
|
||||||
|
ret = append(ret, src)
|
||||||
|
}
|
||||||
|
} else if ast.NodeAttributeView == node.Type {
|
||||||
|
attrView, _ := av.ParseAttributeView(node.AttributeViewID)
|
||||||
|
if nil == attrView {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.IsAssetLinkDest([]byte(ret)) {
|
for _, keyValues := range attrView.KeyValues {
|
||||||
ret = ""
|
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 !util.IsAssetLinkDest([]byte(dest)) {
|
||||||
|
ret = append(ret, strings.TrimSpace(dest))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1078,8 +1145,8 @@ func getRemoteAssetsLinkDestsInTree(tree *parse.Tree, onlyImg bool) (nodes []*as
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
dest := getRemoteAssetsLinkDest(n, onlyImg)
|
dests := getRemoteAssetsLinkDests(n, onlyImg)
|
||||||
if "" == dest {
|
if 1 > len(dests) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user