Fix /page/{uri_hash} to render directly instead of redirecting

This commit is contained in:
Russell Ballestrini 2026-01-06 17:26:58 -05:00
parent d91c0592ca
commit c6bf3c375e

View file

@ -470,27 +470,8 @@ async def view_media_page(request: Request, md5_hash: str, noai: bool = Query(Fa
@app.get("/page/{uri_hash}")
async def view_page_by_hash(uri_hash: str, noai: bool = Query(False, description="Disable AI assistant")):
"""View an archived page by URI hash - redirects to /page/view."""
page = await db.get_page_by_hash(uri_hash)
if not page:
raise HTTPException(status_code=404, detail="Page not found")
# Redirect to the URI-based view (language handled by Depends in view_page)
from urllib.parse import quote
redirect_url = f"/page/view?uri={quote(page['uri'], safe='')}"
if noai:
redirect_url += "&noai=true"
return RedirectResponse(url=redirect_url, status_code=302)
@app.get("/page/view", response_class=HTMLResponse)
async def view_page(request: Request,
uri: str = Query(..., description="Page URI to view"),
noai: bool = Query(False, description="Disable AI assistant"),
language: str = Depends(get_language),
):
"""View an archived page with markdown and screenshot. Use ?lang=XX to force language."""
async def _render_page(request: Request, uri: str, noai: bool, language: str):
"""Internal: render a page view (shared by hash and URI routes)."""
import html as html_module
import re
from urllib.parse import urljoin, quote
@ -611,6 +592,23 @@ async def view_page(request: Request,
"langs": LANG_NAMES,
"import_mode": IMPORT_MODE,
})
@app.get("/page/{uri_hash}", response_class=HTMLResponse)
async def view_page_by_hash(request: Request, uri_hash: str, noai: bool = Query(False), language: str = Depends(get_language)):
"""View an archived page by URI hash."""
page = await db.get_page_by_hash(uri_hash)
if not page:
raise HTTPException(status_code=404, detail="Page not found")
return await _render_page(request, page['uri'], noai, language)
@app.get("/page/view", response_class=HTMLResponse)
async def view_page(request: Request, uri: str = Query(...), noai: bool = Query(False), language: str = Depends(get_language)):
"""View an archived page by URI. Use ?lang=XX to force language."""
return await _render_page(request, uri, noai, language)
@app.get("/phantom/export")
async def phantom_export(domain: str = Query(None, description="Filter by domain")):
"""