diff --git a/server.py b/server.py index f186088..4ac2bf2 100644 --- a/server.py +++ b/server.py @@ -1991,8 +1991,8 @@ async def get_cached(content_hash: str, request: Request): return HTMLResponse(render_page("Not Found", content, ctx.actor_id if ctx else None, active_tab="media"), status_code=404) raise HTTPException(404, f"Content {content_hash} not in cache") - # JSON response for API clients - if "application/json" in accept: + # JSON response only if explicitly requested + if "application/json" in accept and "text/html" not in accept: t0 = time.time() meta = await database.load_item_metadata(content_hash, ctx.actor_id if ctx else None) logger.debug(f"get_cached: load_item_metadata took {time.time()-t0:.3f}s") @@ -2018,8 +2018,9 @@ async def get_cached(content_hash: str, request: Request): "meta": meta } - # HTML response for browsers - show detail page - if wants_html(request): + # HTML response for browsers (default for all non-JSON requests) + # Raw data is only served from /cache/{hash}/raw endpoint + if True: # Always show HTML page, raw data via /raw endpoint if not ctx: content = '
Login via L2 to view cached content.
' return HTMLResponse(render_page("Login Required", content, None, active_tab="media"), status_code=401) @@ -2157,9 +2158,6 @@ async def get_cached(content_hash: str, request: Request): return HTMLResponse(render_page(f"Cache: {content_hash[:16]}...", content, ctx.actor_id, active_tab="media")) - # Default: return raw file - return FileResponse(cache_path) - @app.get("/cache/{content_hash}/raw") async def get_cached_raw(content_hash: str):