feat(phase4): permanent cache-control & asset versioning, canonical nabil stored_session_id & resume, dsh session persistence fix, dsh dialogue/files toggle, and collapsible conv sidebar

This commit is contained in:
bolbol
2026-08-20 23:51:08 +01:00
parent e40fe71f5c
commit 9c8f292d0f
6 changed files with 150 additions and 36 deletions
+20 -5
View File
@@ -1,10 +1,11 @@
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, Response
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from pathlib import Path
from typing import Optional, Tuple
from contextlib import asynccontextmanager
import time
from app.config import settings, UNIVERSES, BASE_DIR
from app.routers import api, proxy, chat
@@ -12,6 +13,8 @@ from app.proxy import close_http_client, proxy_request, proxy_websocket
from app.personas import ensure_dirs
from app.db import init_db
APP_VERSION = f"2.1.{int(time.time())}"
def get_subdomain_target(host: str) -> Optional[Tuple[str, str]]:
"""
Inspects Host header and returns (target_backend_url, universe_id) if it matches a universe hostname.
@@ -22,7 +25,7 @@ def get_subdomain_target(host: str) -> Optional[Tuple[str, str]]:
perso-hub.yesminedor.tn -> (HERMES_PERSO_URL, 'perso')
nabil-hub.yesminedor.tn -> (HERMES_NABIL_URL, 'nabil')
dsh-hub.yesminedor.tn -> (HERMES_DSH_URL, 'dsh')
files-hub.yesminedor.tn -> (DSH_FILEBROWSER_URL, 'nabil')
files-hub.yesminedor.tn -> (DSH_FILEBROWSER_URL, 'dsh')
Apex / Hub UI:
hub.yesminedor.tn -> None (Serves index.html Workspace Switcher)
@@ -54,7 +57,7 @@ def get_subdomain_target(host: str) -> Optional[Tuple[str, str]]:
return None
if sub in ("files", "dsh-files"):
return (settings.dsh_filebrowser_url, "nabil")
return (settings.dsh_filebrowser_url, "dsh")
if sub in UNIVERSES:
return (UNIVERSES[sub].backend_url, sub)
@@ -70,10 +73,21 @@ async def lifespan(app: FastAPI):
app = FastAPI(
title=settings.app_name,
version="1.0.0",
version="2.1.0",
lifespan=lifespan
)
# Cache-Control & Anti-Stale Middleware for Hub UI & Statics
@app.middleware("http")
async def cache_control_middleware(request: Request, call_next):
response: Response = await call_next(request)
path = request.url.path
if path.startswith("/static/") or path == "/" or path.endswith(".html"):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
return response
# Subdomain Routing Middleware for HTTP
@app.middleware("http")
async def subdomain_routing_middleware(request: Request, call_next):
@@ -112,7 +126,8 @@ async def index_view(request: Request):
name="index.html",
context={
"universes": UNIVERSES,
"app_name": settings.app_name
"app_name": settings.app_name,
"version": APP_VERSION
}
)