feat: finish forecast rendering and account-authenticated API explorer

This commit is contained in:
Pigway
2026-10-02 09:27:44 +08:00
parent e67b4ceb6e
commit d10b07c464
8 changed files with 83 additions and 10 deletions
+19 -1
View File
@@ -891,7 +891,7 @@ def create_app(settings=None, start_worker=True):
@app.get("/docs", include_in_schema=False)
def api_docs():
return get_swagger_ui_html(
response = get_swagger_ui_html(
openapi_url="/openapi.json",
title="Pigway Frame Flow · API Docs",
swagger_js_url="/ui/swagger-ui-bundle.js",
@@ -902,6 +902,24 @@ def create_app(settings=None, start_worker=True):
"displayRequestDuration": True,
},
)
html = (
bytes(response.body)
.decode()
.replace(
"SwaggerUIBundle({",
"""SwaggerUIBundle({
requestInterceptor: async (req) => {
if (!['GET','HEAD'].includes(req.method.toUpperCase())) {
const session = await fetch('/api/v1/auth/me');
if (session.ok) req.headers['X-CSRF-Token'] = (await session.json()).csrf_token;
}
return req;
},""",
)
)
from fastapi.responses import HTMLResponse
return HTMLResponse(html)
root = Path(__file__).resolve().parent.parent / "web"