From 896e52a52abd523eaeaff969f6d221f8515d8acb Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 25 Sep 2024 08:25:37 +0800 Subject: [PATCH] Fix PublicRoot bug and get Sid from request --- sui/api/render.go | 2 +- sui/api/request.go | 8 ++++++++ sui/core/sui.go | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sui/api/render.go b/sui/api/render.go index e3ac5b21..06f2ac23 100644 --- a/sui/api/render.go +++ b/sui/api/render.go @@ -194,7 +194,7 @@ func TemplateRender(process *process.Process) interface{} { } } - r := core.Request{Theme: opt["theme"], Locale: opt["locale"]} + r := core.Request{Theme: opt["theme"], Locale: opt["locale"], Sid: process.Sid} if process.NumOfArgs() > 5 { raw, err := jsoniter.Marshal(process.Args[5]) diff --git a/sui/api/request.go b/sui/api/request.go index bd442e38..8ca48a40 100644 --- a/sui/api/request.go +++ b/sui/api/request.go @@ -53,10 +53,18 @@ func NewRequestContext(c *gin.Context) (*Request, int, error) { path := strings.TrimSuffix(c.Request.URL.Path, ".sui") + sid := "" + if v, has := c.Get("__sid"); has { + if s, ok := v.(string); ok { + sid = s + } + } + return &Request{ File: file, context: c, Request: &core.Request{ + Sid: sid, Method: c.Request.Method, Query: c.Request.URL.Query(), Body: body, diff --git a/sui/core/sui.go b/sui/core/sui.go index 44e465e4..99faf0c6 100644 --- a/sui/core/sui.go +++ b/sui/core/sui.go @@ -96,7 +96,9 @@ func (sui *DSL) PublicRoot(data map[string]interface{}) (string, error) { // Merge the data for k, v := range sessionData { - data[k] = v + if _, ok := data[k]; !ok { + data[k] = v + } } vars := map[string]interface{}{"$session": data}