-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·113 lines (102 loc) · 4.34 KB
/
server.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env node
const express = require("express");
const { getRouter } = require("stremio-addon-sdk");
const addonBuilder = require("./addon");
const app = express();
const path = require("path");
const fs = require("fs");
const pkg = require("./package.json");
app.set("trust proxy", true);
app.use(express.urlencoded({ extended: true }));
app.use("/dist", express.static(path.join(__dirname, "dist")));
app.use("/icon", express.static(path.join(__dirname, "icon")));
app.get("/", (req, res) => {
res.redirect("/configure");
});
app.get("/configure", (req, res) => {
fs.readFile(path.join(__dirname, "configure.html"), "utf8", (err, data) => {
if (err) {
res.status(500).send("Error loading configure.html");
} else {
const currentYear = new Date().getFullYear();
const updatedData = data
.replace(/{{VERSION}}/g, pkg.version)
.replace(/{{CURRENT_YEAR}}/g, currentYear);
res.send(updatedData);
}
});
});
app.post("/install", (req, res) => {
const apiKey = req.body.apiKey;
const tmdbApiKey = req.body.tmdbApiKey;
const omdbApiKey = req.body.omdbApiKey;
if (!apiKey) {
return res.send("Real Debrid API Key is required.");
}
const config = { apiKey };
if (tmdbApiKey) {
config.tmdbApiKey = tmdbApiKey;
}
if (omdbApiKey) {
config.omdbApiKey = omdbApiKey;
}
const configEncoded = Buffer.from(JSON.stringify(config)).toString(
"base64"
);
const protocol = req.headers["x-forwarded-proto"] || req.protocol;
const host = req.headers["x-forwarded-host"] || req.get("host");
const addonUrl = `${protocol}://${host}/${configEncoded}/manifest.json`;
const addonInstallUrlNoProtocol = `${host}/${configEncoded}/manifest.json`;
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Install Real Debrid Addon</title>
<link href="/dist/main.css" rel="stylesheet" />
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
<div class="bg-white p-8 rounded shadow-md w-full max-w-md">
<h1 class="text-2xl font-bold mb-4">Install Real Debrid Addon</h1>
<p class="mb-4 font-medium">Click the link below to install the addon in Stremio:</p>
<a href="stremio://${addonInstallUrlNoProtocol}" class="rounded bg-indigo-600 px-2.5 py-1.5 text-lg font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Install Addon</a>
<p class="mt-4 font-medium">Or add the following URL in Stremio:</p>
<p class="bg-gray-100 p-3 rounded break-all overflow-wrap-anywhere overflow-x-auto my-2 font-mono text-sm">${addonUrl}</p>
<p class="text-sm font-semibold text-orange-600 mt-4">
Disclaimer: This addon is not official and is not affiliated
with the
<a
href="https://real-debrid.com/"
target="_blank"
rel="noopener noreferrer"
class="underline transition duration-300 hover:text-orange-700"
>Real Debrid</a
>
website.
</p>
<footer class="mt-4 text-center text-sm font-medium text-gray-600">
© ${new Date().getFullYear()} <a href="https://devwz.com" target="_blank" class="font-semibold text-blue-500 hover:text-blue-700">DEV Wizard</a>. All rights reserved. Version ${pkg.version}
</footer>
</div>
</body>
</html>
`);
});
app.use("/:config", (req, res, next) => {
const configEncoded = req.params.config;
let config;
try {
const configString = Buffer.from(configEncoded, "base64").toString(
"utf8"
);
config = JSON.parse(configString);
} catch (e) {
return res.status(400).send("Invalid configuration");
}
const addonInterface = addonBuilder(config);
const router = getRouter(addonInterface);
router(req, res, next);
});
const PORT = process.env.PORT || 62316;
app.listen(PORT, () => {
console.log(`Addon running at http://localhost:${PORT}`);
});