From 6ae523bcd65bdd37337991eac1fa8fb7749636e0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 15:59:57 +0800 Subject: [PATCH 01/10] :memo: Update changelogs --- app/changelogs/v2.12.0/v2.12.0.md | 1 + app/changelogs/v2.12.0/v2.12.0_zh_CHT.md | 1 + app/changelogs/v2.12.0/v2.12.0_zh_CN.md | 1 + 3 files changed, 3 insertions(+) diff --git a/app/changelogs/v2.12.0/v2.12.0.md b/app/changelogs/v2.12.0/v2.12.0.md index 769c78d05..3a77274ea 100644 --- a/app/changelogs/v2.12.0/v2.12.0.md +++ b/app/changelogs/v2.12.0/v2.12.0.md @@ -35,6 +35,7 @@ Below are the detailed changes in this version. * [Search and replace fails in some cases](https://github.com/siyuan-note/siyuan/issues/10016) * [Reference jump is not located in read-only mode](https://github.com/siyuan-note/siyuan/issues/10028) * [Converting PDF annotation ref to text fails after setting the appearance](https://github.com/siyuan-note/siyuan/issues/10029) +* [Pressing the scoring shortcut key immediately after `Alt+F` is invalid](https://github.com/siyuan-note/siyuan/issues/10020) ### Development diff --git a/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md b/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md index 6551351e1..39ba7f3c3 100644 --- a/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md +++ b/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md @@ -35,6 +35,7 @@ * [某些情況下搜尋替換失效](https://github.com/siyuan-note/siyuan/issues/10016) * [唯讀模式下引用跳轉後未定位瀏覽位置](https://github.com/siyuan-note/siyuan/issues/10028) * [無法轉換外觀樣式的 PDF 註解引用為文字](https://github.com/siyuan-note/siyuan/issues/10029) +* [`Alt+F` 後快速按下評分快捷鍵失效](https://github.com/siyuan-note/siyuan/issues/10020) ### 開發者 diff --git a/app/changelogs/v2.12.0/v2.12.0_zh_CN.md b/app/changelogs/v2.12.0/v2.12.0_zh_CN.md index 5f820fb8b..36ed88b0b 100644 --- a/app/changelogs/v2.12.0/v2.12.0_zh_CN.md +++ b/app/changelogs/v2.12.0/v2.12.0_zh_CN.md @@ -35,6 +35,7 @@ * [某些情况下搜索替换失效](https://github.com/siyuan-note/siyuan/issues/10016) * [只读模式下引用跳转后未定位浏览位置](https://github.com/siyuan-note/siyuan/issues/10028) * [无法转换带外观样式的 PDF 注释引用为文本](https://github.com/siyuan-note/siyuan/issues/10029) +* [`Alt+F` 后快速按下评分快捷键失效](https://github.com/siyuan-note/siyuan/issues/10020) ### 开发者 From d9a0d8966857f4a31fa4922316f38f87bc5e0f80 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 16:08:46 +0800 Subject: [PATCH 02/10] :art: Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958 --- kernel/model/attribute_view.go | 28 ++++++++++++++-------------- kernel/treenode/node.go | 10 +++++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 805025b71..e98545782 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -245,18 +245,18 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) { destAv, _ := av.ParseAttributeView(relKey.Relation.AvID) if nil != destAv { for _, bID := range relVal.Relation.BlockIDs { + destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID) + if nil == destKey { + continue + } + destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID) if nil == destVal { - destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID) - if nil == destKey { - continue - } - destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, blockID, destKey.Type) } - if av.KeyTypeNumber == destVal.Type { - destVal.Number.Format = kv.Key.NumberFormat + if av.KeyTypeNumber == destKey.Type { + destVal.Number.Format = destKey.NumberFormat destVal.Number.FormatNumber() } @@ -818,17 +818,17 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a } for _, blockID := range relVal.Relation.BlockIDs { + destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) + if nil == destKey { + continue + } + destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) if nil == destVal { - destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) - if nil == destKey { - continue - } - destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) } - if av.KeyTypeNumber == destVal.Type { - destVal.Number.Format = rollupKey.NumberFormat + if av.KeyTypeNumber == destKey.Type { + destVal.Number.Format = destKey.NumberFormat destVal.Number.FormatNumber() } diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go index 6f335c9f7..d96ec25da 100644 --- a/kernel/treenode/node.go +++ b/kernel/treenode/node.go @@ -775,17 +775,21 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a } for _, blockID := range relVal.Relation.BlockIDs { + destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) + if nil == destKey { + continue + } + destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) if nil == destVal { - destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) if nil == destKey { continue } destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) } - if av.KeyTypeNumber == destVal.Type { - destVal.Number.Format = rollupKey.NumberFormat + if av.KeyTypeNumber == destKey.Type { + destVal.Number.Format = destKey.NumberFormat destVal.Number.FormatNumber() } From 5c8bab48edd3bd75c1f01dbd90374fd8d92fba3e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 16:19:49 +0800 Subject: [PATCH 03/10] :art: Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958 --- kernel/av/value.go | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/kernel/av/value.go b/kernel/av/value.go index 29c3bb966..28e0e3ca1 100644 --- a/kernel/av/value.go +++ b/kernel/av/value.go @@ -531,9 +531,8 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { case CalcOperatorSum: sum := 0.0 for _, v := range r.Contents { - if "" != v.String() { - n, _ := strconv.ParseFloat(v.String(), 64) - sum += n + if nil != v.Number { + sum += v.Number.Content } } r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(sum)}} @@ -541,9 +540,8 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { sum := 0.0 count := 0 for _, v := range r.Contents { - if "" != v.String() { - n, _ := strconv.ParseFloat(v.String(), 64) - sum += n + if nil != v.Number { + sum += v.Number.Content count++ } } @@ -553,9 +551,8 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { case CalcOperatorMedian: var numbers []float64 for _, v := range r.Contents { - if "" != v.String() { - n, _ := strconv.ParseFloat(v.String(), 64) - numbers = append(numbers, n) + if nil != v.Number { + numbers = append(numbers, v.Number.Content) } } sort.Float64s(numbers) @@ -565,10 +562,9 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { case CalcOperatorMin: min := math.MaxFloat64 for _, v := range r.Contents { - if "" != v.String() { - n, _ := strconv.ParseFloat(v.String(), 64) - if n < min { - min = n + if nil != v.Number { + if v.Number.Content < min { + min = v.Number.Content } } } @@ -576,10 +572,9 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { case CalcOperatorMax: max := -math.MaxFloat64 for _, v := range r.Contents { - if "" != v.String() { - n, _ := strconv.ParseFloat(v.String(), 64) - if n > max { - max = n + if nil != v.Number { + if v.Number.Content > max { + max = v.Number.Content } } } @@ -588,13 +583,12 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { min := math.MaxFloat64 max := -math.MaxFloat64 for _, v := range r.Contents { - if "" != v.String() { - n, _ := strconv.ParseFloat(v.String(), 64) - if n < min { - min = n + if nil != v.Number { + if v.Number.Content < min { + min = v.Number.Content } - if n > max { - max = n + if v.Number.Content > max { + max = v.Number.Content } } } @@ -602,32 +596,40 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { case CalcOperatorChecked: countChecked := 0 for _, v := range r.Contents { - if "√" == v.String() { - countChecked++ + if nil != v.Checkbox { + if v.Checkbox.Checked { + countChecked++ + } } } r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(float64(countChecked))}} case CalcOperatorUnchecked: countUnchecked := 0 for _, v := range r.Contents { - if "√" != v.String() { - countUnchecked++ + if nil != v.Checkbox { + if !v.Checkbox.Checked { + countUnchecked++ + } } } r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(float64(countUnchecked))}} case CalcOperatorPercentChecked: countChecked := 0 for _, v := range r.Contents { - if "√" == v.String() { - countChecked++ + if nil != v.Checkbox { + if v.Checkbox.Checked { + countChecked++ + } } } r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(float64(countChecked * 100 / len(r.Contents)))}} case CalcOperatorPercentUnchecked: countUnchecked := 0 for _, v := range r.Contents { - if "√" != v.String() { - countUnchecked++ + if nil != v.Checkbox { + if !v.Checkbox.Checked { + countUnchecked++ + } } } r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(float64(countUnchecked * 100 / len(r.Contents)))}} From b2967713405954db7fcb9cea0019f9fe0d21086c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 16:27:01 +0800 Subject: [PATCH 04/10] :art: Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958 --- kernel/av/value.go | 14 +++++++------- kernel/model/attribute_view.go | 22 +++++++++------------- kernel/treenode/node.go | 16 ++++++---------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/kernel/av/value.go b/kernel/av/value.go index 28e0e3ca1..0e70548cc 100644 --- a/kernel/av/value.go +++ b/kernel/av/value.go @@ -475,7 +475,7 @@ type ValueRollup struct { Contents []*Value `json:"contents"` } -func (r *ValueRollup) RenderContents(calc *RollupCalc) { +func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key) { if nil == calc { return } @@ -535,7 +535,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { sum += v.Number.Content } } - r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(sum)}} + r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(sum, destKey.NumberFormat)}} case CalcOperatorAverage: sum := 0.0 count := 0 @@ -546,7 +546,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { } } if 0 < count { - r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(sum / float64(count))}} + r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(sum/float64(count), destKey.NumberFormat)}} } case CalcOperatorMedian: var numbers []float64 @@ -557,7 +557,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { } sort.Float64s(numbers) if 0 < len(numbers) { - r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(numbers[len(numbers)/2])}} + r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(numbers[len(numbers)/2], destKey.NumberFormat)}} } case CalcOperatorMin: min := math.MaxFloat64 @@ -568,7 +568,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { } } } - r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(min)}} + r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(min, destKey.NumberFormat)}} case CalcOperatorMax: max := -math.MaxFloat64 for _, v := range r.Contents { @@ -578,7 +578,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { } } } - r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(max)}} + r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(max, destKey.NumberFormat)}} case CalcOperatorRange: min := math.MaxFloat64 max := -math.MaxFloat64 @@ -592,7 +592,7 @@ func (r *ValueRollup) RenderContents(calc *RollupCalc) { } } } - r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewValueNumber(max - min)}} + r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(max-min, destKey.NumberFormat)}} case CalcOperatorChecked: countChecked := 0 for _, v := range r.Contents { diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index e98545782..fc86013e4 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -243,13 +243,9 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) { relVal := attrView.GetValue(kv.Key.Rollup.RelationKeyID, kv.Values[0].BlockID) if nil != relVal && nil != relVal.Relation { destAv, _ := av.ParseAttributeView(relKey.Relation.AvID) - if nil != destAv { + destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID) + if nil != destAv && nil != destKey { for _, bID := range relVal.Relation.BlockIDs { - destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID) - if nil == destKey { - continue - } - destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID) if nil == destVal { destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, blockID, destKey.Type) @@ -261,8 +257,8 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) { } kv.Values[0].Rollup.Contents = append(kv.Values[0].Rollup.Contents, destVal.Clone()) - kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc) } + kv.Values[0].Rollup.RenderContents(kv.Key.Rollup.Calc, destKey) } } case av.KeyTypeRelation: @@ -817,12 +813,12 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a break } - for _, blockID := range relVal.Relation.BlockIDs { - destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) - if nil == destKey { - continue - } + destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) + if nil == destKey { + continue + } + for _, blockID := range relVal.Relation.BlockIDs { destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) if nil == destVal { destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) @@ -835,7 +831,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a cell.Value.Rollup.Contents = append(cell.Value.Rollup.Contents, destVal.Clone()) } - cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc) + cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey) case av.KeyTypeRelation: // 渲染关联列 relKey, _ := attrView.GetKey(cell.Value.KeyID) if nil != relKey && nil != relKey.Relation { diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go index d96ec25da..0853c513b 100644 --- a/kernel/treenode/node.go +++ b/kernel/treenode/node.go @@ -774,18 +774,14 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a break } - for _, blockID := range relVal.Relation.BlockIDs { - destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) - if nil == destKey { - continue - } + destKey, _ := destAv.GetKey(rollupKey.Rollup.KeyID) + if nil == destKey { + continue + } + for _, blockID := range relVal.Relation.BlockIDs { destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) if nil == destVal { - if nil == destKey { - continue - } - destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) } if av.KeyTypeNumber == destKey.Type { @@ -796,7 +792,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a cell.Value.Rollup.Contents = append(cell.Value.Rollup.Contents, destVal.Clone()) } - cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc) + cell.Value.Rollup.RenderContents(rollupKey.Rollup.Calc, destKey) case av.KeyTypeRelation: // 渲染关联列 relKey, _ := attrView.GetKey(cell.Value.KeyID) if nil != relKey && nil != relKey.Relation { From 876e95ef277dab6551414f7a4dd5892ea41e1139 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 16:34:58 +0800 Subject: [PATCH 05/10] :art: S3/WebDAV data sync and backup are available for a fee https://github.com/siyuan-note/siyuan/issues/8780 --- kernel/model/conf.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 72bbe3bef..84f2ba1ff 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -780,12 +780,17 @@ func IsSubscriber() bool { } func IsPaidUser() bool { + // S3/WebDAV data sync and backup are available for a fee https://github.com/siyuan-note/siyuan/issues/8780 + if IsSubscriber() { return true } - return nil != Conf.GetUser() // Sign in to use S3/WebDAV data sync https://github.com/siyuan-note/siyuan/issues/8779 - // TODO S3/WebDAV data sync and backup are available for a fee https://github.com/siyuan-note/siyuan/issues/8780 - // return nil != Conf.User && 1 == Conf.User.UserSiYuanOneTimePayStatus + + u := Conf.GetUser() + if nil == u { + return false + } + return 1 == u.UserSiYuanOneTimePayStatus } const ( From b9f1da33f0f140dd093a99a1f2126dc3271f0700 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 16:48:52 +0800 Subject: [PATCH 06/10] :art: Improve upload assets tip --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- kernel/api/asset.go | 8 +++++--- kernel/model/assets.go | 6 +++++- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 402b7f18f..6c40b8e5b 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1200,7 +1200,7 @@ "38": "Too many keywords mentioned [%d], adjust if necessary [Settings - Search - Backlink Mentions - Keyword Limit]", "39": "Deleting index %s", "40": "Inserting index %s", - "41": "Upload completed", + "41": "Upload completed [%d]", "42": "The setting is complete, the application will be closed automatically, please restart later...", "43": "The maximum storage capacity of cloud space [%s] has been exceeded, and data upload cannot continue", "44": "Parse template failed: %s", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 8f1e92d4e..136e9e485 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1200,7 +1200,7 @@ "38": "Demasiadas palabras clave mencionadas [%d], ajústelas si es necesario [Configuración - Búsqueda - Menciones de backlinks - Límite de palabras clave]", "39": "Eliminando índice %s", "40": "Insertando índice %s", - "41": "Carga completada", + "41": "Carga completada [%d]", "42": "La configuración se ha completado, la aplicación se cerrará automáticamente, por favor reinicie más tarde...", "43": "Se ha superado la capacidad máxima de almacenamiento del espacio en la nube [%s] y la carga de datos no puede continuar", "44": "El proceso de análisis de la plantilla ha fallado: %s", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 7defe0f66..4f7010f2d 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1200,7 +1200,7 @@ "38": "Trop de mots-clés mentionnés [%d], ajustez si nécessaire [Paramètres - Recherche - Mentions de backlink - Limite de mots-clés]", "39": "Suppression de l'index %s", "40": "Insertion de l'index %s", - "41": "Transfert complété", + "41": "Transfert complété [%d]", "42": "Le paramétrage est terminé, l'application se fermera automatiquement, merci de redémarrer plus tard...", "43": "La capacité de stockage maximale de l'espace cloud [%s] a été dépassée et le téléchargement des données ne peut pas continuer", "44": "L'analyse du template a échoué : %s", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 171084d0e..f0a2de14f 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1200,7 +1200,7 @@ "38": "提及關鍵字數量 [%d] 過多,如有需要可以調整 [設置 - 搜索 - 反連提及 - 關鍵字數量限制]", "39": "正在刪除索引 %s", "40": "正在插入索引 %s", - "41": "上傳完畢", + "41": "上傳完畢 [%d]", "42": "設置完成,即將自動關閉應用,請稍後重新啟動...", "43": "已超過雲端空間最大存儲容量 [%s],無法繼續上傳資料", "44": "範本解析失敗:%s", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 1a66783ad..cce910915 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1200,7 +1200,7 @@ "38": "提及关键字数量 [%d] 过多,如有需要可以调整 [设置 - 搜索 - 反链提及 - 关键字数量限制]", "39": "正在删除索引 %s", "40": "正在插入索引 %s", - "41": "上传完毕", + "41": "上传完毕 [%d]", "42": "设置完成,即将自动关闭应用,请稍后重新启动...", "43": "已超过云端空间最大存储容量 [%s],无法继续上传数据", "44": "模板解析失败:%s", diff --git a/kernel/api/asset.go b/kernel/api/asset.go index e8514cb4d..0dc9c6133 100644 --- a/kernel/api/asset.go +++ b/kernel/api/asset.go @@ -17,6 +17,7 @@ package api import ( + "fmt" "net/http" "path/filepath" "strings" @@ -257,14 +258,15 @@ func uploadCloud(c *gin.Context) { } rootID := arg["id"].(string) - err := model.UploadAssets2Cloud(rootID) + count, err := model.UploadAssets2Cloud(rootID) if nil != err { ret.Code = -1 ret.Msg = err.Error() ret.Data = map[string]interface{}{"closeTimeout": 3000} - } else { - util.PushMsg(model.Conf.Language(41), 3000) + return } + + util.PushMsg(fmt.Sprintf(model.Conf.Language(41), count), 3000) } func insertLocalAssets(c *gin.Context) { diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 855c877d4..65267c8d5 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -509,13 +509,17 @@ func GetAssetAbsPath(relativePath string) (ret string, err error) { return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath)) } -func UploadAssets2Cloud(rootID string) (err error) { +func UploadAssets2Cloud(rootID string) (count int, err error) { if !IsSubscriber() { return } sqlAssets := sql.QueryRootBlockAssets(rootID) err = uploadAssets2Cloud(sqlAssets, bizTypeUploadAssets) + if nil != err { + return + } + count = len(sqlAssets) return } From fdb0600dbbfeb4fe495e086645f80da5669587ed Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 16:54:00 +0800 Subject: [PATCH 07/10] :art: Improve upload assets to cloud --- kernel/model/assets.go | 21 +++++++++++++-------- kernel/model/export.go | 4 ++-- kernel/sql/asset.go | 15 --------------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 65267c8d5..f1050f960 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -514,12 +514,17 @@ func UploadAssets2Cloud(rootID string) (count int, err error) { return } - sqlAssets := sql.QueryRootBlockAssets(rootID) - err = uploadAssets2Cloud(sqlAssets, bizTypeUploadAssets) + tree, err := loadTreeByBlockID(rootID) if nil != err { return } - count = len(sqlAssets) + + assets := assetsLinkDestsInTree(tree) + err = uploadAssets2Cloud(assets, bizTypeUploadAssets) + if nil != err { + return + } + count = len(assets) return } @@ -529,17 +534,17 @@ const ( ) // uploadAssets2Cloud 将资源文件上传到云端图床。 -func uploadAssets2Cloud(sqlAssets []*sql.Asset, bizType string) (err error) { +func uploadAssets2Cloud(assetPaths []string, bizType string) (err error) { var uploadAbsAssets []string - for _, asset := range sqlAssets { + for _, assetPath := range assetPaths { var absPath string - absPath, err = GetAssetAbsPath(asset.Path) + absPath, err = GetAssetAbsPath(assetPath) if nil != err { - logging.LogWarnf("get asset [%s] abs path failed: %s", asset, err) + logging.LogWarnf("get asset [%s] abs path failed: %s", assetPath, err) return } if "" == absPath { - logging.LogErrorf("not found asset [%s]", asset) + logging.LogErrorf("not found asset [%s]", assetPath) continue } diff --git a/kernel/model/export.go b/kernel/model/export.go index 367b95b6d..fa91a029b 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -67,8 +67,8 @@ func Export2Liandi(id string) (err error) { return errors.New(Conf.Language(204)) } - sqlAssets := sql.QueryRootBlockAssets(id) - err = uploadAssets2Cloud(sqlAssets, bizTypeExport2Liandi) + assets := assetsLinkDestsInTree(tree) + err = uploadAssets2Cloud(assets, bizTypeExport2Liandi) if nil != err { return } diff --git a/kernel/sql/asset.go b/kernel/sql/asset.go index 332dfd850..66d619d55 100644 --- a/kernel/sql/asset.go +++ b/kernel/sql/asset.go @@ -115,21 +115,6 @@ func QueryAssetByHash(hash string) (ret *Asset) { return } -func QueryRootBlockAssets(rootID string) (ret []*Asset) { - sqlStmt := "SELECT * FROM assets WHERE root_id = ?" - rows, err := query(sqlStmt, rootID) - if nil != err { - logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err) - return - } - defer rows.Close() - for rows.Next() { - asset := scanAssetRows(rows) - ret = append(ret, asset) - } - return -} - func scanAssetRows(rows *sql.Rows) (ret *Asset) { var asset Asset if err := rows.Scan(&asset.ID, &asset.BlockID, &asset.RootID, &asset.Box, &asset.DocPath, &asset.Path, &asset.Name, &asset.Title, &asset.Hash); nil != err { From 275714f0170b425242b9bb02eda2796609d537a7 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 17:07:15 +0800 Subject: [PATCH 08/10] :bug: The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042 --- app/changelogs/v2.12.0/v2.12.0.md | 1 + app/changelogs/v2.12.0/v2.12.0_zh_CHT.md | 1 + app/changelogs/v2.12.0/v2.12.0_zh_CN.md | 1 + kernel/model/assets.go | 42 ++++++++++++++++++++++-- kernel/model/export.go | 3 ++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/changelogs/v2.12.0/v2.12.0.md b/app/changelogs/v2.12.0/v2.12.0.md index 3a77274ea..fa104d3c2 100644 --- a/app/changelogs/v2.12.0/v2.12.0.md +++ b/app/changelogs/v2.12.0/v2.12.0.md @@ -36,6 +36,7 @@ Below are the detailed changes in this version. * [Reference jump is not located in read-only mode](https://github.com/siyuan-note/siyuan/issues/10028) * [Converting PDF annotation ref to text fails after setting the appearance](https://github.com/siyuan-note/siyuan/issues/10029) * [Pressing the scoring shortcut key immediately after `Alt+F` is invalid](https://github.com/siyuan-note/siyuan/issues/10020) +* [The images in the embed blocks are not uploaded to the community hosting](https://github.com/siyuan-note/siyuan/issues/10042) ### Development diff --git a/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md b/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md index 39ba7f3c3..e2be68fff 100644 --- a/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md +++ b/app/changelogs/v2.12.0/v2.12.0_zh_CHT.md @@ -36,6 +36,7 @@ * [唯讀模式下引用跳轉後未定位瀏覽位置](https://github.com/siyuan-note/siyuan/issues/10028) * [無法轉換外觀樣式的 PDF 註解引用為文字](https://github.com/siyuan-note/siyuan/issues/10029) * [`Alt+F` 後快速按下評分快捷鍵失效](https://github.com/siyuan-note/siyuan/issues/10020) +* [在嵌入區塊中的圖片未能上傳社群](https://github.com/siyuan-note/siyuan/issues/10042) ### 開發者 diff --git a/app/changelogs/v2.12.0/v2.12.0_zh_CN.md b/app/changelogs/v2.12.0/v2.12.0_zh_CN.md index 36ed88b0b..da9159b30 100644 --- a/app/changelogs/v2.12.0/v2.12.0_zh_CN.md +++ b/app/changelogs/v2.12.0/v2.12.0_zh_CN.md @@ -36,6 +36,7 @@ * [只读模式下引用跳转后未定位浏览位置](https://github.com/siyuan-note/siyuan/issues/10028) * [无法转换带外观样式的 PDF 注释引用为文本](https://github.com/siyuan-note/siyuan/issues/10029) * [`Alt+F` 后快速按下评分快捷键失效](https://github.com/siyuan-note/siyuan/issues/10020) +* [在嵌入块中的图片未能上传社区](https://github.com/siyuan-note/siyuan/issues/10042) ### 开发者 diff --git a/kernel/model/assets.go b/kernel/model/assets.go index f1050f960..3f0a02750 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -20,6 +20,7 @@ import ( "bytes" "errors" "fmt" + "github.com/88250/lute/editor" "io" "io/fs" "mime" @@ -520,6 +521,9 @@ func UploadAssets2Cloud(rootID string) (count int, err error) { } assets := assetsLinkDestsInTree(tree) + embedAssets := assetsLinkDestsInQueryEmbedNodes(tree) + assets = append(assets, embedAssets...) + assets = gulu.Str.RemoveDuplicatedElem(assets) err = uploadAssets2Cloud(assets, bizTypeUploadAssets) if nil != err { return @@ -1053,9 +1057,43 @@ func emojisInTree(tree *parse.Tree) (ret []string) { return } -func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) { +func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) { ret = []string{} ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering || ast.NodeBlockQueryEmbedScript != n.Type { + return ast.WalkContinue + } + + stmt := n.ChildByType(ast.NodeBlockQueryEmbedScript).TokensStr() + stmt = html.UnescapeString(stmt) + stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n") + sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit) + for _, sqlBlock := range sqlBlocks { + subtree, _ := loadTreeByBlockID(sqlBlock.ID) + if nil == subtree { + continue + } + embedNode := treenode.GetNodeInTree(subtree, sqlBlock.ID) + if nil == embedNode { + continue + } + + ret = append(ret, assetsLinkDestsInNode(embedNode)...) + } + return ast.WalkContinue + }) + ret = gulu.Str.RemoveDuplicatedElem(ret) + return +} + +func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) { + ret = assetsLinkDestsInNode(tree.Root) + return +} + +func assetsLinkDestsInNode(node *ast.Node) (ret []string) { + ret = []string{} + ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus { // 修改以下代码时需要同时修改 database 构造行级元素实现,增加必要的类型 if !entering || (ast.NodeLinkDest != n.Type && ast.NodeHTMLBlock != n.Type && ast.NodeInlineHTML != n.Type && ast.NodeIFrame != n.Type && ast.NodeWidget != n.Type && ast.NodeAudio != n.Type && ast.NodeVideo != n.Type && @@ -1112,7 +1150,7 @@ func assetsLinkDestsInTree(tree *parse.Tree) (ret []string) { dest := strings.TrimSpace(string(src)) ret = append(ret, dest) } else { - logging.LogWarnf("src is missing the closing double quote in tree [%s] ", tree.Box+tree.Path) + logging.LogWarnf("src is missing the closing double quote in tree [%s] ", node.Box+node.Path) } } } diff --git a/kernel/model/export.go b/kernel/model/export.go index fa91a029b..62d6f02d6 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -68,6 +68,9 @@ func Export2Liandi(id string) (err error) { } assets := assetsLinkDestsInTree(tree) + embedAssets := assetsLinkDestsInQueryEmbedNodes(tree) + assets = append(assets, embedAssets...) + assets = gulu.Str.RemoveDuplicatedElem(assets) err = uploadAssets2Cloud(assets, bizTypeExport2Liandi) if nil != err { return From d71f488880562e8c4e7d5126af99cd37915b9872 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 17:08:04 +0800 Subject: [PATCH 09/10] :bug: The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042 --- kernel/model/assets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 3f0a02750..16a0a50bb 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -1064,7 +1064,7 @@ func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) { return ast.WalkContinue } - stmt := n.ChildByType(ast.NodeBlockQueryEmbedScript).TokensStr() + stmt := n.TokensStr() stmt = html.UnescapeString(stmt) stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n") sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit) From ea5788728856a78d4ef23fc383285597009164a3 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Jan 2024 17:09:16 +0800 Subject: [PATCH 10/10] :bug: The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042 --- kernel/model/assets.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 16a0a50bb..90ec91908 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -1058,6 +1058,8 @@ func emojisInTree(tree *parse.Tree) (ret []string) { } func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (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 { if !entering || ast.NodeBlockQueryEmbedScript != n.Type {