import fs from "fs"
import path from "path"
function getFileNameFromPath(path: string) {
let splitStr = path.split("/");
let filename = splitStr[splitStr.length - 1];
return filename
}
export default defineEventHandler(async (event) => {
const { slug } = getRouterParams(event)
const fileName = getFileNameFromPath(slug)
const file_name = path.join(process.cwd(), "/uploads", fileName)
const pathVideo = path.resolve(file_name)
const stat = fs.statSync(pathVideo)
const fileSize = stat.size
if (fs.existsSync(file_name)) {
const head = {
'Content-Length': fileSize.toString(),
'Content-Type': 'video/mp4',
};
appendResponseHeaders(event, head);
return fs.createReadStream(pathVideo)
}
})