update wtv-home:/home

- remove spacing in favor of right alignment
- add compression status
This commit is contained in:
zefie
2021-08-08 22:55:22 -04:00
parent 177c43192e
commit 1aa1755664
2 changed files with 74 additions and 47 deletions

View File

@@ -12,6 +12,16 @@ if (ssid_sessions[socket.ssid].get('box-does-psuedo-encryption')) {
var cryptstatus = ((socket_sessions[socket.id].secure === true) ? "Encrypted" : "Not Encrypted") var cryptstatus = ((socket_sessions[socket.id].secure === true) ? "Encrypted" : "Not Encrypted")
} }
var comp_type = shouldWeCompress(socket.ssid,'text/html');
var compstatus = "uncompressed";
switch (comp_type) {
case 1:
compstatus = "wtv-lzpf";
break;
case 2:
compstatus = "gzip (level 9)";
break;
}
data = `<html> data = `<html>
<head> <head>
@@ -27,12 +37,13 @@ function go() {
<b>Welcome to ${z_title}`; <b>Welcome to ${z_title}`;
if (ssid_sessions[socket.ssid].getSessionData("registered")) data += ", " + ssid_sessions[socket.ssid].getSessionData("subscriber_username") + "!"; if (ssid_sessions[socket.ssid].getSessionData("registered")) data += ", " + ssid_sessions[socket.ssid].getSessionData("subscriber_username") + "!";
data += "</b><br>"; data += "</b><br>";
if (minisrv_config.config.git_commit) data += "<small><i>" + "&nbsp; ".repeat(35) + "git revision " + minisrv_config.config.git_commit + "</i></small><br>"; if (minisrv_config.config.git_commit) data += `<div width="540" align="right"><font size="-4"><i>git revision ${minisrv_config.config.git_commit}</i></small></font></div><br>`;
data += ` data += `
<b>Encryption Status</b>: ${cryptstatus}<br> <hr>
<b>Status</b>: ${cryptstatus} (${compstatus})<br>
<b>Connection Speed</b>: &rate; <b>Connection Speed</b>: &rate;
<p> <hr>
<form name=access onsubmit="go()"> <form name=access onsubmit="go()">
<ul> <ul>
<li><a href="client:relog">client:relog (direct)</a></li> <li><a href="client:relog">client:relog (direct)</a></li>

View File

@@ -567,8 +567,56 @@ function headerStringToObj(headers, response = false) {
return headers_obj; return headers_obj;
} }
async function sendToClient(socket, headers_obj, data) { function shouldWeCompress(ssid, headers_obj) {
var compress_data = false; var compress_data = false;
var compression_type = 0; // no compression
if (ssid_sessions[ssid]) {
if (ssid_sessions[ssid].capabilities) {
if (ssid_sessions[ssid].capabilities['client-can-receive-compressed-data']) {
if (minisrv_config.config.enable_lzpf_compression || minisrv_config.config.force_compression_type) {
compression_type = 1; // lzpf
}
if (ssid_sessions[ssid]) {
if (ssid_sessions[ssid].get("wtv-client-rom-type") != "bf0app" && (minisrv_config.config.enable_gzip_compression || minisrv_config.config.force_compression_type)) {
// LC2 and newer appear to support gzip even in the MiniBrowser
compression_type = 2; // gzip
}
}
// mostly for debugging
if (minisrv_config.config.force_compression_type == "lzpf") compression_type = 1;
if (minisrv_config.config.force_compression_type == "gzip") compression_type = 2;
// do not compress if already encoded
if (headers_obj["Content-Encoding"]) return 0;
// should we bother to compress?
var content_type = "";
if (typeof (headers_obj) == 'string') content_type = headers_obj;
else content_type = (typeof (headers_obj["wtv-modern-content-type"]) != 'undefined') ? headers_obj["wtv-modern-content-type"] : headers_obj["Content-Type"];
if (content_type) {
// both lzpf and gzip
if (content_type.match(/^text\//) && content_type != "text/tellyscript") compress_data = true;
else if (content_type.match(/^application\/(x-?)javascript$/)) compress_data = true;
else if (content_type == "application/json") compress_data = true;
if (compression_type == 2) {
// gzip only
if (content_type.match(/^audio\/(x-)?[midi|wav]/)) compress_data = true; // midi & wav
if (content_type.match(/^audio\/(x-)?[s3m|mod|xm]/)) compress_data = true; // s3m, mod, xm
if (content_type.match(/^audio\/(x-)?[midi|wav]/)) compress_data = true; // midi & wav
}
}
}
}
}
// return compression_type if compress_data = true
return (compress_data) ? compression_type : 0;
}
async function sendToClient(socket, headers_obj, data) {
var headers = ""; var headers = "";
var content_length = 0; var content_length = 0;
if (typeof (data) === 'undefined') data = ''; if (typeof (data) === 'undefined') data = '';
@@ -604,59 +652,27 @@ async function sendToClient(socket, headers_obj, data) {
// if box can do compression, see if its worth enabling // if box can do compression, see if its worth enabling
if (ssid_sessions[socket.ssid].capabilities) { var compression_type = shouldWeCompress(socket.ssid, headers_obj);
if (ssid_sessions[socket.ssid].capabilities['client-can-receive-compressed-data']) {
var compression_type = 1; // lzpf
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") != "bf0app") {
var compression_type = 2; // gzip
}
// mostly for debugging
if (minisrv_config.config.force_compression_type == "lzpf") compression_type = 1;
if (minisrv_config.config.force_compression_type == "gzip") compression_type = 2;
// should we bother to compress?
if (!headers_obj["Content-Encoding"]) {
if (typeof (headers_obj["Content-Type"]) != 'undefined') {
var content_type = (typeof (headers_obj["wtv-modern-content-type"]) != 'undefined') ? headers_obj["wtv-modern-content-type"] : headers_obj["Content-Type"];
// both lzpf and gzip
if (content_type.match(/^text\//) && headers_obj["Content-Type"] != "text/tellyscript") compress_data = true;
else if (content_type.match(/^application\/(x-?)javascript$/)) compress_data = true;
else if (content_type == "application/json") compress_data = true;
if (compression_type == 2) {
// gzip only
if (content_type.match(/^audio\/(x-)?[midi|wav]/)) compress_data = true; // midi & wav
if (content_type.match(/^audio\/(x-)?[s3m|mod|xm]/)) compress_data = true; // s3m, mod, xm
if (content_type.match(/^audio\/(x-)?[midi|wav]/)) compress_data = true; // midi & wav
}
}
}
if (headers_obj["wtv-modern-content-type"]) delete headers_obj["wtv-modern-content-type"]; if (headers_obj["wtv-modern-content-type"]) delete headers_obj["wtv-modern-content-type"];
}
}
// compress if needed // compress if needed
if (compress_data && compression_type && content_length > 0) { if (compression_type > 0 && content_length > 0) {
var uncompressed_content_length = content_length; var uncompressed_content_length = content_length;
switch (compression_type) { switch (compression_type) {
case 1: case 1:
// wtv-lzpf implementation // wtv-lzpf implementation
if (minisrv_config.config.enable_lzpf_compression || minisrv_config.config.force_compression_type) {
headers_obj["wtv-lzpf"] = 0; headers_obj["wtv-lzpf"] = 0;
var wtvcomp = new WTVLzpf(); var wtvcomp = new WTVLzpf();
data = wtvcomp.Compress(data); data = wtvcomp.Compress(data);
wtvcomp = null; // Makes the garbage gods happy so it cleans up our mess wtvcomp = null; // Makes the garbage gods happy so it cleans up our mess
}
break; break;
case 2: case 2:
// zlib gzip implementation // zlib gzip implementation
if (minisrv_config.config.enable_gzip_compression || minisrv_config.config.force_compression_type) {
headers_obj['Content-Encoding'] = 'gzip'; headers_obj['Content-Encoding'] = 'gzip';
data = zlib.gzipSync(data, { data = zlib.gzipSync(data, {
'level': 9 'level': 9
}); });
}
break; break;
} }