Extract a poster frame when a still-thumb is missing, and show the clip name in the library with the prompt on the info icon. Co-authored-by: Cursor <cursoragent@cursor.com>
17 lines
681 B
TypeScript
17 lines
681 B
TypeScript
import { existsSync, readFileSync } from 'node:fs'
|
|
|
|
export default defineEventHandler((event) => {
|
|
const { owner } = assertLibraryOwner(event)
|
|
const id = String(getRouterParam(event, 'id') || '')
|
|
const clip = getClip(owner, id)
|
|
assertFolderAccess(event, clip.folderId)
|
|
const path = clipVideoPath(owner, clip.id)
|
|
if (!existsSync(path)) {
|
|
throw createError({ statusCode: 404, statusMessage: 'Video file is missing' })
|
|
}
|
|
setHeader(event, 'Content-Type', 'video/mp4')
|
|
setHeader(event, 'Content-Disposition', `inline; filename="${safeDownloadName(clipTitle(clip))}.mp4"`)
|
|
setHeader(event, 'Cache-Control', 'private, max-age=3600')
|
|
return readFileSync(path)
|
|
})
|