dist
This commit is contained in:
parent
21c6ee0acd
commit
bb873bff2f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
|
||||||
temp/
|
temp/
|
||||||
|
|||||||
1
dist/index.d.ts
vendored
Normal file
1
dist/index.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { };
|
||||||
36
dist/index.js
vendored
Normal file
36
dist/index.js
vendored
Normal file
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user