From 88ec98c92a5c1f457423b89c1930074c4ab88a6b Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 19 Oct 2020 03:25:49 +0000 Subject: [PATCH] size sanity in webui sidebar log output --- static-data/www/shared/sidebar/sidebar.js | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/static-data/www/shared/sidebar/sidebar.js b/static-data/www/shared/sidebar/sidebar.js index 92ec00a9..483d9196 100644 --- a/static-data/www/shared/sidebar/sidebar.js +++ b/static-data/www/shared/sidebar/sidebar.js @@ -14,6 +14,8 @@ var sidebarActive = false var lastLogOffset = 0 var logActive = false +var maxLogOutputSize = 1000000 +var logfileOutputEl = null async function showLog(){ @@ -24,13 +26,29 @@ async function showLog(){ }}) .then((resp) => resp.json()) .then(function(resp){ + let doScroll = function(){ + if (!logActive){ + logfileOutputEl.scrollTop = logfileOutputEl.scrollHeight; + } + } + if (! resp.data){ + doScroll() + return + } + lastLogOffset = resp['new_offset'] - var logfileOutputEl = document.getElementById('logfileOutput') + + var length = (new TextEncoder().encode(logfileOutputEl.innerText)).length + var tempText = logfileOutputEl.innerText + while(length > maxLogOutputSize){ + tempText = tempText.substring(tempText.indexOf("\n") + 1) + length = (new TextEncoder().encode(tempText)).length + logfileOutputEl.innerText = tempText + } + logfileOutputEl.innerText += resp.data.replace( /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '') - if (!logActive){ - logfileOutputEl.scrollTop = logfileOutputEl.scrollHeight; - } + doScroll() }) } @@ -94,6 +112,7 @@ window.addEventListener("keydown", function(event) { clearInterval(refreshSideBarInterval) } if (event.key === "s"){ + logfileOutputEl = document.getElementById('logfileOutput') sidebarActive = true if (document.activeElement.nodeName == "TEXTAREA" || document.activeElement.nodeName == "INPUT"){ if (! document.activeElement.hasAttribute("readonly")){