mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Add an internal kernel API /api/block/prependDailyNoteBlock https://github.com/siyuan-note/siyuan/issues/11442
This commit is contained in:
parent
761e48dada
commit
15375cfd98
2 changed files with 54 additions and 0 deletions
|
|
@ -133,6 +133,59 @@ func appendDailyNoteBlock(c *gin.Context) {
|
|||
broadcastTransactions(transactions)
|
||||
}
|
||||
|
||||
func prependDailyNoteBlock(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: "prependInsert",
|
||||
Data: data,
|
||||
ParentID: parentID,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
model.PerformTransactions(&transactions)
|
||||
model.WaitForWritingFiles()
|
||||
|
||||
ret.Data = transactions
|
||||
broadcastTransactions(transactions)
|
||||
}
|
||||
|
||||
func unfoldBlock(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue