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

This commit is contained in:
Vanessa 2025-03-26 12:21:07 +08:00
commit bd59a69d51
5 changed files with 78 additions and 19 deletions

View file

@ -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/10482

View file

@ -59,7 +59,7 @@ require (
github.com/sashabaranov/go-openai v1.38.1
github.com/shirou/gopsutil/v4 v4.25.2
github.com/siyuan-note/dejavu v0.0.0-20250322021810-323cb42aa914
github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97
github.com/siyuan-note/filelock v0.0.0-20250227145141-7d111cdf3c57
github.com/siyuan-note/httpclient v0.0.0-20250322021658-9045f69f1f42

View file

@ -377,8 +377,8 @@ github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05Ut
github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8=
github.com/siyuan-note/dejavu v0.0.0-20250322021810-323cb42aa914 h1:f51i21p1NHEtwcFw96tFaazVI6yvaxttSu3OyVaYLPc=
github.com/siyuan-note/dejavu v0.0.0-20250322021810-323cb42aa914/go.mod h1:f2hrbTZrR5aUAbK/ND+bETBpGqugfApeq/gy62M2wKs=
github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4 h1:kJaw5L/evyW6LcB9IQT8PR4ppx8JVqOFP9Ix3rfwSrc=
github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4/go.mod h1:UYcCCY+0wh+GmUoDOaO63j1sV5lgy7laLAk1XhEiUis=
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec h1:D8Sjwa+7WxP3XrIBscT4PxBZZddZ83/O+5nX1sq6g6g=
github.com/siyuan-note/encryption v0.0.0-20250326023622-24a67e6956ec/go.mod h1:6iAxXPOOAG3+M4bCiKQZTQ+n4gSUx/OyHhsP57dJlS8=
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 h1:lM5v8BfNtbOL5jYwhCdMYBcYtr06IYBKjjSLAPMKTM8=
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97/go.mod h1:1/nGgthl89FPA7GzAcEWKl6zRRnfgyTjzLZj9bW7kuw=
github.com/siyuan-note/filelock v0.0.0-20250227145141-7d111cdf3c57 h1:gRFbRUgTFP+XcV6vfiblGB9oHI/UwzD7cSUNwE1TrpE=
@ -455,7 +455,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
@ -515,7 +514,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
@ -528,7 +526,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=

View file

@ -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()) {

View file

@ -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("append dailynote content [%s]", content)
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
}
clearShorthand(toRemoves)
return
}