-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
24 lines (21 loc) · 817 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const express = require("express");
const app = express();
require("dotenv/config");
const { convert } = require("subtitle-converter");
const axios = require("axios").default;
const cors = require("cors");
app.use(cors({ origin: true }));
app.get("/", async (req, res) => {
try {
if (!req.query.url) return res.send("SRT to VTT Proxy. Params url is required");
const response = await axios.get(encodeURI(req.query.url));
const { subtitle } = convert(response.data, ".vtt");
if (!subtitle) return res.status(400).send("Cannot convert");
res.setHeader("content-type", "text/vtt");
res.send(subtitle);
} catch (error) {
if (!res.headerSent) res.sendStatus(500);
}
});
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server is listening on port ${port}`));