This commit is contained in:
Jared Furlow 2025-06-17 23:42:44 -05:00
commit a1ff9758b4
8 changed files with 1223 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
dist
temp/

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM node:23.6-bullseye-slim
RUN apt-get update && apt-get install curl ffmpeg -y
WORKDIR /opt/prod/app
COPY . .
RUN mkdir -p /opt/prod/pipe/
RUN mkdir -p /opt/prod/storage/uploadsPart1
RUN mkdir -p /opt/prod/storage/uploadsPart2
RUN npm install
CMD [ "node", "dist/index.js" ]

0
compose.yaml Normal file
View File

19
ffmpegQueuePipe.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
pipe=/opt/prod/pipe/ffmpeg
trap "rm -f $pipe" EXIT
# creating the FIFO
[[ -p $pipe ]] || mkfifo $pipe
while true; do
# can't just use "while read line" if we
# want this script to continue running.
read line <$pipe
# now implementing a bit of security,
# feel free to improve it.
# we ensure that the command is a ffmpeg one.
bash <<<"$line"
done

28
package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "tsdown-starter",
"version": "0.0.0",
"private": true,
"description": "A simple example library built by tsdown",
"type": "module",
"files": [
"dist"
],
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
},
"scripts": {
"build": "tsdown",
"dev": "tsdown --watch"
},
"devDependencies": {
"tsdown": "latest"
},
"dependencies": {
"connect-busboy": "^1.0.0",
"express": "^5.1.0"
}
}

1108
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

43
src/index.ts Normal file
View File

@ -0,0 +1,43 @@
import Express from "express";
import busboy from "connect-busboy";
import path from "path";
import fs from "fs";
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/", //"/opt/prod/storage/uploadsPart1"
`${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);

9
tsdown.config.ts Normal file
View File

@ -0,0 +1,9 @@
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
platform: 'neutral',
dts: {
isolatedDeclarations: true,
},
})