Files
processing/index.js
2025-07-09 01:30:18 -04:00

29 lines
1014 B
JavaScript

import { $ } from "bun";
import 'dotenv/config'
Bun.serve({
port: 6001,
routes: {
"/status": new Response("OK"),
"/process": {
POST: async req => {
if(req.headers.get("X-Authentication") == process.env.PRIVATE_KEY) {
let path = "tmp/" + Bun.randomUUIDv7();
await Bun.write(path + ".mp4", await req.body.blob());
await $`ffmpeg -i ${path}.mp4 -map_metadata -1 -map 0 -map -0:v -b:a 64k ${path}.ogg`
await (Bun.file(path + ".mp4")).delete();
let response = new Response(await Bun.file(path + ".ogg").bytes(), {
headers: {
"Content-Type": "application/ogg",
},
});
await (Bun.file(path + ".ogg")).delete();
return response;
} else {
return new Response("Not Authenticated", { status: 401 });
}
}
}
}
});
console.log("http://localhost:6001")