From bb873bff2f991809c2a54a16a9eebc306972dfa9 Mon Sep 17 00:00:00 2001 From: Jared Furlow Date: Tue, 17 Jun 2025 23:52:05 -0500 Subject: [PATCH] dist --- .gitignore | 1 - dist/index.d.ts | 1 + dist/index.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 dist/index.d.ts create mode 100644 dist/index.js diff --git a/.gitignore b/.gitignore index 382707c..206ba3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules -dist temp/ diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..619fbdd --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1 @@ +export { }; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..265c0a2 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,36 @@ +import Express from "express"; +import busboy from "connect-busboy"; +import path from "path"; +import fs from "fs"; + +//#region src/index.ts +const app = Express(); +app.use(busboy()); +app.use(Express.json()); +app.post("/uploadVideo", async (req, res) => { + try { + console.log("Starting upload"); + const videoId = req.query.videoId; + req.busboy.on("file", (fieldname, uploadingFile, fileInfo) => { + console.log(`Saving ${fileInfo.filename} as ${videoId}`); + const videoExt = fileInfo.filename.split(".").at(-1); + var targetPath = path.join("./temp/", `${videoId}.${videoExt}`); + const fileStream = fs.createWriteStream(targetPath); + uploadingFile.pipe(fileStream); + fileStream.on("close", () => { + console.log(`Completed upload ${fileInfo.filename}`); + const ffmpegCommand = `ffmpeg -i "${targetPath}" -c:v libx264 -crf 23 -preset medium -movflags +faststart -c:a aac -b:a 128k /opt/prod/storage/uploadsPart2/${videoId}-formatted.mp4`; + const wstream = fs.createWriteStream("/opt/prod/pipe/ffmpeg"); + wstream.write(`${ffmpegCommand}\n`); + wstream.write(`rm -f "${targetPath}"\n`); + res.send({ statusMessage: "Upload part 1 complete" }); + }); + }); + req.pipe(req.busboy); + } catch (err) { + res.status(500).send(err); + } +}); +app.listen(3001); + +//#endregion \ No newline at end of file