mirror of
https://github.com/TheBinaryNinja/tvapp2.git
synced 2026-06-04 04:35:41 -04:00
feat: add filesize to list of files hosted in app
This commit is contained in:
@@ -49,9 +49,12 @@ chalk.level = 3;
|
||||
*/
|
||||
|
||||
let FILE_URL;
|
||||
let FILE_DAT;
|
||||
let FILE_M3U;
|
||||
let FILE_XML;
|
||||
let FILE_TAR;
|
||||
let FILE_M3U_SIZE = 0;
|
||||
let FILE_XML_SIZE = 0;
|
||||
let FILE_TAR_SIZE = 0;
|
||||
|
||||
/*
|
||||
Define > Environment Variables || Defaults
|
||||
@@ -170,7 +173,7 @@ if ( process.pkg )
|
||||
Log.info( `Processing Package` );
|
||||
const basePath = path.dirname( process.execPath );
|
||||
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.length;
|
||||
FILE_TAR = path.join( basePath, `${ envFileTAR }` );
|
||||
@@ -179,7 +182,7 @@ else
|
||||
{
|
||||
Log.info( `Processing Locals` );
|
||||
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_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
|
||||
|
||||
@@ -650,7 +686,7 @@ async function serveM3U( response, req )
|
||||
const protocol = req.headers['x-forwarded-proto']?.split( ',' )[0] || ( req.socket.encrypted ? 'https' : 'http' );
|
||||
const host = req.headers.host;
|
||||
const baseUrl = `${ protocol }://${ host }`;
|
||||
const formattedContent = fs.readFileSync( FILE_DAT, 'utf-8' );
|
||||
const formattedContent = fs.readFileSync( FILE_M3U, 'utf-8' );
|
||||
const updatedContent = formattedContent
|
||||
.replace( /(https?:\/\/[^\s]*thetvapp[^\s]*)/g, ( fullUrl ) =>
|
||||
{
|
||||
@@ -779,8 +815,8 @@ async function initialize()
|
||||
Log.info( `Initializing server...` );
|
||||
|
||||
await ensureFileExists( extURL, FILE_URL );
|
||||
await ensureFileExists( extFormatted, FILE_DAT );
|
||||
await ensureFileExists( extXML, FILE_XML );
|
||||
await ensureFileExists( extFormatted, FILE_M3U );
|
||||
|
||||
/*
|
||||
Create tar.gz of xml data
|
||||
@@ -813,6 +849,14 @@ async function initialize()
|
||||
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` );
|
||||
}
|
||||
catch ( error )
|
||||
@@ -907,7 +951,17 @@ const server = http.createServer( ( request, response ) =>
|
||||
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 )
|
||||
{
|
||||
|
||||
133
tvapp2/www/css/tvapp2.min.css
vendored
133
tvapp2/www/css/tvapp2.min.css
vendored
@@ -1,16 +1,16 @@
|
||||
body
|
||||
{
|
||||
background-color: #f8f9fa;
|
||||
padding-bottom: 20px;
|
||||
overflow: auto;
|
||||
background-color: #f8f9fa;
|
||||
padding-bottom: 20px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark)
|
||||
{
|
||||
body
|
||||
{
|
||||
background-color: #262626;
|
||||
color: #fff;
|
||||
background-color: #262626;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ body
|
||||
{
|
||||
padding-left: 8px;
|
||||
padding-bottom: 4vh;
|
||||
font-size: 1.6vmin;
|
||||
line-height: 2.5vmin;
|
||||
font-size: clamp(0.7em, 1vw, 0.9em);
|
||||
line-height: 1.6;
|
||||
font-weight: 100;
|
||||
}
|
||||
|
||||
@@ -99,10 +99,10 @@ p
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.header .logo
|
||||
@@ -199,12 +199,15 @@ p
|
||||
#list a,
|
||||
#list a:focus
|
||||
{
|
||||
color: #FFF !important;
|
||||
color: #ff286e !important;
|
||||
font-weight: 100;
|
||||
}
|
||||
|
||||
#list a:hover
|
||||
{
|
||||
color: #ff275d !important;
|
||||
color: #FFF !important;
|
||||
text-decoration: underline dotted #FF0048;
|
||||
font-weight: 100;
|
||||
}
|
||||
|
||||
#list colgroup
|
||||
@@ -212,25 +215,52 @@ p
|
||||
display: none;
|
||||
}
|
||||
|
||||
#list .cell-file
|
||||
#list .file
|
||||
{
|
||||
word-break: keep-all;
|
||||
white-space: normal;
|
||||
min-width: 11vw !important;
|
||||
min-width: 8vw !important;
|
||||
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;
|
||||
white-space: normal;
|
||||
min-width: 14vw !important;
|
||||
min-width: 11vw !important;
|
||||
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
|
||||
@@ -242,10 +272,10 @@ table
|
||||
.table td, .table th
|
||||
{
|
||||
padding: .75rem;
|
||||
vertical-align: top;
|
||||
vertical-align: baseline;
|
||||
border-top: 0px solid #dee2e6;
|
||||
font-size: 1.6vmin;
|
||||
line-height: 2.5vmin;
|
||||
font-size: clamp(0.7em, 1vw, 0.9em);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.table thead tr
|
||||
@@ -259,23 +289,10 @@ table
|
||||
{
|
||||
vertical-align: bottom;
|
||||
border-bottom: 0px solid #575757;
|
||||
font-size: 1.6vmin;
|
||||
font-size: clamp(0.7em, 1vw, 0.9em);
|
||||
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
|
||||
{
|
||||
background-color: rgba(155, 155, 155, 0.075);
|
||||
@@ -292,7 +309,7 @@ table
|
||||
background-color: #1A1A1A;
|
||||
padding: 2vh;
|
||||
margin-bottom: 1vh;
|
||||
font-size: 1.6vmin;
|
||||
font-size: clamp(0.7em, 1vw, 0.9em);
|
||||
font-weight: 100;
|
||||
border: 1px dashed #FF6C00;
|
||||
width: 100%;
|
||||
@@ -303,7 +320,7 @@ table
|
||||
{
|
||||
background-color: #1A1A1A;
|
||||
padding: 2vh;
|
||||
font-size: 1.6vmin;
|
||||
font-size: clamp(0.7em, 1vw, 0.9em);
|
||||
font-weight: 100;
|
||||
border: 1px dashed #FF0048;
|
||||
width: 100%;
|
||||
@@ -369,38 +386,38 @@ code
|
||||
}
|
||||
|
||||
.col, .col-1, .col-10, .col-11, .col-12, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-auto, .col-lg, .col-lg-1, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-auto, .col-md, .col-md-1, .col-md-10, .col-md-11, .col-md-12, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-auto, .col-sm, .col-sm-1, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-auto, .col-xl, .col-xl-1, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-auto {
|
||||
position: relative;
|
||||
width: auto;
|
||||
min-height: 1px;
|
||||
padding-right: 15px;
|
||||
padding-left: 15px;
|
||||
position: relative;
|
||||
width: auto;
|
||||
min-height: 1px;
|
||||
padding-right: 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
.fixed-top
|
||||
{
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.fixed-bottom
|
||||
{
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.sticky-top
|
||||
{
|
||||
@supports (position: sticky)
|
||||
{
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,8 +425,8 @@ code
|
||||
{
|
||||
@supports (position: sticky)
|
||||
{
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,10 @@
|
||||
File Name
|
||||
</th>
|
||||
<th class="link cell-link">
|
||||
Link
|
||||
Download
|
||||
</th>
|
||||
<th class="size cell-size">
|
||||
Size
|
||||
</th>
|
||||
<th class="desc cell-desc">
|
||||
Description
|
||||
@@ -56,12 +59,13 @@
|
||||
<a id="m3u-name" 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>
|
||||
</tr>
|
||||
<tr>
|
||||
<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="">
|
||||
<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>
|
||||
<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="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>
|
||||
<!-- <i class="fa fa-fw fa-solid fa-file-lines" aria-hidden="true"></i> -->
|
||||
</td>
|
||||
@@ -69,6 +73,7 @@
|
||||
<a id="xml-name" 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>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -82,6 +87,7 @@
|
||||
<a id="tar-name" 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>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -114,16 +120,19 @@
|
||||
document.getElementById("m3u-name").href = urlM3U;
|
||||
document.getElementById("m3u-link").textContent = urlM3U;
|
||||
document.getElementById("m3u-link").href = urlM3U;
|
||||
document.getElementById("m3u-size").textContent = "<%= sizeM3U %>";
|
||||
|
||||
document.getElementById("xml-name").textContent = "<%= fileXML %>";
|
||||
document.getElementById("xml-name").href = urlXML;
|
||||
document.getElementById("xml-link").textContent = urlXML;
|
||||
document.getElementById("xml-link").href = urlXML;
|
||||
document.getElementById("xml-size").textContent = "<%= sizeXML %>";
|
||||
|
||||
document.getElementById("tar-name").textContent = "<%= fileTAR %>";
|
||||
document.getElementById("tar-name").href = urlTAR;
|
||||
document.getElementById("tar-link").textContent = urlTAR;
|
||||
document.getElementById("tar-link").href = urlTAR;
|
||||
document.getElementById("tar-size").textContent = "<%= sizeTAR %>";
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user