Add paginated library JSON and dedicated still thumbs that never stream archive masters.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,13 +7,26 @@ export default defineEventHandler(async (event) => {
|
||||
const still = getStill(owner, id)
|
||||
assertFolderAccess(event, still.folderId)
|
||||
const wantThumb = String(getQuery(event).thumb || '') === '1'
|
||||
const path = wantThumb ? await stillThumbPath(owner, id) : stillPath(owner, still.id)
|
||||
if (!path || !existsSync(path)) {
|
||||
const original = stillPath(owner, still.id)
|
||||
|
||||
let path = original
|
||||
if (wantThumb) {
|
||||
path = await stillThumbPath(owner, id)
|
||||
// Never fall back to the archive PNG/JPEG for ?thumb=1
|
||||
if (!path || path === original || !existsSync(path)) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Thumbnail not found' })
|
||||
}
|
||||
} else if (!existsSync(path)) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Image file is missing' })
|
||||
}
|
||||
|
||||
const etag = fileEtag(path)
|
||||
setHeader(event, 'ETag', etag)
|
||||
setHeader(event, 'Cache-Control', wantThumb ? 'private, max-age=86400, stale-while-revalidate=604800' : 'private, max-age=3600')
|
||||
setHeader(
|
||||
event,
|
||||
'Cache-Control',
|
||||
wantThumb ? 'public, max-age=86400' : 'private, max-age=3600'
|
||||
)
|
||||
if (getHeader(event, 'if-none-match') === etag) {
|
||||
setResponseStatus(event, 304)
|
||||
return null
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { existsSync, createReadStream } from 'node:fs'
|
||||
import { fileEtag, stillPath, stillThumbPath } from '~/server/utils/library'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
const id = String(getRouterParam(event, 'id') || '')
|
||||
const still = getStill(owner, id)
|
||||
assertFolderAccess(event, still.folderId)
|
||||
|
||||
const path = await stillThumbPath(owner, id)
|
||||
const original = stillPath(owner, still.id)
|
||||
// Never stream the archive master as a "thumb"
|
||||
if (!path || !existsSync(path) || path === original) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Thumbnail not found' })
|
||||
}
|
||||
|
||||
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))
|
||||
})
|
||||
Reference in New Issue
Block a user