Files
aigen/server/api/library/drafts/[id]/still.get.ts
T

21 lines
758 B
TypeScript

import { existsSync, readFileSync } from 'node:fs'
import { setLibraryMediaHeaders } from '~/server/utils/library'
export default defineEventHandler((event) => {
setLibraryMediaHeaders(event)
const { owner } = assertLibraryOwner(event)
const id = String(getRouterParam(event, 'id') || '')
const draft = getRetryDraft(owner, id)
if (!draft.stillId) {
throw createError({ statusCode: 404, statusMessage: 'Held job has no still' })
}
const still = getStill(owner, draft.stillId)
const path = stillPath(owner, still.id)
if (!existsSync(path)) {
throw createError({ statusCode: 404, statusMessage: 'Image file is missing' })
}
const buf = readFileSync(path)
setHeader(event, 'Content-Type', imageContentType(buf))
return buf
})