Merge pull request #753 from trheyi/main

Fix PublicRoot bug and get Sid from request
This commit is contained in:
Max 2024-09-25 08:26:17 +08:00 committed by GitHub
commit 6c6aaad058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 2 deletions

View file

@ -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 { if process.NumOfArgs() > 5 {
raw, err := jsoniter.Marshal(process.Args[5]) raw, err := jsoniter.Marshal(process.Args[5])

View file

@ -53,10 +53,18 @@ func NewRequestContext(c *gin.Context) (*Request, int, error) {
path := strings.TrimSuffix(c.Request.URL.Path, ".sui") 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{ return &Request{
File: file, File: file,
context: c, context: c,
Request: &core.Request{ Request: &core.Request{
Sid: sid,
Method: c.Request.Method, Method: c.Request.Method,
Query: c.Request.URL.Query(), Query: c.Request.URL.Query(),
Body: body, Body: body,

View file

@ -96,7 +96,9 @@ func (sui *DSL) PublicRoot(data map[string]interface{}) (string, error) {
// Merge the data // Merge the data
for k, v := range sessionData { for k, v := range sessionData {
data[k] = v if _, ok := data[k]; !ok {
data[k] = v
}
} }
vars := map[string]interface{}{"$session": data} vars := map[string]interface{}{"$session": data}