[add] page builder editor render api

This commit is contained in:
Max 2023-10-05 23:12:15 +08:00
parent b43f83aa61
commit 92a3405f75
2 changed files with 50 additions and 8 deletions

View file

@ -114,13 +114,25 @@ var dsl = []byte(`
"path": "/:id/editor/render/:template_id/*route",
"method": "GET",
"process": "sui.Editor.Render",
"in": ["$param.id", "$param.template_id", "$param.route"],
"in": ["$param.id", "$param.template_id", "$param.route", ":query"],
"out": { "status": 200, "type": "application/json" }
},{
"path": "/:id/editor/render/:template_id/*route",
"method": "POST",
"process": "sui.Editor.RenderAfterSaveTemp",
"in": ["$param.id", "$param.template_id", "$param.route", ":context", ":query"],
"out": { "status": 200, "type": "application/json" }
},{
"path": "/:id/editor/:kind/source/:template_id/*route",
"method": "GET",
"process": "sui.Editor.Source",
"in": ["$param.id", "$param.template_id", "$param.route", "$param.kind"],
"in": ["$param.id", "$param.template_id", "$param.route", "$param.kind", ":query"],
"out": { "status": 200, "type": "application/json" }
},{
"path": "/:id/editor/:kind/source/:template_id/*route",
"method": "POST",
"process": "sui.Editor.SourceAfterSaveTemp",
"in": ["$param.id", "$param.template_id", "$param.route", ":context", "$param.kind", ":query"],
"out": { "status": 200, "type": "application/json" }
},

View file

@ -1,6 +1,8 @@
package api
import (
"fmt"
"net/url"
"path/filepath"
"strings"
@ -35,8 +37,10 @@ func init() {
"page.exist": PageExist,
"page.asset": PageAsset,
"editor.render": EditorRender,
"editor.source": EditorSource,
"editor.render": EditorRender,
"editor.source": EditorSource,
"editor.renderaftersavetemp": EditorRenderAfterSaveTemp,
"editor.sourceaftersavetemp": EditorSourceAfterSaveTemp,
})
}
@ -439,7 +443,6 @@ func EditorRender(process *process.Process) interface{} {
sui := get(process)
templateID := process.ArgsString(1)
route := route(process, 2)
query := process.ArgsMap(3, map[string]interface{}{"method": "GET"})
tmpl, err := sui.GetTemplate(templateID)
if err != nil {
@ -452,8 +455,14 @@ func EditorRender(process *process.Process) interface{} {
}
// Request data
req := &core.Request{Method: query["method"].(string)}
urlQuery := url.Values{}
if process.NumOfArgs() > 3 {
if v, ok := process.Args[3].(url.Values); ok {
urlQuery = v
}
}
req := &core.Request{Method: "GET", Query: urlQuery}
res, err := page.EditorRender(req)
if err != nil {
exception.New(err.Error(), 500).Throw()
@ -462,6 +471,16 @@ func EditorRender(process *process.Process) interface{} {
return res
}
// EditorRenderAfterSaveTemp handle the render page request
func EditorRenderAfterSaveTemp(process *process.Process) interface{} {
process.ValidateArgNums(5)
PageSaveTemp(process)
args := append([]interface{}{}, process.Args[:3]...)
args = append(args, process.Args[4:]...)
process.Args = args
return EditorRender(process)
}
// EditorSource handle the render page request
func EditorSource(process *process.Process) interface{} {
process.ValidateArgNums(3)
@ -501,6 +520,17 @@ func EditorSource(process *process.Process) interface{} {
}
}
// EditorSourceAfterSaveTemp handle the render page request
func EditorSourceAfterSaveTemp(process *process.Process) interface{} {
process.ValidateArgNums(5)
PageSaveTemp(process)
args := append([]interface{}{}, process.Args[:3]...)
args = append(args, process.Args[4:]...)
process.Args = args
return EditorSource(process)
}
// get the sui
func get(process *process.Process) core.SUI {
sui, has := core.SUIs[process.ArgsString(0)]
@ -534,9 +564,9 @@ func getSource(process *process.Process) (*core.RequestSource, error) {
case *gin.Context:
source := core.RequestSource{UID: v.GetHeader("Yao-Builder-Uid")}
err := v.Bind(&source)
err := v.ShouldBind(&source)
if err != nil {
return nil, err
return nil, fmt.Errorf("Bind: %s", err.Error())
}
return &source, nil