mirror of
https://github.com/TheBinaryNinja/tvapp2.git
synced 2026-06-04 05:35:41 -04:00
chore: fix formatting for index.js main node script
This commit is contained in:
@@ -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_IP` | `0.0.0.0` | IP to use for webserver |
|
||||||
| `WEB_PORT` | `4124` | Port 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. |
|
| `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> |
|
| `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 />
|
<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_IP` | `0.0.0.0` | IP to use for webserver |
|
||||||
| `WEB_PORT` | `4124` | Port 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. |
|
| `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> |
|
| `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 />
|
<br />
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ async function downloadFile(url, filePath) {
|
|||||||
}
|
}
|
||||||
response.pipe(file);
|
response.pipe(file);
|
||||||
file.on('finish', () => {
|
file.on('finish', () => {
|
||||||
log(`Sucess: ${filePath}`);
|
log(`Success: ${filePath}`);
|
||||||
file.close(() => resolve(true));
|
file.close(() => resolve(true));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -145,7 +145,11 @@ async function fetchRemote(url) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const mod = url.startsWith('https') ? https : http;
|
const mod = url.startsWith('https') ? https : http;
|
||||||
mod
|
mod
|
||||||
.get(url, { headers: { 'Accept-Encoding': 'gzip, deflate, br' } }, (resp) => {
|
.get(url, {
|
||||||
|
headers: {
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br'
|
||||||
|
}
|
||||||
|
}, (resp) => {
|
||||||
if (resp.statusCode !== 200) {
|
if (resp.statusCode !== 200) {
|
||||||
return reject(new Error(`HTTP ${resp.statusCode} for ${url}`));
|
return reject(new Error(`HTTP ${resp.statusCode} for ${url}`));
|
||||||
}
|
}
|
||||||
@@ -182,15 +186,21 @@ async function serveKey(req, res) {
|
|||||||
try {
|
try {
|
||||||
const uriParam = new URL(req.url, `http://${req.headers.host}`).searchParams.get('uri');
|
const uriParam = new URL(req.url, `http://${req.headers.host}`).searchParams.get('uri');
|
||||||
if (!uriParam) {
|
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.');
|
return res.end('Error: Missing "uri" parameter for key download.');
|
||||||
}
|
}
|
||||||
const keyData = await fetchRemote(uriParam);
|
const keyData = await fetchRemote(uriParam);
|
||||||
res.writeHead(200, { 'Content-Type': 'application/octet-stream' });
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/octet-stream'
|
||||||
|
});
|
||||||
res.end(keyData);
|
res.end(keyData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error in serveKey:', err.message);
|
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.');
|
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');
|
const urlParam = new URL(req.url, `http://${req.headers.host}`).searchParams.get('url');
|
||||||
if (!urlParam) {
|
if (!urlParam) {
|
||||||
log('Error: Missing URL parameter');
|
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.');
|
res.end('Error: Missing URL parameter.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const decodedUrl = decodeURIComponent(urlParam);
|
const decodedUrl = decodeURIComponent(urlParam);
|
||||||
if (decodedUrl.endsWith('.ts')) {
|
if (decodedUrl.endsWith('.ts')) {
|
||||||
res.writeHead(302, { Location: decodedUrl });
|
res.writeHead(302, {
|
||||||
|
Location: decodedUrl
|
||||||
|
});
|
||||||
res.end();
|
res.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -321,7 +335,9 @@ async function serveChannelPlaylist(req, res) {
|
|||||||
const finalUrl = await getTokenizedUrl(decodedUrl);
|
const finalUrl = await getTokenizedUrl(decodedUrl);
|
||||||
if (!finalUrl) {
|
if (!finalUrl) {
|
||||||
log('Error: Failed to retrieve tokenized URL');
|
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.');
|
res.end('Error: Failed to retrieve tokenized URL.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -337,7 +353,9 @@ async function serveChannelPlaylist(req, res) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Error processing request: ${error.message}`);
|
log(`Error processing request: ${error.message}`);
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
res.writeHead(500, {
|
||||||
|
'Content-Type': 'text/plain'
|
||||||
|
});
|
||||||
res.end('Error processing request.');
|
res.end('Error processing request.');
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -391,7 +409,9 @@ async function servePlaylist(response, req) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
console.error('Error in servePlaylist:', error.message);
|
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}`);
|
response.end(`Error serving playlist: ${error.message}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -416,7 +436,9 @@ async function serveXmltv(response, req) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
console.error('Error in servePlaylist:', error.message);
|
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}`);
|
response.end(`Error serving playlist: ${error.message}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -479,7 +501,10 @@ async function servePlaylist(response, req) {
|
|||||||
|
|
||||||
function setCache(key, value, ttl) {
|
function setCache(key, value, ttl) {
|
||||||
const expiry = Date.now() + 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`);
|
log(`Cache set: ${key}, expires in ${ttl / 1000} seconds`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +543,7 @@ const server = http.createServer((req, res) => {
|
|||||||
if (req.url === '/' && req.method === 'GET') {
|
if (req.url === '/' && req.method === 'GET') {
|
||||||
const htmlContent = `<!DOCTYPE html>
|
const htmlContent = `<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Playlist Details</title>
|
<title>Playlist Details</title>
|
||||||
@@ -530,26 +555,32 @@ const server = http.createServer((req, res) => {
|
|||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 470px;
|
max-width: 470px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
color: #333;
|
color: #333;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #007bff;
|
color: #007bff;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.details p {
|
.details p {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
color: #555;
|
color: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
.warning {
|
.warning {
|
||||||
color: #ff4e4e;
|
color: #ff4e4e;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
@@ -558,24 +589,32 @@ const server = http.createServer((req, res) => {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#firewall-warning {
|
#firewall-warning {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #555;
|
color: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning-container p {
|
#warning-container p {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<center>
|
<center>
|
||||||
<div class="container main-container">
|
<div class="container main-container">
|
||||||
<h1>Playlist Details</h1>
|
<h1>Playlist Details</h1>
|
||||||
<div class="details">
|
<div class="details">
|
||||||
<p><strong>Playlist URL:</strong> <a id="playlist-url" target="_blank"></a></p>
|
<p>
|
||||||
<p><strong>EPG URL:</strong> <a id="epg-url" target="_blank"></a></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>
|
||||||
<div id="firewall-warning"></div>
|
<div id="firewall-warning"></div>
|
||||||
<div id="warning-container" class="container"></div>
|
<div id="warning-container" class="container"></div>
|
||||||
@@ -599,21 +638,26 @@ const server = http.createServer((req, res) => {
|
|||||||
warning.style.fontSize = "14px";
|
warning.style.fontSize = "14px";
|
||||||
warning.style.textAlign = "center";
|
warning.style.textAlign = "center";
|
||||||
warning.style.fontWeight = "bold";
|
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>" +
|
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.getElementById("warning-container").appendChild(warning);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
const port = window.location.port || (window.location.protocol === "https:" ? "443" : "80");
|
const port = window.location.port || (window.location.protocol === "https:" ? "443" : "80");
|
||||||
const warningMessage =
|
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'
|
||||||
"<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>";
|
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;
|
document.getElementById("firewall-warning").innerHTML = warningMessage;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>`;
|
</html>`;
|
||||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'text/html'
|
||||||
|
});
|
||||||
res.end(htmlContent);
|
res.end(htmlContent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -640,12 +684,16 @@ const server = http.createServer((req, res) => {
|
|||||||
res.end();
|
res.end();
|
||||||
return;*/
|
return;*/
|
||||||
}
|
}
|
||||||
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
res.writeHead(404, {
|
||||||
|
'Content-Type': 'text/plain'
|
||||||
|
});
|
||||||
res.end('Not Found');
|
res.end('Not Found');
|
||||||
};
|
};
|
||||||
handleRequest().catch((error) => {
|
handleRequest().catch((error) => {
|
||||||
console.error('Error handling request:', 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');
|
res.end('Internal Server Error');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user