Serve the stage from a 1600px preview instead of the grid thumb.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { existsSync, createReadStream } from 'node:fs'
|
||||
import { fileEtag, stillPath, stillPreviewPath, existingStillPreviewPath } from '~/server/utils/library'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
const id = String(getRouterParam(event, 'id') || '')
|
||||
const still = getStill(owner, id)
|
||||
assertFolderAccess(event, still.folderId)
|
||||
|
||||
const path = existingStillPreviewPath(owner, id)
|
||||
const original = stillPath(owner, still.id)
|
||||
// Ready preview → stream. Never await ffmpeg; never stream the archive master.
|
||||
if (path && existsSync(path) && path !== original) {
|
||||
const etag = fileEtag(path)
|
||||
setHeader(event, 'ETag', etag)
|
||||
setHeader(event, 'Cache-Control', 'public, max-age=86400')
|
||||
if (getHeader(event, 'if-none-match') === etag) {
|
||||
setResponseStatus(event, 304)
|
||||
return null
|
||||
}
|
||||
setHeader(event, 'Content-Type', 'image/jpeg')
|
||||
return sendStream(event, createReadStream(path))
|
||||
}
|
||||
|
||||
// Missing → answer now; build .preview.jpg in the background
|
||||
void stillPreviewPath(owner, id).catch(() => null)
|
||||
setHeader(event, 'Cache-Control', 'no-store')
|
||||
setResponseStatus(event, 204)
|
||||
return null
|
||||
})
|
||||
Reference in New Issue
Block a user