-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
92 lines (81 loc) · 4.14 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
import express from 'express';
import fetch from 'node-fetch';
const app = express();
const port = 3005;
app.get('/', async (req, res) => {
const { width, player, timeset, theme, bgColor, headerColor, buttonColor, labelColor, ppColor, selectedColor } = req.query;
if (!width || !player || !timeset) {
return res.status(400).send('Width and bioFile query parameters are required');
}
try {
const response = await fetch(`https://cdn.assets.beatleader.xyz/player-${player}-richbio-${parseInt(timeset)}.html`);
if (!response.ok) {
throw new Error('Failed to fetch bio file');
}
const richBio = await response.text();
const htmlContent = `
<!DOCTYPE html>
<html data-overlayscrollbars-initialize>
<head>
<style>
html {
width: ${width}px;
}
:root {
--bgColor: ${bgColor};
--headerColor: ${headerColor};
--buttonColor: ${buttonColor};
--labelColor: ${labelColor};
--ppColor: ${ppColor};
--selectedColor: ${selectedColor};
}
.os-theme-dark {
--os-handle-bg: rgb(183 183 183 / 44%) !important;
--os-handle-bg-hover: rgba(0,0,0,.55);
--os-handle-bg-active: rgba(0,0,0,.66);
}
body.default-theme {
background-color: #3d3d3d;
}
body.mirror-theme {
box-shadow: inset 0 0 7px 0px #00000029;
background-color: rgba(0, 0, 0, 0.2);
}
body.mirror-low-theme {
background-color: rgba(0, 0, 0, 0.2);
}
body.ree-dark-theme {
background: #121212;
}
body.flylight-theme {
background-color: rgba(0, 0, 0, 0.1);
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/overlayscrollbars/2.3.0/styles/overlayscrollbars.min.css" integrity="sha512-MMVRaRR0pB97w1tzt6+29McVwX+YsQcSlIehGCGqFsC+KisK3d2F/xRxFaGMN7126EeC3A6iYRhdkr5nY8fz3Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body data-overlayscrollbars-initialize class="${theme}-theme">
${richBio}
<script src="https://cdnjs.cloudflare.com/ajax/libs/overlayscrollbars/2.3.0/browser/overlayscrollbars.browser.es6.min.js" integrity="sha512-tu2VesH7qQi/IX4MN47Zw0SCia4hgBgu4xY/fP/gV2XcqdZsIh1B5wbSy4Mk5AhkkfTj/XMDQt86wzsZIsxPSA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
function sendHeight() {
var height = document.body?.offsetHeight;
window.parent.postMessage({
'frameHeight': height
}, '*');
}
window.onload = sendHeight;
window.onresize = sendHeight;
document.onreadystatechange = sendHeight;
const scrollbars = OverlayScrollbarsGlobal.OverlayScrollbars(document.body, {overflow: {x: "hidden"}, scrollbars: { theme: 'os-theme-dark', autoHide: "scroll", dragScroll: true }});
</script>
</body>
</html>`;
res.send(htmlContent);
} catch (err) {
console.error(err);
res.status(500).send('Error fetching the bio file');
}
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});