Files
aigen/server/api/library/clips/[id]/video.get.ts
T

22 lines
880 B
TypeScript

import { existsSync } from 'node:fs'
import { sendPathWithRange } from '~/server/utils/httpRange'
import { setLibraryMediaHeaders } from '~/server/utils/library'
import { inlineFilename } from '~/shared/content-disposition.mjs'
export default defineEventHandler((event) => {
setLibraryMediaHeaders(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' })
}
return sendPathWithRange(event, path, 'video/mp4', {
'Content-Disposition': inlineFilename(`${safeDownloadName(clipTitle(clip))}.mp4`),
'Cache-Control': 'no-store, no-cache, must-revalidate',
'Pragma': 'no-cache'
})
})