An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Attribute View number column format https://github.com/siyuan-note/siyuan/issues/8764
Danielafb698d1fe0d
diff --git a/kernel/model/asset_content.go b/kernel/model/asset_content.goindex d609bef7c6..db35a2fb06 100644--- a/kernel/model/asset_content.go+++ b/kernel/model/asset_content.go@@ -17,6 +17,12 @@package modelimport (+ "io/fs"+ "os"+ "path/filepath"+ "strings"+ "sync"+"github.com/88250/gulu""github.com/88250/lute/ast""github.com/siyuan-note/eventbus"@@ -25,11 +31,48 @@ import ("github.com/siyuan-note/siyuan/kernel/sql""github.com/siyuan-note/siyuan/kernel/task""github.com/siyuan-note/siyuan/kernel/util"- "io/fs"- "path/filepath"- "strings")+var assetContentSearcher = NewAssetsSearcher()++func IndexAssetContent(absPath string) {+ assetsDir := util.GetDataAssetsAbsPath()++ ext := strings.ToLower(filepath.Ext(absPath))+ parser, found := assetContentSearcher.Parsers[ext]+ if !found {+ return+ }++ result := parser.Parse(absPath)+ if nil == result {+ return+ }++ info, err := os.Stat(absPath)+ if nil != err {+ logging.LogErrorf("stat [%s] failed: %s", absPath, err)+ return+ }++ p := "assets" + filepath.ToSlash(strings.TrimPrefix(absPath, assetsDir))++ assetContents := []*sql.AssetContent{+ {+ ID: ast.NewNodeID(),+ Name: filepath.Base(p),+ Ext: filepath.Ext(p),+ Path: p,+ Size: info.Size(),+ Updated: info.ModTime().Unix(),+ Content: result.Content,+ },+ }++ sql.DeleteAssetContentsByPathQueue(p)+ sql.IndexAssetContentsQueue(assetContents)+}+func ReindexAssetContent() {task.AppendTask(task.AssetContentDatabaseIndexFull, fullReindexAssetContent)return@@ -39,8 +82,7 @@ func fullReindexAssetContent() {util.PushMsg(Conf.Language(216), 7*1000)sql.InitAssetContentDatabase(true)- assetsSearch := NewAssetsSearcher()- assetsSearch.Index()+ assetContentSearcher.FullIndex()return}@@ -59,12 +101,13 @@ var ()type AssetsSearcher struct {- AssetsDir string- Parsers map[string]AssetParser+ Parsers map[string]AssetParser++ lock *sync.Mutex}-func (searcher *AssetsSearcher) Index() {- assetsDir := searcher.AssetsDir+func (searcher *AssetsSearcher) FullIndex() {+ assetsDir := util.GetDataAssetsAbsPath()if !gulu.File.IsDir(assetsDir) {return}@@ -116,10 +159,11 @@ func (searcher *AssetsSearcher) Index() {func NewAssetsSearcher() *AssetsSearcher {return &AssetsSearcher{- AssetsDir: util.GetDataAssetsAbsPath(),Parsers: map[string]AssetParser{".txt": &TxtAssetParser{},},++ lock: &sync.Mutex{},}}diff --git a/kernel/model/assets_watcher.go b/kernel/model/assets_watcher.goindex aae6fa6732..d56a818497 100644--- a/kernel/model/assets_watcher.go+++ b/kernel/model/assets_watcher.go@@ -87,6 +87,9 @@ func watchAssets() {// 重新缓存资源文件,以便使用 /资源 搜索go cache.LoadAssets()++ // 索引资源文件内容+ IndexAssetContent(lastEvent.Name)}}}()diff --git a/kernel/model/assets_watcher_darwin.go b/kernel/model/assets_watcher_darwin.goindex d06a034d00..8169f3a1f0 100644--- a/kernel/model/assets_watcher_darwin.go+++ b/kernel/model/assets_watcher_darwin.go@@ -59,6 +59,9 @@ func watchAssets() {// 重新缓存资源文件,以便使用 /资源 搜索go cache.LoadAssets()++ // 索引资源文件内容+ IndexAssetContent(event.Path)case err, ok := <-assetsWatcher.Error:if !ok {returndiff --git a/kernel/sql/queue_asset_content.go b/kernel/sql/queue_asset_content.goindex 22357634ef..0741b81fbc 100644--- a/kernel/sql/queue_asset_content.go+++ b/kernel/sql/queue_asset_content.go@@ -111,7 +111,7 @@ func execAssetContentOp(op *assetContentDBQueueOperation, tx *sql.Tx, context maswitch op.action {case "index":err = insertAssetContents(tx, op.assetContents, context)- case "delete":+ case "deletePath":err = deleteAssetContentsByPath(tx, op.path, context)default:msg := fmt.Sprintf("unknown asset content operation [%s]", op.action)