Preview cache-busting: Cache-Control: no-cache na endpoint + ?v=Date.now() v frontend URL — browser ne sme cachat starega output-a po recutu

This commit is contained in:
OpenClaw Agent 2026-05-02 12:24:19 +00:00
parent c1e00b7b73
commit 7a7d7ea20d
2 changed files with 10 additions and 3 deletions

View File

@ -1521,6 +1521,7 @@ async def preview(job_id: str, request: Request, user: str = Depends(check_auth)
"Accept-Ranges": "bytes", "Accept-Ranges": "bytes",
"Content-Length": str(chunk_size), "Content-Length": str(chunk_size),
"Content-Type": "video/mp4", "Content-Type": "video/mp4",
"Cache-Control": "no-cache, must-revalidate", # browser ne sme cachat starega output-a
} }
return StreamingResponse(iter_file(), status_code=206, headers=headers, return StreamingResponse(iter_file(), status_code=206, headers=headers,
media_type="video/mp4") media_type="video/mp4")
@ -1531,7 +1532,11 @@ async def preview(job_id: str, request: Request, user: str = Depends(check_auth)
return FileResponse( return FileResponse(
out, out,
media_type="video/mp4", media_type="video/mp4",
headers={"Accept-Ranges": "bytes", "Content-Length": str(file_size)}, headers={
"Accept-Ranges": "bytes",
"Content-Length": str(file_size),
"Cache-Control": "no-cache, must-revalidate", # browser ne sme cachat starega output-a
},
) )

View File

@ -1773,15 +1773,17 @@
function previewJob(id, title) { function previewJob(id, title) {
// Odpre velik modal z reel videom // Odpre velik modal z reel videom
// Dodaj timestamp cache-buster da browser ne servira starega cached output-a
const cacheBust = Date.now();
const overlay = document.createElement("div"); const overlay = document.createElement("div");
overlay.className = "modal-overlay"; overlay.className = "modal-overlay";
overlay.innerHTML = ` overlay.innerHTML = `
<div class="modal-content" onclick="event.stopPropagation()"> <div class="modal-content" onclick="event.stopPropagation()">
<button class="modal-close" title="Zapri (ESC)">×</button> <button class="modal-close" title="Zapri (ESC)">×</button>
<video src="/api/preview/${id}" controls autoplay playsinline></video> <video src="/api/preview/${id}?v=${cacheBust}" controls autoplay playsinline></video>
${title ? `<div class="modal-title">${title}</div>` : ""} ${title ? `<div class="modal-title">${title}</div>` : ""}
<div class="modal-actions"> <div class="modal-actions">
<button class="primary" onclick="window.open('/api/download/${id}')">⬇ Prenesi reel</button> <button class="primary" onclick="window.open('/api/download/${id}?v=${cacheBust}')">⬇ Prenesi reel</button>
<button onclick="closeModal()">Zapri</button> <button onclick="closeModal()">Zapri</button>
</div> </div>
</div> </div>