Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-11-22 17:14:40 +08:00
commit 7cbf14a42f
6 changed files with 62 additions and 19 deletions

View file

@ -44,13 +44,13 @@ require (
github.com/mssola/useragent v1.0.0
github.com/olahol/melody v1.1.4
github.com/open-spaced-repetition/go-fsrs v1.0.0
github.com/panjf2000/ants/v2 v2.8.2
github.com/panjf2000/ants/v2 v2.9.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/radovskyb/watcher v1.0.7
github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0
github.com/sashabaranov/go-openai v1.17.8
github.com/shirou/gopsutil/v3 v3.23.10
github.com/siyuan-note/dejavu v0.0.0-20231120143143-e407eb1309c0
github.com/siyuan-note/dejavu v0.0.0-20231122082037-f5d92ba84aff
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20230804030110-cf250f838c80
github.com/siyuan-note/filelock v0.0.0-20231107122348-6ed75b0b525a
@ -78,7 +78,7 @@ require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
github.com/aws/aws-sdk-go v1.48.0 // indirect
github.com/aws/aws-sdk-go v1.48.2 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect

View file

@ -49,8 +49,8 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
github.com/aws/aws-sdk-go v1.48.0 h1:1SeJ8agckRDQvnSCt1dGZYAwUaoD2Ixj6IaXB4LCv8Q=
github.com/aws/aws-sdk-go v1.48.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.48.2 h1:Lf7+Y4WmHB0AQLRQZA46diSwDa+LWbwY6IGaYoCVtTc=
github.com/aws/aws-sdk-go v1.48.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
@ -290,8 +290,8 @@ github.com/otiai10/gosseract/v2 v2.4.1 h1:G8AyBpXEeSlcq8TI85LH/pM5SXk8Djy2GEXisg
github.com/otiai10/gosseract/v2 v2.4.1/go.mod h1:1gNWP4Hgr2o7yqWfs6r5bZxAatjOIdqWxJLWsTsembk=
github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/panjf2000/ants/v2 v2.8.2 h1:D1wfANttg8uXhC9149gRt1PDQ+dLVFjNXkCEycMcvQQ=
github.com/panjf2000/ants/v2 v2.8.2/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/panjf2000/ants/v2 v2.9.0 h1:SztCLkVxBRigbg+vt0S5QvF5vxAbxbKt09/YfAJ0tEo=
github.com/panjf2000/ants/v2 v2.9.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
@ -356,8 +356,8 @@ github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR
github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+tqMccdGMwuEU+hjux/zL6xSmf5S9ITaA=
github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw=
github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8=
github.com/siyuan-note/dejavu v0.0.0-20231120143143-e407eb1309c0 h1:MvzFOpZiV94vbqSSdjeE3bK7pfJ4oCPzCQpdH22L42U=
github.com/siyuan-note/dejavu v0.0.0-20231120143143-e407eb1309c0/go.mod h1:qhORyWwn+RS2TMw7aga1Nkti6E0N9CjEVVw3wIgaeLQ=
github.com/siyuan-note/dejavu v0.0.0-20231122082037-f5d92ba84aff h1:WpIqLLaaDskar4ZMjsevYXmIML+lbbC4PXjralFC5uI=
github.com/siyuan-note/dejavu v0.0.0-20231122082037-f5d92ba84aff/go.mod h1:qhORyWwn+RS2TMw7aga1Nkti6E0N9CjEVVw3wIgaeLQ=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20230804030110-cf250f838c80 h1:XghjHKJd+SiL0DkGYFVC+UGUDFtnR4v9gkAbPeh9Eq8=

View file

@ -45,7 +45,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
waitForSyncingStorages()
ret = []*BlockAttributeViewKeys{}
attrs := GetBlockAttrs(blockID)
attrs := GetBlockAttrsWithoutWaitWriting(blockID)
avs := attrs[av.NodeAttrNameAvs]
if "" == avs {
return
@ -102,7 +102,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
}
case av.KeyTypeUpdated:
ial := GetBlockAttrs(blockID)
ial := GetBlockAttrsWithoutWaitWriting(blockID)
updatedStr := ial["updated"]
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
if nil == parseErr {
@ -122,7 +122,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
ial := map[string]string{}
block := getRowBlockValue(keyValues)
if !block.IsDetached {
ial = GetBlockAttrs(blockID)
ial = GetBlockAttrsWithoutWaitWriting(blockID)
}
kv.Values[0].Template.Content = renderTemplateCol(ial, kv.Key.Template, keyValues)
}
@ -464,7 +464,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
ial := map[string]string{}
block := row.GetBlockValue()
if !block.IsDetached {
ial = GetBlockAttrs(row.ID)
ial = GetBlockAttrsWithoutWaitWriting(row.ID)
}
content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)
cell.Value.Template.Content = content
@ -481,7 +481,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
ial := map[string]string{}
block := row.GetBlockValue()
if !block.IsDetached {
ial = GetBlockAttrs(row.ID)
ial = GetBlockAttrsWithoutWaitWriting(row.ID)
}
updatedStr := ial["updated"]
if "" == updatedStr {

View file

@ -268,3 +268,28 @@ func GetBlockAttrs(id string) (ret map[string]string) {
cache.PutBlockIAL(id, ret)
return
}
func GetBlockAttrsWithoutWaitWriting(id string) (ret map[string]string) {
ret = map[string]string{}
if cached := cache.GetBlockIAL(id); nil != cached {
ret = cached
return
}
tree, err := loadTreeByBlockID(id)
if nil != err {
return
}
node := treenode.GetNodeInTree(tree, id)
if nil == node {
logging.LogWarnf("block [%s] not found", id)
return
}
for _, kv := range node.KramdownIAL {
ret[kv[0]] = html.UnescapeAttrVal(kv[1])
}
cache.PutBlockIAL(id, ret)
return
}

View file

@ -162,6 +162,12 @@ func CheckAuth(c *gin.Context) {
// 未设置访问授权码
if "" == Conf.AccessAuthCode {
// Skip the empty access authorization code check https://github.com/siyuan-note/siyuan/issues/9709
if util.SiyuanAccessAuthCodeBypass {
c.Next()
return
}
// Authenticate requests with the Origin header other than 127.0.0.1 https://github.com/siyuan-note/siyuan/issues/9180
clientIP := c.ClientIP()
host := c.GetHeader("Host")

View file

@ -46,6 +46,19 @@ const (
IsInsider = false
)
var (
RunInContainer = false // 是否运行在容器中
SiyuanAccessAuthCodeBypass = false // 是否跳过空访问授权码检查
)
func initEnvVars() {
RunInContainer = isRunningInDockerContainer()
var err error
if SiyuanAccessAuthCodeBypass, err = strconv.ParseBool(os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")); nil != err {
SiyuanAccessAuthCodeBypass = false
}
}
var (
bootProgress float64 // 启动进度,从 0 到 100
bootDetails string // 启动细节描述
@ -53,6 +66,7 @@ var (
)
func Boot() {
initEnvVars()
IncBootProgress(3, "Booting kernel...")
rand.Seed(time.Now().UTC().UnixNano())
initMime()
@ -79,15 +93,13 @@ func Boot() {
ReadOnly, _ = strconv.ParseBool(*readOnly)
AccessAuthCode = *accessAuthCode
Container = ContainerStd
if isRunningInDockerContainer() {
if RunInContainer {
Container = ContainerDocker
if "" == AccessAuthCode {
interruptBoot := true
// Set the env `SIYUAN_ACCESS_AUTH_CODE_BYPASS=true` to skip checking access auth code when deploying Docker https://github.com/siyuan-note/siyuan/issues/9709
byPassEnv := os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")
bypass, parseErr := strconv.ParseBool(byPassEnv)
if nil == parseErr && bypass {
// Set the env `SIYUAN_ACCESS_AUTH_CODE_BYPASS=true` to skip checking empty access auth code https://github.com/siyuan-note/siyuan/issues/9709
if SiyuanAccessAuthCodeBypass {
interruptBoot = false
fmt.Println("bypass access auth code check since the env [SIYUAN_ACCESS_AUTH_CODE_BYPASS] is set to [true]")
}