From 591c0aad4c22ec6cb36a6b04620fabcaa30edc82 Mon Sep 17 00:00:00 2001 From: gilesb Date: Thu, 8 Jan 2026 17:51:09 +0000 Subject: [PATCH] Show logged-in user on home page instead of login button Convert static HOME_HTML to render_home_html() function that dynamically shows user info with link to L2 profile when authenticated, or login button when not logged in. Co-Authored-By: Claude Opus 4.5 --- server.py | 76 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/server.py b/server.py index 065b157..fb10313 100644 --- a/server.py +++ b/server.py @@ -419,7 +419,21 @@ async def api_info(): } -HOME_HTML = """ +def render_home_html(actor_id: Optional[str] = None) -> str: + """Render the home page HTML with optional user info.""" + if actor_id: + # Extract username and domain from @username@domain format + parts = actor_id.lstrip("@").split("@") + username = parts[0] if parts else actor_id + domain = parts[1] if len(parts) > 1 else "" + l2_user_url = f"https://{domain}/users/{username}" if domain else "#" + user_section = f'''
+ Logged in as {actor_id} +
''' + else: + user_section = '''Login via L2''' + + return f""" @@ -428,10 +442,10 @@ HOME_HTML = """ Art DAG L1 Server @@ -441,7 +455,7 @@ HOME_HTML = """ Recipes Media API Docs - Login + {user_section}

Art DAG L1 Server

@@ -481,16 +495,16 @@ HOME_HTML = """

Start a Run

curl -X POST /runs \\
   -H "Content-Type: application/json" \\
-  -d '{"recipe": "dog", "inputs": ["33268b6e..."]}'
+ -d '{{"recipe": "dog", "inputs": ["33268b6e..."]}}'

Provenance

Every render produces a provenance record linking inputs, effects, and infrastructure:

-
{
-  "output": {"content_hash": "..."},
+        
{{
+  "output": {{"content_hash": "..."}},
   "inputs": [...],
   "effects": [...],
-  "infrastructure": {...}
-}
+ "infrastructure": {{...}} +}}
@@ -498,9 +512,11 @@ HOME_HTML = """ @app.get("/", response_class=HTMLResponse) -async def root(): +async def root(request: Request): """Home page.""" - return HOME_HTML + ctx = get_user_context_from_cookie(request) + actor_id = ctx.actor_id if ctx else None + return render_home_html(actor_id) @app.post("/runs", response_model=RunStatus) @@ -729,7 +745,7 @@ async def run_detail(run_id: str, request: Request): if wants_html(request): ctx = get_user_context_from_cookie(request) if not ctx: - content = '

Login to view run details.

' + content = '

Login via L2 to view run details.

' return HTMLResponse(render_page("Login Required", content, None, active_tab="runs"), status_code=401) # Check user owns this run @@ -964,7 +980,7 @@ async def list_runs(request: Request, page: int = 1, limit: int = 20): if wants_html(request): if not ctx: - content = '

Login to see your runs.

' + content = '

Login via L2 to see your runs.

' return HTMLResponse(render_page("Runs", content, None, active_tab="runs")) if not runs_page: @@ -1147,7 +1163,7 @@ async def list_recipes_api(request: Request, page: int = 1, limit: int = 20): if not ctx: return HTMLResponse(render_page( "Recipes", - '

Login to see recipes.

', + '

Login via L2 to see recipes.

', None, active_tab="recipes" )) @@ -1520,7 +1536,7 @@ async def ui_recipes_list(request: Request): ctx = get_user_context_from_cookie(request) if not ctx: - return '

Login to see recipes.

' + return '

Login via L2 to see recipes.

' all_recipes = list_all_recipes() @@ -1681,7 +1697,7 @@ async def cache_detail(content_hash: str, request: Request): if wants_html(request): if not ctx: - content = '

Login to view cached content.

' + content = '

Login via L2 to view cached content.

' return HTMLResponse(render_page("Login Required", content, None, active_tab="media"), status_code=401) # Check user has access @@ -2190,7 +2206,7 @@ async def list_media( if wants_html(request): # Require login for HTML media view if not ctx: - content = '

Login to see media.

' + content = '

Login via L2 to see media.

' return HTMLResponse(render_page("Media", content, None, active_tab="media")) # Get hashes owned by/associated with this user @@ -3078,16 +3094,20 @@ def render_page(title: str, content: str, actor_id: Optional[str] = None, active """ user_info = "" if actor_id: + # Extract username and domain from @username@domain format + parts = actor_id.lstrip("@").split("@") + username = parts[0] if parts else actor_id + domain = parts[1] if len(parts) > 1 else "" + l2_user_url = f"https://{domain}/users/{username}" if domain else "#" user_info = f'''
- Logged in as {actor_id} - Logout + Logged in as {actor_id}
''' else: user_info = ''' ''' @@ -3135,16 +3155,20 @@ def render_ui_html(actor_id: Optional[str] = None, tab: str = "runs") -> str: """ user_info = "" if actor_id: + # Extract username and domain from @username@domain format + parts = actor_id.lstrip("@").split("@") + username = parts[0] if parts else actor_id + domain = parts[1] if len(parts) > 1 else "" + l2_user_url = f"https://{domain}/users/{username}" if domain else "#" user_info = f'''
- Logged in as {actor_id} - Logout + Logged in as {actor_id}
''' else: user_info = ''' ''' @@ -3327,7 +3351,7 @@ async def ui_runs(request: Request): # Require login to see runs if not ctx: - return '

Login to see your runs.

' + return '

Login via L2 to see your runs.

' # Filter runs by user - match both plain username and ActivityPub format (@user@domain) runs = [r for r in runs if r.username in (ctx.username, ctx.actor_id)] @@ -3426,7 +3450,7 @@ async def ui_media_list( # Require login to see media if not ctx: - return '

Login to see media.

' + return '

Login via L2 to see media.

' # Get hashes owned by/associated with this user user_hashes = await get_user_cache_hashes(ctx.username, ctx.actor_id)