feat: add filesize to list of files hosted in app

This commit is contained in:
2025-03-23 21:10:07 -07:00
parent 44f7f8c6c2
commit b163dff842
3 changed files with 147 additions and 67 deletions

View File

@@ -49,9 +49,12 @@ chalk.level = 3;
*/ */
let FILE_URL; let FILE_URL;
let FILE_DAT; let FILE_M3U;
let FILE_XML; let FILE_XML;
let FILE_TAR; let FILE_TAR;
let FILE_M3U_SIZE = 0;
let FILE_XML_SIZE = 0;
let FILE_TAR_SIZE = 0;
/* /*
Define > Environment Variables || Defaults Define > Environment Variables || Defaults
@@ -170,7 +173,7 @@ if ( process.pkg )
Log.info( `Processing Package` ); Log.info( `Processing Package` );
const basePath = path.dirname( process.execPath ); const basePath = path.dirname( process.execPath );
FILE_URL = path.join( basePath, 'urls.txt' ); FILE_URL = path.join( basePath, 'urls.txt' );
FILE_DAT = path.join( basePath, 'formatted.dat' ); FILE_M3U = path.join( basePath, 'formatted.dat' );
FILE_XML = path.join( basePath, `${ envFileXML }` ); FILE_XML = path.join( basePath, `${ envFileXML }` );
FILE_XML.length; FILE_XML.length;
FILE_TAR = path.join( basePath, `${ envFileTAR }` ); FILE_TAR = path.join( basePath, `${ envFileTAR }` );
@@ -179,7 +182,7 @@ else
{ {
Log.info( `Processing Locals` ); Log.info( `Processing Locals` );
FILE_URL = path.resolve( __dirname, 'urls.txt' ); FILE_URL = path.resolve( __dirname, 'urls.txt' );
FILE_DAT = path.resolve( __dirname, 'formatted.dat' ); FILE_M3U = path.resolve( __dirname, 'formatted.dat' );
FILE_XML = path.resolve( __dirname, `${ envFileXML }` ); FILE_XML = path.resolve( __dirname, `${ envFileXML }` );
FILE_TAR = path.resolve( __dirname, `${ envFileTAR }` ); FILE_TAR = path.resolve( __dirname, `${ envFileTAR }` );
} }
@@ -267,6 +270,39 @@ async function downloadFile( url, filePath )
}); });
} }
/*
Get Filesize and convert to human readable format
*/
function getFilesizeHuman( filename, si = true, dp = 1 )
{
const stats = fs.statSync( filename );
let bytes = stats.size;
const thresh = si ? 1000 : 1024;
if ( Math.abs( bytes ) < thresh )
return bytes + ' B';
const units = si
? [
'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'
]
: [
'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'
];
let u = -1;
const r = 10 ** dp;
do
{
bytes /= thresh;
++u;
} while ( Math.round( Math.abs( bytes ) * r ) / r >= thresh && u < units.length - 1 );
return bytes.toFixed( dp ) + ' ' + units[u];
}
/* /*
Func > Ensure File Exists Func > Ensure File Exists
@@ -650,7 +686,7 @@ async function serveM3U( response, req )
const protocol = req.headers['x-forwarded-proto']?.split( ',' )[0] || ( req.socket.encrypted ? 'https' : 'http' ); const protocol = req.headers['x-forwarded-proto']?.split( ',' )[0] || ( req.socket.encrypted ? 'https' : 'http' );
const host = req.headers.host; const host = req.headers.host;
const baseUrl = `${ protocol }://${ host }`; const baseUrl = `${ protocol }://${ host }`;
const formattedContent = fs.readFileSync( FILE_DAT, 'utf-8' ); const formattedContent = fs.readFileSync( FILE_M3U, 'utf-8' );
const updatedContent = formattedContent const updatedContent = formattedContent
.replace( /(https?:\/\/[^\s]*thetvapp[^\s]*)/g, ( fullUrl ) => .replace( /(https?:\/\/[^\s]*thetvapp[^\s]*)/g, ( fullUrl ) =>
{ {
@@ -779,8 +815,8 @@ async function initialize()
Log.info( `Initializing server...` ); Log.info( `Initializing server...` );
await ensureFileExists( extURL, FILE_URL ); await ensureFileExists( extURL, FILE_URL );
await ensureFileExists( extFormatted, FILE_DAT );
await ensureFileExists( extXML, FILE_XML ); await ensureFileExists( extXML, FILE_XML );
await ensureFileExists( extFormatted, FILE_M3U );
/* /*
Create tar.gz of xml data Create tar.gz of xml data
@@ -813,6 +849,14 @@ async function initialize()
throw new Error( `No valid URLs found in ${ FILE_URL }` ); throw new Error( `No valid URLs found in ${ FILE_URL }` );
} }
/*
Calculate Sizes
*/
FILE_M3U_SIZE = getFilesizeHuman( FILE_M3U );
FILE_XML_SIZE = getFilesizeHuman( FILE_XML );
FILE_TAR_SIZE = getFilesizeHuman( FILE_TAR );
Log.info( `Initializing Complete` ); Log.info( `Initializing Complete` );
} }
catch ( error ) catch ( error )
@@ -907,7 +951,17 @@ const server = http.createServer( ( request, response ) =>
read the loaded asset file read the loaded asset file
*/ */
ejs.renderFile( './www/' + loadAsset, { fileXML: envFileXML, fileM3U: envFileM3U, fileTAR: envFileTAR, appName: name, appVersion: version }, ( err, data ) => ejs.renderFile( './www/' + loadAsset,
{
fileXML: envFileXML,
sizeXML: FILE_XML_SIZE,
fileM3U: envFileM3U,
sizeM3U: FILE_M3U_SIZE,
fileTAR: envFileTAR,
sizeTAR: FILE_TAR_SIZE,
appName: name,
appVersion: version
}, ( err, data ) =>
{ {
if ( !err ) if ( !err )
{ {

View File

@@ -56,8 +56,8 @@ body
{ {
padding-left: 8px; padding-left: 8px;
padding-bottom: 4vh; padding-bottom: 4vh;
font-size: 1.6vmin; font-size: clamp(0.7em, 1vw, 0.9em);
line-height: 2.5vmin; line-height: 1.6;
font-weight: 100; font-weight: 100;
} }
@@ -199,12 +199,15 @@ p
#list a, #list a,
#list a:focus #list a:focus
{ {
color: #FFF !important; color: #ff286e !important;
font-weight: 100;
} }
#list a:hover #list a:hover
{ {
color: #ff275d !important; color: #FFF !important;
text-decoration: underline dotted #FF0048;
font-weight: 100;
} }
#list colgroup #list colgroup
@@ -212,25 +215,52 @@ p
display: none; display: none;
} }
#list .cell-file #list .file
{ {
word-break: keep-all; word-break: keep-all;
white-space: normal; white-space: normal;
min-width: 11vw !important; min-width: 8vw !important;
text-wrap: nowrap; text-wrap: nowrap;
font-size: clamp(0.7em, 1vw, 0.9em);
font-weight: 800;
vertical-align: middle;
} }
#list .cell-link #list .file a
{
font-weight: 800;
}
#list .link
{ {
word-break: break-all; word-break: break-all;
white-space: normal; white-space: normal;
min-width: 14vw !important; min-width: 11vw !important;
text-wrap: nowrap; text-wrap: nowrap;
font-size: clamp(0.7em, 1vw, 0.9em);
vertical-align: middle;
} }
table #list .icon
{ {
font-size: 2.2vmin;
vertical-align: middle;
}
#list .size
{
min-width: 5vw !important;
font-size: clamp(0.7em, 1vw, 0.9em);
word-break: break-all;
white-space: normal;
text-wrap: nowrap;
vertical-align: middle;
}
#list .desc
{
font-size: clamp(0.7em, 1vw, 0.9em);
vertical-align: middle;
} }
.table thead th a .table thead th a
@@ -242,10 +272,10 @@ table
.table td, .table th .table td, .table th
{ {
padding: .75rem; padding: .75rem;
vertical-align: top; vertical-align: baseline;
border-top: 0px solid #dee2e6; border-top: 0px solid #dee2e6;
font-size: 1.6vmin; font-size: clamp(0.7em, 1vw, 0.9em);
line-height: 2.5vmin; line-height: 1.6;
} }
.table thead tr .table thead tr
@@ -259,23 +289,10 @@ table
{ {
vertical-align: bottom; vertical-align: bottom;
border-bottom: 0px solid #575757; border-bottom: 0px solid #575757;
font-size: 1.6vmin; font-size: clamp(0.7em, 1vw, 0.9em);
line-height: 2.5vmin; line-height: 2.5vmin;
} }
#list .link a
{
color: #ff286e !important;
font-weight: 100;
}
#list .link a:hover
{
color: #FFF !important;
text-decoration: underline dotted #FF0048;
font-weight: 100;
}
.table-hover tbody tr:hover .table-hover tbody tr:hover
{ {
background-color: rgba(155, 155, 155, 0.075); background-color: rgba(155, 155, 155, 0.075);
@@ -292,7 +309,7 @@ table
background-color: #1A1A1A; background-color: #1A1A1A;
padding: 2vh; padding: 2vh;
margin-bottom: 1vh; margin-bottom: 1vh;
font-size: 1.6vmin; font-size: clamp(0.7em, 1vw, 0.9em);
font-weight: 100; font-weight: 100;
border: 1px dashed #FF6C00; border: 1px dashed #FF6C00;
width: 100%; width: 100%;
@@ -303,7 +320,7 @@ table
{ {
background-color: #1A1A1A; background-color: #1A1A1A;
padding: 2vh; padding: 2vh;
font-size: 1.6vmin; font-size: clamp(0.7em, 1vw, 0.9em);
font-weight: 100; font-weight: 100;
border: 1px dashed #FF0048; border: 1px dashed #FF0048;
width: 100%; width: 100%;

View File

@@ -37,7 +37,10 @@
File Name File Name
</th> </th>
<th class="link cell-link"> <th class="link cell-link">
Link Download
</th>
<th class="size cell-size">
Size
</th> </th>
<th class="desc cell-desc"> <th class="desc cell-desc">
Description Description
@@ -56,12 +59,13 @@
<a id="m3u-name" target="_blank"></a> <a id="m3u-name" target="_blank"></a>
</td> </td>
<td class="link cell-link"><a id="m3u-link" target="_blank"></a></td> <td class="link cell-link"><a id="m3u-link" target="_blank"></a></td>
<td class="size cell-size"><span id="m3u-size"></span></td>
<td class="desc cell-desc">Playlist data file which contains a list of all channels, their associated group, and logo URL.</td> <td class="desc cell-desc">Playlist data file which contains a list of all channels, their associated group, and logo URL.</td>
</tr> </tr>
<tr> <tr>
<td class="icon cell-icon"> <td class="icon cell-icon">
<svg class="svg-inline--fa fa-file-lines fa-fw" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="file-lines" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" data-fa-i2svg=""> <svg class="svg-inline--fa fa-file-xml fa-fw" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="file-xml" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg="">
<path fill="currentColor" d="M64 0C28.7 0 0 28.7 0 64V448c0 35.3 28.7 64 64 64H320c35.3 0 64-28.7 64-64V160H256c-17.7 0-32-14.3-32-32V0H64zM256 0V128H384L256 0zM112 256H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16zm0 64H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16zm0 64H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16z"></path> <path fill="currentColor" d="M0 64C0 28.7 28.7 0 64 0H224V128c0 17.7 14.3 32 32 32H384V304H176c-35.3 0-64 28.7-64 64V512H64c-35.3 0-64-28.7-64-64V64zm384 64H256V0L384 128zM192 368c0 7.3 2.2 14.4 6.2 20.4l9.8 14.7 9.8-14.7c4-6.1 6.2-13.2 6.2-20.4c0-8.8 7.2-16 16-16s16 7.2 16 16c0 13.6-4 26.9-11.6 38.2L227.2 432l17.2 25.8C252 469.1 256 482.4 256 496c0 8.8-7.2 16-16 16s-16-7.2-16-16c0-7.3-2.2-14.4-6.2-20.4L208 460.8l-9.8 14.7c-4 6.1-6.2 13.2-6.2 20.4c0 8.8-7.2 16-16 16s-16-7.2-16-16c0-13.6 4-26.9 11.6-38.2L188.8 432l-17.2-25.8C164 394.9 160 381.6 160 368c0-8.8 7.2-16 16-16s16 7.2 16 16zM448 496V368c0-8.8 7.2-16 16-16s16 7.2 16 16V480h16c8.8 0 16 7.2 16 16s-7.2 16-16 16H464c-8.8 0-16-7.2-16-16zM299.7 352.6c6.9-1.9 14.3 1 18 7.2L352 416.9l34.3-57.1c3.7-6.2 11.1-9.1 18-7.2s11.7 8.2 11.7 15.4V496c0 8.8-7.2 16-16 16s-16-7.2-16-16V425.8l-18.3 30.5c-2.9 4.8-8.1 7.8-13.7 7.8s-10.8-2.9-13.7-7.8L320 425.8V496c0 8.8-7.2 16-16 16s-16-7.2-16-16V368c0-7.2 4.8-13.5 11.7-15.4z"></path>
</svg> </svg>
<!-- <i class="fa fa-fw fa-solid fa-file-lines" aria-hidden="true"></i> --> <!-- <i class="fa fa-fw fa-solid fa-file-lines" aria-hidden="true"></i> -->
</td> </td>
@@ -69,6 +73,7 @@
<a id="xml-name" target="_blank"></a> <a id="xml-name" target="_blank"></a>
</td> </td>
<td class="link cell-link"><a id="xml-link" target="_blank"></a></td> <td class="link cell-link"><a id="xml-link" target="_blank"></a></td>
<td class="size cell-size"><span id="xml-size"></span></td>
<td class="desc cell-desc">XML / EPG guide data which contains a list of all programs which are scheduled to play on a specific channel.</td> <td class="desc cell-desc">XML / EPG guide data which contains a list of all programs which are scheduled to play on a specific channel.</td>
</tr> </tr>
<tr> <tr>
@@ -82,6 +87,7 @@
<a id="tar-name" target="_blank"></a> <a id="tar-name" target="_blank"></a>
</td> </td>
<td class="link cell-link"><a id="tar-link" target="_blank"></a></td> <td class="link cell-link"><a id="tar-link" target="_blank"></a></td>
<td class="size cell-size"><span id="tar-size"></span></td>
<td class="desc cell-desc">XML / EPG guide data compressed into tar.gz</td> <td class="desc cell-desc">XML / EPG guide data compressed into tar.gz</td>
</tr> </tr>
</tbody> </tbody>
@@ -114,16 +120,19 @@
document.getElementById("m3u-name").href = urlM3U; document.getElementById("m3u-name").href = urlM3U;
document.getElementById("m3u-link").textContent = urlM3U; document.getElementById("m3u-link").textContent = urlM3U;
document.getElementById("m3u-link").href = urlM3U; document.getElementById("m3u-link").href = urlM3U;
document.getElementById("m3u-size").textContent = "<%= sizeM3U %>";
document.getElementById("xml-name").textContent = "<%= fileXML %>"; document.getElementById("xml-name").textContent = "<%= fileXML %>";
document.getElementById("xml-name").href = urlXML; document.getElementById("xml-name").href = urlXML;
document.getElementById("xml-link").textContent = urlXML; document.getElementById("xml-link").textContent = urlXML;
document.getElementById("xml-link").href = urlXML; document.getElementById("xml-link").href = urlXML;
document.getElementById("xml-size").textContent = "<%= sizeXML %>";
document.getElementById("tar-name").textContent = "<%= fileTAR %>"; document.getElementById("tar-name").textContent = "<%= fileTAR %>";
document.getElementById("tar-name").href = urlTAR; document.getElementById("tar-name").href = urlTAR;
document.getElementById("tar-link").textContent = urlTAR; document.getElementById("tar-link").textContent = urlTAR;
document.getElementById("tar-link").href = urlTAR; document.getElementById("tar-link").href = urlTAR;
document.getElementById("tar-size").textContent = "<%= sizeTAR %>";
</script> </script>
<script> <script>