admin: fix server settings env editor crashing on empty template

ReadEnvGroups returned a nil slice (out := groups[:0]) whenever no group
ended up with fields, which marshals to JSON null instead of []. The
admin UI's EnvSection calls groups.reduce()/iterates unconditionally, so
that null crashed the Server Settings page.

Also switch the source of the panel structure from .env.example to .env
once .env exists, falling back to .env.example only pre-setup: .env
already carries the same group headers and comments after any save
(WriteEnvValues always rewrites it from .env.example's exact text), so
it's the more current source of what's actually configured.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Astra 2026-09-14 18:59:24 +01:00
parent 4cbd4c0c9e
commit 8850554500
2 changed files with 22 additions and 12 deletions

View file

@ -415,9 +415,9 @@ function EnvSection() {
setError("");
try {
const g = await api.serverEnv();
setGroups(g);
setGroups(g ?? []);
const next: Record<string, string> = {};
for (const group of g) {
for (const group of g ?? []) {
for (const field of group.fields) {
next[field.key] = field.value;
}