Cleanup and bugfixes on Bootstrap and JSONL handling.

This commit is contained in:
2026-01-26 23:54:03 +00:00
parent 7e568dbd10
commit 4ddaa9fdf4
8 changed files with 205 additions and 152 deletions
+26 -27
View File
@@ -5,13 +5,14 @@ import logging
import os
from urllib.parse import urlparse
import uvicorn
from fastapi_vue.hostutil import parse_endpoint
from uvicorn import Config, Server
from paskia import globals as _globals
from paskia.bootstrap import bootstrap_if_needed
from paskia.config import PaskiaConfig
from paskia.db import start_background
from paskia.db.background import flush
from paskia.fastapi import app as fastapi_app
from paskia.fastapi import reset as reset_cmd
from paskia.util import startupbox
@@ -183,28 +184,8 @@ def main():
}
os.environ["PASKIA_CONFIG"] = json.dumps(config_json)
# Initialize globals (without bootstrap yet)
asyncio.run(
_globals.init(
rp_id=config.rp_id,
rp_name=config.rp_name,
origins=config.origins,
bootstrap=False,
)
)
# Print startup configuration
startupbox.print_startup_config(config)
# Bootstrap after startup box is printed
asyncio.run(bootstrap_if_needed())
# Handle reset command (no server start)
if is_reset:
exit_code = reset_cmd.run(args.reset_query)
raise SystemExit(exit_code)
# Dev mode: enable reload when FASTAPI_VUE_FRONTEND_URL is set
devmode = bool(os.environ.get("FASTAPI_VUE_FRONTEND_URL"))
run_kwargs: dict = {
@@ -221,18 +202,36 @@ def main():
# Suppress uvicorn startup messages in dev mode
run_kwargs["log_level"] = "warning"
if len(endpoints) > 1:
# Run separate servers for multiple endpoints (e.g. IPv4 + IPv6)
async def serve_all():
async def async_main():
await _globals.init(
rp_id=config.rp_id,
rp_name=config.rp_name,
origins=config.origins,
bootstrap=False,
)
await bootstrap_if_needed()
await flush()
if is_reset:
exit_code = reset_cmd.run(args.reset_query)
raise SystemExit(exit_code)
await start_background()
if len(endpoints) > 1:
async with asyncio.TaskGroup() as tg:
for ep in endpoints:
tg.create_task(
Server(Config(app=fastapi_app, **run_kwargs, **ep)).serve()
)
else:
server = Server(Config(app=fastapi_app, **run_kwargs, **endpoints[0]))
await server.serve()
asyncio.run(serve_all())
else:
uvicorn.run("paskia.fastapi:app", **run_kwargs, **endpoints[0])
try:
asyncio.run(async_main())
except KeyboardInterrupt:
pass
if __name__ == "__main__":
-25
View File
@@ -220,31 +220,6 @@ async def get_settings():
}
@app.get("/token-info")
async def api_token_info(token: str):
"""Get information about a reset token.
Returns:
- type: "reset"
- user_name: display name of the user
- token_type: type of reset token
"""
if not passphrase.is_well_formed(token):
raise HTTPException(status_code=404, detail="Invalid token")
# Check if this is a reset token
try:
reset_token = await get_reset(token)
user = db.get_user_by_uuid(reset_token.user_uuid)
return {
"type": "reset",
"user_name": user.display_name,
"token_type": reset_token.token_type,
}
except (ValueError, Exception):
raise HTTPException(status_code=404, detail="Token not found or expired")
@app.post("/user-info")
async def api_user_info(
request: Request,
+7 -3
View File
@@ -71,10 +71,11 @@ async def websocket_register_add(
stripped = name.strip()
if stripped:
user_name = stripped
challenge_ids = db.get_credentials_by_user_uuid(user_uuid)
credentials = db.get_credentials_by_user_uuid(user_uuid)
credential_ids = [c.credential_id for c in credentials] if credentials else None
# WebAuthn registration
credential = await register_chat(ws, user_uuid, user_name, origin, challenge_ids)
credential = await register_chat(ws, user_uuid, user_name, origin, credential_ids)
# Create a new session and store everything in database
metadata = infodict(ws, "authenticated")
@@ -113,7 +114,10 @@ async def websocket_authenticate(ws: WebSocket, auth=AUTH_COOKIE):
try:
session = await get_session(auth, host=host)
session_user_uuid = session.user_uuid
credential_ids = db.get_credentials_by_user_uuid(session_user_uuid)
credentials = db.get_credentials_by_user_uuid(session_user_uuid)
credential_ids = (
[c.credential_id for c in credentials] if credentials else None
)
except ValueError:
pass # Invalid/expired session - allow normal authentication