From 4d550d624c72e4822fa4eabcd3a6d0abb5c52123 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 21 Oct 2023 09:01:51 +0800 Subject: [PATCH] Report language. v5.10.10 --- platform/report.go | 7 +++++++ platform/service.go | 15 +++++++++++++++ platform/utils.go | 1 + ui/src/App.js | 4 +++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/platform/report.go b/platform/report.go index 153a8c95..200e109f 100644 --- a/platform/report.go +++ b/platform/report.go @@ -148,6 +148,13 @@ func queryLatestVersion(ctx context.Context) (*Versions, error) { params["https"] = r0 } + // Report about locale feature. + if r0, err := rdb.Get(ctx, SRS_LOCALE).Result(); err != nil && err != redis.Nil { + return nil, errors.Wrapf(err, "get %v", SRS_LOCALE) + } else if r0 != "" { + params["lan"] = r0 + } + // Report about upgrade window feature. if r0, err := rdb.HGet(ctx, SRS_UPGRADE_WINDOW, "update").Result(); err != nil && err != redis.Nil { return nil, errors.Wrapf(err, "hget %v update", SRS_UPGRADE_WINDOW) diff --git a/platform/service.go b/platform/service.go index 06b47071..21929de8 100644 --- a/platform/service.go +++ b/platform/service.go @@ -476,11 +476,26 @@ func handleMgmtEnvs(ctx context.Context, handler *http.ServeMux) { logger.Tf(ctx, "Handle %v", ep) handler.HandleFunc(ep, func(w http.ResponseWriter, r *http.Request) { if err := func() error { + var locale string + if err := ParseBody(ctx, r.Body, &struct { + Locale *string `json:"locale"` + }{ + Locale: &locale, + }); err != nil { + return errors.Wrapf(err, "parse body") + } + + if err := rdb.Set(ctx, SRS_LOCALE, locale, 0).Err(); err != nil && err != redis.Nil { + return errors.Wrapf(err, "set %v %v", SRS_LOCALE, locale) + } + ohttp.WriteData(ctx, w, r, &struct { MgmtDocker bool `json:"mgmtDocker"` }{ MgmtDocker: true, }) + + logger.Tf(ctx, "mgmt envs ok, locale=%v", locale) return nil }(); err != nil { ohttp.WriteError(ctx, w, r, err) diff --git a/platform/utils.go b/platform/utils.go index 5947325a..242f37eb 100644 --- a/platform/utils.go +++ b/platform/utils.go @@ -284,6 +284,7 @@ const ( // For container and images. SRS_CONTAINER_DISABLED = "SRS_CONTAINER_DISABLED" // For system settings. + SRS_LOCALE = "SRS_LOCALE" SRS_SECRET_PUBLISH = "SRS_SECRET_PUBLISH" SRS_DOCKER_IMAGES = "SRS_DOCKER_IMAGES" SRS_AUTH_SECRET = "SRS_AUTH_SECRET" diff --git a/ui/src/App.js b/ui/src/App.js index 9e875780..49327779 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -48,7 +48,9 @@ function AppPreImpl() { React.useEffect(() => { if (!setEnv) return; - axios.get('/terraform/v1/mgmt/envs').then(res => { + axios.post('/terraform/v1/mgmt/envs', { + locale: Locale.current() + }).then(res => { setEnv(res.data.data); console.log(`Env ok, ${JSON.stringify(res.data)}`); }).catch(handleError);