Test
This commit is contained in:
parent
d6762d51c1
commit
345d84c461
@ -8,12 +8,7 @@ trap "rm -f $pipe" EXIT
|
|||||||
[[ -p $pipe ]] || mkfifo $pipe
|
[[ -p $pipe ]] || mkfifo $pipe
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
# can't just use "while read line" if we
|
|
||||||
# want this script to continue running.
|
|
||||||
read line <$pipe
|
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"
|
bash <<<"$line"
|
||||||
done
|
done
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
"tsdown": "latest"
|
"tsdown": "latest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/node": "^24.0.15",
|
||||||
"connect-busboy": "^1.0.0",
|
"connect-busboy": "^1.0.0",
|
||||||
"express": "^5.1.0"
|
"express": "^5.1.0"
|
||||||
}
|
}
|
||||||
|
|||||||
15
pnpm-lock.yaml
generated
15
pnpm-lock.yaml
generated
@ -8,6 +8,9 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@types/node':
|
||||||
|
specifier: ^24.0.15
|
||||||
|
version: 24.0.15
|
||||||
connect-busboy:
|
connect-busboy:
|
||||||
specifier: ^1.0.0
|
specifier: ^1.0.0
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
@ -149,6 +152,9 @@ packages:
|
|||||||
'@tybys/wasm-util@0.9.0':
|
'@tybys/wasm-util@0.9.0':
|
||||||
resolution: {integrity: sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==}
|
resolution: {integrity: sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==}
|
||||||
|
|
||||||
|
'@types/node@24.0.15':
|
||||||
|
resolution: {integrity: sha512-oaeTSbCef7U/z7rDeJA138xpG3NuKc64/rZ2qmUFkFJmnMsAPaluIifqyWd8hSSMxyP9oie3dLAqYPblag9KgA==}
|
||||||
|
|
||||||
accepts@2.0.0:
|
accepts@2.0.0:
|
||||||
resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==}
|
resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
@ -551,6 +557,9 @@ packages:
|
|||||||
unconfig@7.3.2:
|
unconfig@7.3.2:
|
||||||
resolution: {integrity: sha512-nqG5NNL2wFVGZ0NA/aCFw0oJ2pxSf1lwg4Z5ill8wd7K4KX/rQbHlwbh+bjctXL5Ly1xtzHenHGOK0b+lG6JVg==}
|
resolution: {integrity: sha512-nqG5NNL2wFVGZ0NA/aCFw0oJ2pxSf1lwg4Z5ill8wd7K4KX/rQbHlwbh+bjctXL5Ly1xtzHenHGOK0b+lG6JVg==}
|
||||||
|
|
||||||
|
undici-types@7.8.0:
|
||||||
|
resolution: {integrity: sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==}
|
||||||
|
|
||||||
unpipe@1.0.0:
|
unpipe@1.0.0:
|
||||||
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
|
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
|
||||||
engines: {node: '>= 0.8'}
|
engines: {node: '>= 0.8'}
|
||||||
@ -678,6 +687,10 @@ snapshots:
|
|||||||
tslib: 2.8.1
|
tslib: 2.8.1
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
'@types/node@24.0.15':
|
||||||
|
dependencies:
|
||||||
|
undici-types: 7.8.0
|
||||||
|
|
||||||
accepts@2.0.0:
|
accepts@2.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
mime-types: 3.0.1
|
mime-types: 3.0.1
|
||||||
@ -1101,6 +1114,8 @@ snapshots:
|
|||||||
jiti: 2.4.2
|
jiti: 2.4.2
|
||||||
quansync: 0.2.10
|
quansync: 0.2.10
|
||||||
|
|
||||||
|
undici-types@7.8.0: {}
|
||||||
|
|
||||||
unpipe@1.0.0: {}
|
unpipe@1.0.0: {}
|
||||||
|
|
||||||
vary@1.1.2: {}
|
vary@1.1.2: {}
|
||||||
|
|||||||
37
src/index.ts
37
src/index.ts
@ -1,12 +1,17 @@
|
|||||||
import Express from "express";
|
import Express from "express";
|
||||||
import busboy from "connect-busboy";
|
import busboy from "connect-busboy";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "node:fs";
|
||||||
|
import { exec } from "node:child_process";
|
||||||
|
import util from "node:util";
|
||||||
|
const execPromise = util.promisify(exec);
|
||||||
|
|
||||||
|
let currentlyExecFfmpeg = false;
|
||||||
|
|
||||||
const app = Express();
|
const app = Express();
|
||||||
app.use(busboy());
|
app.use(busboy());
|
||||||
app.use(Express.json());
|
app.use(Express.json());
|
||||||
|
//https://coomer.su/posts
|
||||||
app.post("/uploadVideo", async (req, res) => {
|
app.post("/uploadVideo", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
console.log("Starting upload");
|
console.log("Starting upload");
|
||||||
@ -14,6 +19,14 @@ app.post("/uploadVideo", async (req, res) => {
|
|||||||
const videoId = req.query.videoId;
|
const videoId = req.query.videoId;
|
||||||
|
|
||||||
req.busboy.on("file", (fieldname, uploadingFile, fileInfo) => {
|
req.busboy.on("file", (fieldname, uploadingFile, fileInfo) => {
|
||||||
|
if (currentlyExecFfmpeg) {
|
||||||
|
res.send({
|
||||||
|
status: "wait",
|
||||||
|
statusMessage:
|
||||||
|
"FFmpeg is currently processing another file. Please wait.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Saving ${fileInfo.filename} as ${videoId}`);
|
console.log(`Saving ${fileInfo.filename} as ${videoId}`);
|
||||||
|
|
||||||
const videoExt = fileInfo.filename.split(".").at(-1);
|
const videoExt = fileInfo.filename.split(".").at(-1);
|
||||||
@ -28,11 +41,23 @@ app.post("/uploadVideo", async (req, res) => {
|
|||||||
fileStream.on("close", () => {
|
fileStream.on("close", () => {
|
||||||
console.log(`Completed upload ${fileInfo.filename}`);
|
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 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");
|
currentlyExecFfmpeg = true;
|
||||||
wstream.write(`${ffmpegCommand}\n`);
|
|
||||||
wstream.write(`rm -f "${targetPath}"\n`);
|
|
||||||
|
|
||||||
res.send({ statusMessage: "Upload part 1 complete" });
|
execPromise(ffmpegCommand)
|
||||||
|
.then(({ stdout, stderr }) => {
|
||||||
|
if (stderr && stderr.length > 0) {
|
||||||
|
console.log("FFmpeg stderr:", stderr);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("FFmpeg caught error:", error);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
fs.unlinkSync(targetPath);
|
||||||
|
currentlyExecFfmpeg = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send({ status: "good", statusMessage: "Upload part 1 complete" });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
req.pipe(req.busboy);
|
req.pipe(req.busboy);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user