fix: run init_db with panel venv python

Use venv interpreter so werkzeug is available; sync admin user from .env on init.
Set default panel username to dekun.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-16 09:14:12 +08:00
parent bccf6cfdce
commit 042ae5a422
4 changed files with 10 additions and 10 deletions
+6 -7
View File
@@ -44,14 +44,13 @@ def init_db(env: dict[str, str]) -> None:
username = env.get("PANEL_USERNAME", "admin")
password = env.get("PANEL_PASSWORD")
if not password:
raise SystemExit("请在 .env 中设置 PANEL_PASSWORD(运行 generate-keys.sh 可自动生成)")
raise SystemExit("请在 .env 中设置 PANEL_PASSWORD")
row = conn.execute("SELECT id FROM admin WHERE username = ?", (username,)).fetchone()
if row is None:
conn.execute(
"INSERT INTO admin (username, password_hash) VALUES (?, ?)",
(username, generate_password_hash(password)),
)
conn.execute("DELETE FROM admin")
conn.execute(
"INSERT INTO admin (username, password_hash) VALUES (?, ?)",
(username, generate_password_hash(password)),
)
count = conn.execute("SELECT COUNT(*) AS c FROM nodes").fetchone()["c"]
if count == 0: