diff --git a/static-data/www/shared/sidebar/sidebar.html b/static-data/www/shared/sidebar/sidebar.html index 4538e35b..1e9e3f37 100644 --- a/static-data/www/shared/sidebar/sidebar.html +++ b/static-data/www/shared/sidebar/sidebar.html @@ -1,6 +1,6 @@
- +
@@ -20,6 +20,7 @@ Add Peer
+

       
diff --git a/static-data/www/shared/sidebar/sidebar.js b/static-data/www/shared/sidebar/sidebar.js index ac00dadf..1040e0e4 100644 --- a/static-data/www/shared/sidebar/sidebar.js +++ b/static-data/www/shared/sidebar/sidebar.js @@ -10,6 +10,22 @@ fetch('/shared/sidebar/sidebar.html', { sidebarAddPeerRegister() }) +var lastLogOffset = 0 +async function showLog(){ + fetch('/readfileoffset/onionr.log?offset=' + lastLogOffset, { + method: 'GET', + headers: { + "token": webpass + }}) + .then((resp) => resp.json()) + .then(function(resp){ + lastLogOffset = resp['new_offset'] + document.getElementById('logfileOutput').innerText += resp.data.replace( + /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '') + }) +} + + function sidebarAddPeerRegister(){ document.getElementById('addPeerBtn').onclick = function(){ let newPeer = document.getElementById('addPeerInput').value @@ -55,12 +71,18 @@ function sidebarAddPeerRegister(){ } window.addEventListener("keydown", function(event) { + var refreshSideBarInterval = null + document.getElementsByClassName('closeSidebar')[0].onclick = function(){ + clearInterval(sidebarLogInterval) + clearInterval(refreshSideBarInterval) + } if (event.key === "s"){ if (document.activeElement.nodeName == "TEXTAREA" || document.activeElement.nodeName == "INPUT"){ if (! document.activeElement.hasAttribute("readonly")){ return } } + sidebarLogInterval = setInterval(function(){showLog()}, 1000) let refreshSideBar = function(){ if (document.hidden){return} var existingValue = document.getElementById("insertingBlocks").innerText @@ -99,7 +121,7 @@ window.addEventListener("keydown", function(event) { document.getElementById("uploadBlocks").innerText = resp.split(',').length - 1 }) } - setInterval(refreshSideBar, 3000) + refreshSideBarInterval = setInterval(refreshSideBar, 3000) setTimeout(function(){document.getElementsByClassName('sidebarBtn')[0].click()}, 300) } diff --git a/tests/test_read_offset.py b/tests/test_read_offset.py index b7832667..ba411db7 100644 --- a/tests/test_read_offset.py +++ b/tests/test_read_offset.py @@ -16,6 +16,15 @@ createdirs.create_dirs() setup_config() class TestReadOffset(unittest.TestCase): + def test_read_offset(self): + temp = tempfile.mkstemp()[1] + f = open(temp, 'wb') + data = b"test1\ntest2\ntest3\test4" + f.write(data) + f.close() + self.assertEqual(readoffset.read_from_offset(temp, 5).data, data[5:]) + self.assertEqual(readoffset.read_from_offset(temp, 5).new_offset, len(data)) + os.remove(temp) def test_read_whole(self): temp = tempfile.mkstemp()[1] f = open(temp, 'wb') @@ -23,6 +32,7 @@ class TestReadOffset(unittest.TestCase): f.write(data) f.close() self.assertEqual(readoffset.read_from_offset(temp).data, data) + self.assertEqual(readoffset.read_from_offset(temp).new_offset, len(data)) os.remove(temp)