Fix settings tab 500 and env config grouping in UI
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Vendored
+42
-3
@@ -8,6 +8,8 @@ from typing import Any, Optional
|
||||
from lib.env.env_file_lib import env_get, env_get_all, read_env_lines
|
||||
|
||||
_GROUP_RE = re.compile(r"^#\s*=+\s*(.+?)\s*=+\s*$")
|
||||
_SEPARATOR_RE = re.compile(r"^#\s*=+\s*$")
|
||||
_SECTION_DASH_RE = re.compile(r"^#\s*---\s*(.+?)\s*---\s*$")
|
||||
_KEY_LINE = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*)\s*=")
|
||||
|
||||
RESTART_REQUIRED_EXACT = frozenset({
|
||||
@@ -146,10 +148,14 @@ def parse_env_example_schema(example_path: str) -> list[dict[str, Any]]:
|
||||
lines = read_env_lines(example_path)
|
||||
groups: list[dict[str, Any]] = []
|
||||
group_map: dict[str, dict[str, Any]] = {}
|
||||
current_group = "应用与鉴权"
|
||||
current_group = "基础配置"
|
||||
pending_note: list[str] = []
|
||||
in_section_block = False
|
||||
section_title_set = False
|
||||
allow_section_blocks = False
|
||||
|
||||
def _ensure_group(title: str) -> dict[str, Any]:
|
||||
title = (title or "").strip() or "其他"
|
||||
if title not in group_map:
|
||||
group_map[title] = {"title": title, "fields": []}
|
||||
groups.append(group_map[title])
|
||||
@@ -161,9 +167,41 @@ def parse_env_example_schema(example_path: str) -> list[dict[str, Any]]:
|
||||
if not stripped:
|
||||
pending_note = []
|
||||
continue
|
||||
if _SEPARATOR_RE.match(stripped):
|
||||
if not allow_section_blocks:
|
||||
continue
|
||||
if not in_section_block:
|
||||
in_section_block = True
|
||||
section_title_set = False
|
||||
else:
|
||||
in_section_block = False
|
||||
continue
|
||||
if in_section_block and stripped.startswith("#"):
|
||||
note = stripped.lstrip("#").strip()
|
||||
if note and not section_title_set:
|
||||
current_group = note
|
||||
_ensure_group(current_group)
|
||||
section_title_set = True
|
||||
elif note:
|
||||
pending_note.append(note)
|
||||
continue
|
||||
gm = _GROUP_RE.match(stripped)
|
||||
if gm:
|
||||
current_group = gm.group(1).strip()
|
||||
title = gm.group(1).strip()
|
||||
if title and title != "=":
|
||||
current_group = title
|
||||
_ensure_group(current_group)
|
||||
in_section_block = False
|
||||
section_title_set = False
|
||||
pending_note = []
|
||||
continue
|
||||
dash = _SECTION_DASH_RE.match(stripped)
|
||||
if dash:
|
||||
allow_section_blocks = True
|
||||
current_group = dash.group(1).strip()
|
||||
_ensure_group(current_group)
|
||||
in_section_block = False
|
||||
section_title_set = False
|
||||
pending_note = []
|
||||
continue
|
||||
if stripped.startswith("#"):
|
||||
@@ -175,6 +213,7 @@ def parse_env_example_schema(example_path: str) -> list[dict[str, Any]]:
|
||||
if not km:
|
||||
continue
|
||||
key = km.group(1)
|
||||
allow_section_blocks = True
|
||||
default_val = env_get(lines, key) or ""
|
||||
grp = _ensure_group(current_group)
|
||||
note = " ".join(pending_note).strip()
|
||||
@@ -191,7 +230,7 @@ def parse_env_example_schema(example_path: str) -> list[dict[str, Any]]:
|
||||
}
|
||||
)
|
||||
pending_note = []
|
||||
return groups
|
||||
return [g for g in groups if g.get("fields")]
|
||||
|
||||
|
||||
def build_env_payload(example_path: str, env_path: str) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user