Test
This commit is contained in:
commit
a1ff9758b4
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
temp/
|
||||||
13
Dockerfile
Normal file
13
Dockerfile
Normal 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
0
compose.yaml
Normal file
19
ffmpegQueuePipe.sh
Normal file
19
ffmpegQueuePipe.sh
Normal 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
28
package.json
Normal 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
1108
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
src/index.ts
Normal file
43
src/index.ts
Normal 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
9
tsdown.config.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { defineConfig } from 'tsdown'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
entry: ['./src/index.ts'],
|
||||||
|
platform: 'neutral',
|
||||||
|
dts: {
|
||||||
|
isolatedDeclarations: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user