第一期骨架:登录、实例登记、多机总览、内嵌/新标签打开。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-01 10:54:07 +08:00
parent 55e77d6b2b
commit d20acaf852
17 changed files with 881 additions and 2 deletions
+46
View File
@@ -0,0 +1,46 @@
"""SQLite 注册表."""
from __future__ import annotations
import os
import sqlite3
from typing import Any
def db_path() -> str:
return (os.getenv("DB_PATH") or "hub.db").strip() or "hub.db"
def get_db() -> sqlite3.Connection:
conn = sqlite3.connect(db_path(), timeout=30)
conn.row_factory = sqlite3.Row
return conn
def init_db() -> None:
conn = get_db()
try:
conn.execute(
"""
CREATE TABLE IF NOT EXISTS hub_instances (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
base_url TEXT NOT NULL,
bridge_token TEXT NOT NULL,
embed_path TEXT NOT NULL DEFAULT '/embed',
tags TEXT DEFAULT '',
enabled INTEGER NOT NULL DEFAULT 1,
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
)
"""
)
conn.commit()
finally:
conn.close()
def row_to_dict(row: sqlite3.Row | None) -> dict[str, Any] | None:
if row is None:
return None
return {k: row[k] for k in row.keys()}