mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 03:50:16 +08:00
🧑💻 Add internal kernel API /api/block/appendDailyNoteBlock
Fix https://github.com/siyuan-note/siyuan/issues/10368
This commit is contained in:
parent
6f8c1176f5
commit
678f28a37c
@ -19,6 +19,8 @@ package api
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
@ -30,6 +32,59 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func appendDailyNoteBlock(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := arg["data"].(string)
|
||||||
|
dataType := arg["dataType"].(string)
|
||||||
|
boxID := arg["notebook"].(string)
|
||||||
|
if util.InvalidIDPattern(boxID, ret) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if "markdown" == dataType {
|
||||||
|
luteEngine := util.NewLute()
|
||||||
|
var err error
|
||||||
|
data, err = dataBlockDOM(data, luteEngine)
|
||||||
|
if nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "data block DOM failed: " + err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p, _, err := model.CreateDailyNote(boxID)
|
||||||
|
if nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "create daily note failed: " + err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
parentID := strings.TrimSuffix(path.Base(p), ".sy")
|
||||||
|
transactions := []*model.Transaction{
|
||||||
|
{
|
||||||
|
DoOperations: []*model.Operation{
|
||||||
|
{
|
||||||
|
Action: "appendInsert",
|
||||||
|
Data: data,
|
||||||
|
ParentID: parentID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
model.PerformTransactions(&transactions)
|
||||||
|
model.WaitForWritingFiles()
|
||||||
|
|
||||||
|
ret.Data = transactions
|
||||||
|
broadcastTransactions(transactions)
|
||||||
|
}
|
||||||
|
|
||||||
func unfoldBlock(c *gin.Context) {
|
func unfoldBlock(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
@ -181,6 +181,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
ginServer.Handle("POST", "/api/block/insertBlock", model.CheckAuth, model.CheckReadonly, insertBlock)
|
ginServer.Handle("POST", "/api/block/insertBlock", model.CheckAuth, model.CheckReadonly, insertBlock)
|
||||||
ginServer.Handle("POST", "/api/block/prependBlock", model.CheckAuth, model.CheckReadonly, prependBlock)
|
ginServer.Handle("POST", "/api/block/prependBlock", model.CheckAuth, model.CheckReadonly, prependBlock)
|
||||||
ginServer.Handle("POST", "/api/block/appendBlock", model.CheckAuth, model.CheckReadonly, appendBlock)
|
ginServer.Handle("POST", "/api/block/appendBlock", model.CheckAuth, model.CheckReadonly, appendBlock)
|
||||||
|
ginServer.Handle("POST", "/api/block/appendDailyNoteBlock", model.CheckAuth, model.CheckReadonly, appendDailyNoteBlock)
|
||||||
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, model.CheckReadonly, updateBlock)
|
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, model.CheckReadonly, updateBlock)
|
||||||
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, model.CheckReadonly, deleteBlock)
|
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, model.CheckReadonly, deleteBlock)
|
||||||
ginServer.Handle("POST", "/api/block/moveBlock", model.CheckAuth, model.CheckReadonly, moveBlock)
|
ginServer.Handle("POST", "/api/block/moveBlock", model.CheckAuth, model.CheckReadonly, moveBlock)
|
||||||
|
Loading…
Reference in New Issue
Block a user