Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve av

Daniel68a7a4554249
diff --git a/kernel/model/attribute_view_fix.go b/kernel/model/attribute_view_fix.go
index fe637f41c3..c999567915 100644
--- a/kernel/model/attribute_view_fix.go
+++ b/kernel/model/attribute_view_fix.go
@@ -17,10 +17,14 @@
package model
import (
+ "time"
+
"github.com/88250/gulu"
+ "github.com/88250/lute/ast"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/treenode"
+ "github.com/siyuan-note/siyuan/kernel/util"
)
func checkAttrView(attrView *av.AttributeView, view *av.View) {
@@ -45,7 +49,7 @@ func checkAttrView(attrView *av.AttributeView, view *av.View) {
}
view.Sorts = tmpSorts
- // 视图类型不匹配时需要订正
+ // 订正视图类型
for i, v := range attrView.Views {
if av.LayoutTypeGallery == v.LayoutType && nil == v.Gallery {
// 切换为卡片视图时可能没有初始化卡片实例 https://github.com/siyuan-note/siyuan/issues/15122
@@ -59,6 +63,36 @@ func checkAttrView(attrView *av.AttributeView, view *av.View) {
}
}
+ now := util.CurrentTimeMillis()
+
+ // 订正字段类型
+ for _, kv := range attrView.KeyValues {
+ for _, v := range kv.Values {
+ if v.Type != kv.Key.Type {
+ v.Type = kv.Key.Type
+ if av.KeyTypeBlock == v.Type && nil == v.Block {
+ v.Block = &av.ValueBlock{ID: v.BlockID}
+ if nil != v.Text {
+ v.Block.Content = v.Text.Content
+ }
+ if "" == v.Block.ID {
+ v.Block.ID = ast.NewNodeID()
+ v.BlockID = v.Block.ID
+ }
+ createdStr := v.Block.ID[:len("20060102150405")]
+ created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
+ if nil == parseErr {
+ v.Block.Created = created.UnixMilli()
+ } else {
+ v.Block.Created = now
+ }
+ v.Block.Updated = v.Block.Created
+ }
+ changed = true
+ }
+ }
+ }
+
if changed {
av.SaveAttributeView(attrView)
}