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'''
curl -X POST /runs \\
-H "Content-Type: application/json" \\
- -d '{"recipe": "dog", "inputs": ["33268b6e..."]}'
+ -d '{{"recipe": "dog", "inputs": ["33268b6e..."]}}'
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'''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)