- Archive card: fixed a cache bug, where wrong cover image was shown

This commit is contained in:
maziggy
2025-12-29 09:05:10 +01:00
parent ee704b4158
commit e97d697d90
6 changed files with 17 additions and 7 deletions
+11 -1
View File
@@ -860,7 +860,17 @@ async def get_thumbnail(archive_id: int, db: AsyncSession = Depends(get_db)):
if not thumb_path.exists():
raise HTTPException(404, "Thumbnail file not found")
return FileResponse(path=thumb_path, media_type="image/png")
# Use file modification time as ETag to bust cache
mtime = int(thumb_path.stat().st_mtime)
return FileResponse(
path=thumb_path,
media_type="image/png",
headers={
"Cache-Control": "no-cache, must-revalidate",
"ETag": f'"{mtime}"',
},
)
@router.get("/{archive_id}/timelapse")
+1 -1
View File
@@ -1426,7 +1426,7 @@ export const api = {
request<{ updated: number; errors: Array<{ id: number; error: string }> }>('/archives/backfill-hashes', {
method: 'POST',
}),
getArchiveThumbnail: (id: number) => `${API_BASE}/archives/${id}/thumbnail`,
getArchiveThumbnail: (id: number) => `${API_BASE}/archives/${id}/thumbnail?v=${Date.now()}`,
getArchiveDownload: (id: number) => `${API_BASE}/archives/${id}/download`,
getArchiveGcode: (id: number) => `${API_BASE}/archives/${id}/gcode`,
getArchiveTimelapse: (id: number) => `${API_BASE}/archives/${id}/timelapse?v=${Date.now()}`,
+1 -1
View File
@@ -124,7 +124,7 @@ function ArchiveGrid({ archives }: { archives: Archive[] }) {
>
{archive.thumbnail_path ? (
<img
src={`/api/v1/archives/${archive.id}/thumbnail`}
src={api.getArchiveThumbnail(archive.id)}
alt={archive.print_name || 'Print'}
className="w-full h-full object-cover"
/>
+1 -1
View File
@@ -416,7 +416,7 @@ function ProjectCard({ project, onClick, onEdit, onDelete }: ProjectCardProps) {
>
{archive.thumbnail_path ? (
<img
src={`/api/v1/archives/${archive.id}/thumbnail`}
src={api.getArchiveThumbnail(archive.id)}
alt={archive.print_name || ''}
className="w-full h-full object-cover"
/>
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -23,7 +23,7 @@
<!-- Splash screens for iOS -->
<link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
<script type="module" crossorigin src="/assets/index-BGnYjiV-.js"></script>
<script type="module" crossorigin src="/assets/index-Bh0qWzko.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CiDcmh7W.css">
</head>
<body>