mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
22246b561d
3 changed files with 101 additions and 19 deletions
|
@ -38,7 +38,6 @@ import (
|
|||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
@ -101,11 +100,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
}
|
||||
}
|
||||
|
||||
browserClient := req.C().
|
||||
SetUserAgent(util.UserAgent).
|
||||
SetTimeout(30 * time.Second).
|
||||
EnableInsecureSkipVerify().
|
||||
SetProxy(httpclient.ProxyFromEnvironment)
|
||||
browserClient := util.NewCustomReqClient() // 自定义了 TLS 指纹,增加下载成功率
|
||||
|
||||
forbiddenCount := 0
|
||||
destNodes := getRemoteAssetsLinkDestsInTree(tree, onlyImg)
|
||||
|
|
|
@ -476,7 +476,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int, containChild
|
|||
var paragraphParentIDs []string
|
||||
for _, link := range links {
|
||||
for _, ref := range link.Refs {
|
||||
if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
|
||||
if "NodeParagraph" == ref.Type {
|
||||
paragraphParentIDs = append(paragraphParentIDs, ref.ParentID)
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int, containChild
|
|||
}
|
||||
for _, link := range links {
|
||||
for _, ref := range link.Refs {
|
||||
if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
|
||||
if "NodeParagraph" == ref.Type {
|
||||
if processedParagraphs.Contains(ref.ParentID) {
|
||||
continue
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
|
|||
var paragraphParentIDs []string
|
||||
for _, link := range links {
|
||||
for _, ref := range link.Refs {
|
||||
if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
|
||||
if "NodeParagraph" == ref.Type {
|
||||
parentRefParagraphs[ref.ParentID] = ref
|
||||
paragraphParentIDs = append(paragraphParentIDs, ref.ParentID)
|
||||
}
|
||||
|
@ -615,15 +615,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
|
|||
continue
|
||||
}
|
||||
|
||||
text := c.Text()
|
||||
if strings.HasPrefix(text, "#") {
|
||||
tmp := strings.ReplaceAll(text, "#", "")
|
||||
if " " == tmp { // 如果是标题标记符则跳过
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if "" != strings.TrimSpace(text) {
|
||||
if "" != strings.TrimSpace(c.Text()) {
|
||||
paragraphUseParentLi = false
|
||||
break
|
||||
}
|
||||
|
@ -648,7 +640,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
|
|||
}
|
||||
for _, link := range links {
|
||||
for _, ref := range link.Refs {
|
||||
if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
|
||||
if "NodeParagraph" == ref.Type {
|
||||
if processedParagraphs.Contains(ref.ParentID) {
|
||||
continue
|
||||
}
|
||||
|
@ -664,6 +656,38 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
|
|||
ret = append(ret, ref)
|
||||
}
|
||||
}
|
||||
|
||||
if 0 < len(keywords) {
|
||||
// 过滤场景处理标题下方块 Improve backlink filtering below the heading https://github.com/siyuan-note/siyuan/issues/14929
|
||||
headingRefChildren := map[string]*Block{}
|
||||
var headingIDs []string
|
||||
for _, link := range links {
|
||||
for _, ref := range link.Refs {
|
||||
if "NodeHeading" == ref.Type {
|
||||
headingRefChildren[ref.ID] = ref
|
||||
headingIDs = append(headingIDs, ref.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
var headingChildren []*Block
|
||||
for _, headingID := range headingIDs {
|
||||
sqlChildren := sql.GetChildBlocks(headingID, "", -1)
|
||||
children := fromSQLBlocks(&sqlChildren, "", 12)
|
||||
headingChildren = append(headingChildren, children...)
|
||||
}
|
||||
for _, child := range headingChildren {
|
||||
if nil == child {
|
||||
continue
|
||||
}
|
||||
|
||||
if matchBacklinkKeyword(child, keywords) {
|
||||
heading := headingRefChildren[child.ParentID]
|
||||
if nil != heading {
|
||||
ret = append(ret, heading)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
63
kernel/util/tls.go
Normal file
63
kernel/util/tls.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
// SiYuan - Refactor your thinking
|
||||
// Copyright (c) 2020-present, b3log.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
)
|
||||
|
||||
// NewCustomReqClient 创建自定义 req 客户端
|
||||
func NewCustomReqClient() *req.Client {
|
||||
client := req.C().
|
||||
SetTLSClientConfig(createCustomTLSConfig()).
|
||||
SetUserAgent(UserAgent).
|
||||
SetTimeout(30 * time.Second).
|
||||
SetProxy(httpclient.ProxyFromEnvironment)
|
||||
return client
|
||||
}
|
||||
|
||||
// createCustomTLSConfig 创建自定义 TLS 配置
|
||||
func createCustomTLSConfig() *tls.Config {
|
||||
return &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
MinVersion: tls.VersionTLS12,
|
||||
MaxVersion: tls.VersionTLS13,
|
||||
|
||||
// 模拟 Chrome 的密码套件顺序
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_AES_128_GCM_SHA256,
|
||||
tls.TLS_AES_256_GCM_SHA384,
|
||||
tls.TLS_CHACHA20_POLY1305_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
||||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
||||
},
|
||||
|
||||
CurvePreferences: []tls.CurveID{
|
||||
tls.X25519,
|
||||
tls.CurveP256,
|
||||
tls.CurveP384,
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue