-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
30 lines (23 loc) · 841 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import { exec } from "https://deno.land/x/exec/mod.ts";
const app = new Application();
const router = new Router();
router.get("/convert", async (context) => {
const { request, response } = context;
const url = request.url.searchParams.get("url");
console.log(url);
const tempFileName = `temp_${Date.now()}.mp4`;
const cmd = `ffmpeg -i ${url} -c copy ${tempFileName}`;
await exec(cmd);
const mp4Buffer = await Deno.readFile(tempFileName);
response.headers.set("Content-Type", "video/mp4");
response.headers.set(
"Content-Disposition",
'attachment; filename="video.mp4"',
);
response.body = mp4Buffer;
await Deno.remove(tempFileName);
});
app.use(router.routes());
app.use(router.allowedMethods());
await app.listen({ port: 3000 });