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: Supports local shorthands on Android https://github.com/siyuan-note/siyuan/issues/14414
Daniel251ce2b2b878
diff --git a/kernel/api/filetree.go b/kernel/api/filetree.goindex e40ebdcb12..f0b8672278 100644--- a/kernel/api/filetree.go+++ b/kernel/api/filetree.go@@ -35,6 +35,59 @@ import ("github.com/siyuan-note/siyuan/kernel/util")+func moveLocalShorthands(c *gin.Context) {+ ret := gulu.Ret.NewResult()+ defer c.JSON(http.StatusOK, ret)++ arg, ok := util.JsonArg(c, ret)+ if !ok {+ return+ }++ notebook := arg["notebook"].(string)+ if util.InvalidIDPattern(notebook, ret) {+ return+ }++ var parentID string+ parentIDArg := arg["parentID"]+ if nil != parentIDArg {+ parentID = parentIDArg.(string)+ }++ id := ast.NewNodeID()+ idArg := arg["id"]+ if nil != idArg {+ id = idArg.(string)+ }++ hPath := arg["path"].(string)+ baseName := path.Base(hPath)+ dir := path.Dir(hPath)+ r, _ := regexp.Compile("\r\n|\r|\n|\u2028|\u2029|\t|/")+ baseName = r.ReplaceAllString(baseName, "")+ if 512 < utf8.RuneCountInString(baseName) {+ baseName = gulu.Str.SubStr(baseName, 512)+ }+ hPath = path.Join(dir, baseName)+ if !strings.HasPrefix(hPath, "/") {+ hPath = "/" + hPath+ }++ id, err := model.MoveLocalShorthands(notebook, hPath, parentID, id)+ if err != nil {+ ret.Code = -1+ ret.Msg = err.Error()+ return+ }+ ret.Data = id++ model.FlushTxQueue()+ box := model.Conf.Box(notebook)+ b, _ := model.GetBlock(id, nil)+ pushCreate(box, b.Path, arg)+}+func listDocTree(c *gin.Context) {// Add kernel API `/api/filetree/listDocTree` https://github.com/siyuan-note/siyuan/issues/10482diff --git a/kernel/job/cron.go b/kernel/job/cron.goindex eef5d79dcb..7255631f2a 100644--- a/kernel/job/cron.go+++ b/kernel/job/cron.go@@ -44,7 +44,6 @@ func StartCron() {go every(30*time.Second, model.HookDesktopUIProcJob)go every(24*time.Hour, model.AutoPurgeRepoJob)go every(30*time.Minute, model.AutoCheckMicrosoftDefender)- go every(7*time.Second, model.ShortcutsAppendToDailynote)}func every(interval time.Duration, f func()) {diff --git a/kernel/model/shortcuts.go b/kernel/model/shortcuts.goindex c61173a258..9f53f75b01 100644--- a/kernel/model/shortcuts.go+++ b/kernel/model/shortcuts.go@@ -27,15 +27,15 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-func ShortcutsAppendToDailynote() {- dailynotesDir := filepath.Join(util.ShortcutsPath, "dailynotes")- if !gulu.File.IsDir(dailynotesDir) {+func MoveLocalShorthands(boxID, hPath, parentID, id string) (retID string, err error) {+ shorthandsDir := filepath.Join(util.ShortcutsPath, "shorthands")+ if !gulu.File.IsDir(shorthandsDir) {return}- dir, err := os.ReadDir(dailynotesDir)+ dir, err := os.ReadDir(shorthandsDir)if nil != err {- logging.LogErrorf("read dir [%s] failed: %s", dailynotesDir, err)+ logging.LogErrorf("read dir [%s] failed: %s", shorthandsDir, err)return}@@ -50,7 +50,7 @@ func ShortcutsAppendToDailynote() {continue}- p := filepath.Join(dailynotesDir, entry.Name())+ p := filepath.Join(shorthandsDir, entry.Name())data, readErr := os.ReadFile(p)if nil != readErr {logging.LogErrorf("read file [%s] failed: %s", p, readErr)@@ -59,22 +59,32 @@ func ShortcutsAppendToDailynote() {buff.Write(bytes.TrimSpace(data))buff.WriteString("\n\n")- logging.LogInfof("read dailynote [%s] content [%s]", p, data)+ logging.LogInfof("read shorthand [%s] content [%s]", p, data)toRemoves = append(toRemoves, p)}- defer func() {+ clearShorthand := func(toRemoves []string) {for _, p := range toRemoves {- if err := os.Remove(p); nil != err {- logging.LogErrorf("remove file [%s] failed: %s", p, err)+ if removeErr := os.Remove(p); nil != removeErr {+ logging.LogErrorf("remove file [%s] failed: %s", p, removeErr)}}- }()+ }content := strings.TrimSpace(buff.String())if 1 > len(content) {+ clearShorthand(toRemoves)+ return+ }++ logging.LogInfof("shorthand content [%s]", content)++ retID, err = CreateWithMarkdown("", boxID, hPath, content, parentID, id, false, "")+ if nil != err {+ logging.LogErrorf("create doc failed: %s", err)return}- logging.LogInfof("append dailynote content [%s]", content)+ clearShorthand(toRemoves)+ return}