ソースを参照

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

maziggy 5 ヶ月 前
コミット
e97d697d90

+ 11 - 1
backend/app/api/routes/archives.py

@@ -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
frontend/src/api/client.ts

@@ -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
frontend/src/pages/ProjectDetailPage.tsx

@@ -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
frontend/src/pages/ProjectsPage.tsx

@@ -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"
                     />

ファイルの差分が大きいため隠しています
+ 0 - 0
static/assets/index-Bh0qWzko.js


+ 1 - 1
static/index.html

@@ -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>

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません