MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / initialize_system

Function initialize_system

core/config.py:82–114  ·  view source on GitHub ↗
(
    admin_password: str,
    site_name: str | None = None,
    setup_options: dict | None = None,
)

Source from the content-addressed store, hash-verified

80
81
82async def initialize_system(
83 admin_password: str,
84 site_name: str | None = None,
85 setup_options: dict | None = None,
86) -> None:
87 password = str(admin_password or "").strip()
88 if len(password) < MIN_ADMIN_PASSWORD_LENGTH:
89 raise ValueError(f"管理员密码至少需要 {MIN_ADMIN_PASSWORD_LENGTH} 位")
90
91 async with db_startup_lock():
92 config_record = await KeyValue.filter(key="settings").first()
93 current_config = {
94 **DEFAULT_CONFIG,
95 **(config_record.value if config_record and config_record.value else {}),
96 }
97 if is_config_initialized(current_config):
98 raise ValueError("系统已经初始化,请直接登录后台")
99
100 next_config = dict(current_config)
101 for key, value in (setup_options or {}).items():
102 if key in SETUP_CONFIG_FIELDS:
103 next_config[key] = value
104
105 normalized_site_name = str(site_name or "").strip()
106 if normalized_site_name:
107 next_config["name"] = normalized_site_name[:80]
108
109 next_config["admin_token"] = hash_password(password)
110 if not is_valid_jwt_secret(next_config.get("jwt_secret")):
111 next_config["jwt_secret"] = generate_jwt_secret()
112
113 await KeyValue.update_or_create(key="settings", defaults={"value": next_config})
114 await refresh_settings()

Callers 1

setup_submitFunction · 0.90

Calls 10

db_startup_lockFunction · 0.90
is_config_initializedFunction · 0.90
hash_passwordFunction · 0.90
is_valid_jwt_secretFunction · 0.90
generate_jwt_secretFunction · 0.90
refresh_settingsFunction · 0.85
itemsMethod · 0.80
firstMethod · 0.45
filterMethod · 0.45
update_or_createMethod · 0.45

Tested by

no test coverage detected