chore: fix formatting for index.js main node script

This commit is contained in:
2025-02-23 10:35:54 -07:00
parent 4e4077145f
commit 856919f055
2 changed files with 515 additions and 467 deletions

View File

@@ -146,7 +146,7 @@ For the [environment variables](#environment-variables), you may specify these i
| `WEB_IP` | `0.0.0.0` | IP to use for webserver |
| `WEB_PORT` | `4124` | Port to use for webserver |
| `URL_REPO` | `https://git.binaryninja.net/BinaryNinja/` | Determines where the data files will be downloaded from. Do not change this or you will be unable to get M3U and EPG data. |
| `DIR_BUILD` | `/usr/src/app` | Path inside container where TVApp2 will be built. <br /><br /> ⚠️ <sup>This should not be used unless you know what you're doing</sup> |
| `DIR_BUILD` | `/usr/src/app` | Path inside container where TVApp2 will be built. <br /><br /> <sup>⚠️ This should not be used unless you know what you're doing</sup> |
| `DIR_RUN` | `/usr/bin/app` | Path inside container where TVApp2 will be placed after it is built <br /><br /> <sup>⚠️ This should not be used unless you know what you're doing</sup> |
<br />
@@ -750,7 +750,7 @@ This docker container contains the following env variables:
| `WEB_IP` | `0.0.0.0` | IP to use for webserver |
| `WEB_PORT` | `4124` | Port to use for webserver |
| `URL_REPO` | `https://git.binaryninja.net/BinaryNinja/` | Determines where the data files will be downloaded from. Do not change this or you will be unable to get M3U and EPG data. |
| `DIR_BUILD` | `/usr/src/app` | Path inside container where TVApp2 will be built. <br /><br /> ⚠️ <sup>This should not be used unless you know what you're doing</sup> |
| `DIR_BUILD` | `/usr/src/app` | Path inside container where TVApp2 will be built. <br /><br /> <sup>⚠️ This should not be used unless you know what you're doing</sup> |
| `DIR_RUN` | `/usr/bin/app` | Path inside container where TVApp2 will be placed after it is built <br /><br /> <sup>⚠️ This should not be used unless you know what you're doing</sup> |
<br />

View File

@@ -91,7 +91,7 @@ async function downloadFile(url, filePath) {
}
response.pipe(file);
file.on('finish', () => {
log(`Sucess: ${filePath}`);
log(`Success: ${filePath}`);
file.close(() => resolve(true));
});
})
@@ -145,7 +145,11 @@ async function fetchRemote(url) {
return new Promise((resolve, reject) => {
const mod = url.startsWith('https') ? https : http;
mod
.get(url, { headers: { 'Accept-Encoding': 'gzip, deflate, br' } }, (resp) => {
.get(url, {
headers: {
'Accept-Encoding': 'gzip, deflate, br'
}
}, (resp) => {
if (resp.statusCode !== 200) {
return reject(new Error(`HTTP ${resp.statusCode} for ${url}`));
}
@@ -182,15 +186,21 @@ async function serveKey(req, res) {
try {
const uriParam = new URL(req.url, `http://${req.headers.host}`).searchParams.get('uri');
if (!uriParam) {
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.writeHead(400, {
'Content-Type': 'text/plain'
});
return res.end('Error: Missing "uri" parameter for key download.');
}
const keyData = await fetchRemote(uriParam);
res.writeHead(200, { 'Content-Type': 'application/octet-stream' });
res.writeHead(200, {
'Content-Type': 'application/octet-stream'
});
res.end(keyData);
} catch (err) {
console.error('Error in serveKey:', err.message);
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Error fetching key.');
}
}
@@ -297,13 +307,17 @@ async function serveChannelPlaylist(req, res) {
const urlParam = new URL(req.url, `http://${req.headers.host}`).searchParams.get('url');
if (!urlParam) {
log('Error: Missing URL parameter');
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.writeHead(400, {
'Content-Type': 'text/plain'
});
res.end('Error: Missing URL parameter.');
return;
}
const decodedUrl = decodeURIComponent(urlParam);
if (decodedUrl.endsWith('.ts')) {
res.writeHead(302, { Location: decodedUrl });
res.writeHead(302, {
Location: decodedUrl
});
res.end();
return;
}
@@ -321,7 +335,9 @@ async function serveChannelPlaylist(req, res) {
const finalUrl = await getTokenizedUrl(decodedUrl);
if (!finalUrl) {
log('Error: Failed to retrieve tokenized URL');
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Error: Failed to retrieve tokenized URL.');
return;
}
@@ -337,7 +353,9 @@ async function serveChannelPlaylist(req, res) {
} catch (error) {
log(`Error processing request: ${error.message}`);
if (!res.headersSent) {
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Error processing request.');
}
} finally {
@@ -391,7 +409,9 @@ async function servePlaylist(response, req) {
} catch (error) {
console.error('Error in servePlaylist:', error.message);
response.writeHead(500, { 'Content-Type': 'text/plain' });
response.writeHead(500, {
'Content-Type': 'text/plain'
});
response.end(`Error serving playlist: ${error.message}`);
}
@@ -416,7 +436,9 @@ async function serveXmltv(response, req) {
} catch (error) {
console.error('Error in servePlaylist:', error.message);
response.writeHead(500, { 'Content-Type': 'text/plain' });
response.writeHead(500, {
'Content-Type': 'text/plain'
});
response.end(`Error serving playlist: ${error.message}`);
}
@@ -479,7 +501,10 @@ async function servePlaylist(response, req) {
function setCache(key, value, ttl) {
const expiry = Date.now() + ttl;
cache.set(key, { value, expiry });
cache.set(key, {
value,
expiry
});
log(`Cache set: ${key}, expires in ${ttl / 1000} seconds`);
}
@@ -530,26 +555,32 @@ const server = http.createServer((req, res) => {
background-color: #fff;
padding: 20px;
}
.container {
width: 100%;
max-width: 470px;
margin: 0 auto;
}
h1 {
color: #333;
margin-bottom: 20px;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.details p {
margin: 10px 0;
color: #555;
}
.warning {
color: #ff4e4e;
font-size: 16px;
@@ -558,12 +589,14 @@ const server = http.createServer((req, res) => {
text-align: center;
width: 100%;
}
#firewall-warning {
margin-top: 20px;
width: 100%;
text-align: center;
color: #555;
}
#warning-container p {
margin: 10px 0;
}
@@ -574,8 +607,14 @@ const server = http.createServer((req, res) => {
<div class="container main-container">
<h1>Playlist Details</h1>
<div class="details">
<p><strong>Playlist URL:</strong> <a id="playlist-url" target="_blank"></a></p>
<p><strong>EPG URL:</strong> <a id="epg-url" target="_blank"></a></p>
<p>
<strong>Playlist URL:</strong>
<a id="playlist-url" target="_blank"></a>
</p>
<p>
<strong>EPG URL:</strong>
<a id="epg-url" target="_blank"></a>
</p>
</div>
<div id="firewall-warning"></div>
<div id="warning-container" class="container"></div>
@@ -600,20 +639,25 @@ const server = http.createServer((req, res) => {
warning.style.textAlign = "center";
warning.style.fontWeight = "bold";
warning.innerHTML = " < p > Warning: If you are accessing this page via 127.0 .0 .1 or localhost, proxying will not work on other devices.Please load this page using your computer 's IP address (e.g., 192.168.x.x) and port in order to access the playlist from other devices on your network.</p>" +
"<p>How to locate IP address on <a href='https://www.youtube.com/watch?v=UAhDHXN2c6E' target='_blank'>Windows</a> or <a href='https://www.youtube.com/watch?v=gaIYP4TZfHI' target='_blank'>Linux</a>.</p>";
" < p > How to locate IP address on < a href = 'https://www.youtube.com/watch?v=UAhDHXN2c6E'
target = '_blank' > Windows < /a> or < a href = 'https://www.youtube.com/watch?v=gaIYP4TZfHI'
target = '_blank' > Linux < /a>. < /p>";
document.getElementById("warning-container").appendChild(warning);
}
});
document.addEventListener("DOMContentLoaded", function() {
const port = window.location.port || (window.location.protocol === "https:" ? "443" : "80");
const warningMessage =
"<p>Ensure that port <strong>" + port + "</strong> is open and allowed through your Windows (<a href='https://youtu.be/zOZWlTplrcA?si=nGXrHKU4sAQsy18e&t=18' target='_blank'>how to</a>) or Linux (<a href='https://youtu.be/7c_V_3nWWbA?si=Hkd_II9myn-AkNnS&t=12' target='_blank'>how to</a>) firewall settings. This will enable other devices, such as Firestick, Android, and others, to connect to the server and request the playlist through the proxy.</p>";
const warningMessage = " < p > Ensure that port < strong > " + port + " < /strong> is open and allowed through your Windows ( < a href = 'https://youtu.be/zOZWlTplrcA?si=nGXrHKU4sAQsy18e&t=18'
target = '_blank' > how to < /a>) or Linux ( < a href = 'https://youtu.be/7c_V_3nWWbA?si=Hkd_II9myn-AkNnS&t=12'
target = '_blank' > how to < /a>) firewall settings. This will enable other devices, such as Firestick, Android, and others, to connect to the server and request the playlist through the proxy. < /p>";
document.getElementById("firewall-warning").innerHTML = warningMessage;
});
</script>
</body>
</html>`;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(htmlContent);
return;
}
@@ -640,12 +684,16 @@ const server = http.createServer((req, res) => {
res.end();
return;*/
}
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.writeHead(404, {
'Content-Type': 'text/plain'
});
res.end('Not Found');
};
handleRequest().catch((error) => {
console.error('Error handling request:', error);
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Internal Server Error');
});
});