From 62891f57fe66258c01039348d621b697b781a3f9 Mon Sep 17 00:00:00 2001 From: gilesb Date: Wed, 7 Jan 2026 14:23:42 +0000 Subject: [PATCH] feat: add cache view page with media display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /ui/cache/{hash} shows image/video inline - File details: hash, type, size - Download button - All cache links now go to view page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- server.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/server.py b/server.py index c1d38bb..e1209fd 100644 --- a/server.py +++ b/server.py @@ -299,6 +299,91 @@ async def get_cached(content_hash: str): return FileResponse(cache_path) +@app.get("/ui/cache/{content_hash}", response_class=HTMLResponse) +async def ui_cache_view(content_hash: str): + """View cached content with appropriate display.""" + cache_path = CACHE_DIR / content_hash + + if not cache_path.exists(): + return HTMLResponse(f""" + + +Not Found | Art DAG L1 + +

Art DAG L1 Server

+ ← Back to runs +

Content not found: {content_hash}

+ + +""", status_code=404) + + media_type = detect_media_type(cache_path) + file_size = cache_path.stat().st_size + size_str = f"{file_size:,} bytes" + if file_size > 1024*1024: + size_str = f"{file_size/(1024*1024):.1f} MB" + elif file_size > 1024: + size_str = f"{file_size/1024:.1f} KB" + + html = f""" + + + + {content_hash[:16]}... | Art DAG L1 + + + +

Art DAG L1 Server

+ ← Back to runs + +
+
+
+ {media_type.capitalize()} + {content_hash[:32]}... +
+ Download +
+ +
+""" + + if media_type == "video": + html += f'' + elif media_type == "image": + html += f'{content_hash}' + else: + html += f'

Unknown file type. Download file

' + + html += f""" +
+ +
+

Details

+
+
Content Hash (SHA3-256)
+
{content_hash}
+
+
+
Type
+
{media_type}
+
+
+
Size
+
{size_str}
+
+
+
Raw URL
+ +
+
+
+ + +""" + return html + + @app.get("/cache") async def list_cache(): """List cached content hashes.""" @@ -600,7 +685,7 @@ async def ui_detail_page(run_id: str): input_media_type = detect_media_type(CACHE_DIR / input_hash) html += f'''
- +
''' if input_media_type == "video": @@ -614,7 +699,7 @@ async def ui_detail_page(run_id: str): output_media_type = detect_media_type(CACHE_DIR / output_hash) html += f'''
- +
''' if output_media_type == "video": @@ -638,7 +723,7 @@ async def ui_detail_page(run_id: str):
''' for inp in run.inputs: - html += f'{inp}
' + html += f'{inp}
' html += f'''
@@ -648,7 +733,7 @@ async def ui_detail_page(run_id: str): html += f''' ''' @@ -739,7 +824,7 @@ async def ui_run_partial(run_id: str): if has_input: input_hash = run.inputs[0] input_media_type = detect_media_type(CACHE_DIR / input_hash) - html += f'
' + html += f'
' if input_media_type == "video": html += f'' elif input_media_type == "image": @@ -749,7 +834,7 @@ async def ui_run_partial(run_id: str): if has_output: output_hash = run.output_hash output_media_type = detect_media_type(CACHE_DIR / output_hash) - html += f'
' + html += f'
' if output_media_type == "video": html += f'' elif output_media_type == "image":