Let a finished player continue into a new MiniMax segment, then losslessly concat the parts and discard the intermediate files so the library keeps one extended MP4. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
975 B
TypeScript
26 lines
975 B
TypeScript
import { existsSync, readFileSync } from 'node:fs'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { owner } = assertLibraryOwner(event)
|
|
const id = String(getRouterParam(event, 'id') || '')
|
|
const clip = getClip(owner, id)
|
|
assertFolderAccess(event, clip.folderId)
|
|
const videoPath = clipVideoPath(owner, clip.id)
|
|
if (!existsSync(videoPath)) {
|
|
throw createError({ statusCode: 404, statusMessage: 'Video file is missing' })
|
|
}
|
|
const framePath = clipLastFramePath(owner, clip.id)
|
|
if (!existsSync(framePath)) {
|
|
try {
|
|
await extractLastFrame(videoPath, framePath)
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
throw createError({ statusCode: 500, statusMessage: `Could not extract the last frame: ${message}` })
|
|
}
|
|
}
|
|
const buf = readFileSync(framePath)
|
|
setHeader(event, 'Content-Type', 'image/png')
|
|
setHeader(event, 'Cache-Control', 'private, no-store')
|
|
return buf
|
|
})
|