now shows log in sidebar

This commit is contained in:
Kevin Froman 2020-10-17 09:54:29 +00:00
parent c23b286540
commit 60c7e6cb37
3 changed files with 35 additions and 2 deletions

View File

@ -1,6 +1,6 @@
<div id="quickviewDefault" class="quickview">
<header class="quickview-header">
<span class="delete" data-dismiss="quickview"></span>
<span class="delete closeSidebar" data-dismiss="quickview"></span>
</header>
<div class="quickview-body">
@ -20,6 +20,7 @@
Add Peer
</a>
</div>
<pre id="logfileOutput"></pre>
</div>
</div>
</div>

View File

@ -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)
}

View File

@ -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)