Make server logs call API

This commit is contained in:
amcmanu3 2023-09-04 13:54:24 -04:00
parent 16e01aed85
commit 10f696edcc
3 changed files with 52 additions and 25 deletions

View File

@ -74,6 +74,6 @@ class ApiServersServerLogsHandler(BaseApiHandler):
if use_html:
for line in lines:
self.write(f"{line}<br />")
else:
line = f"{line}<br />"
self.finish_json(200, {"status": "ok", "data": lines})

View File

@ -188,23 +188,36 @@
// Populate logs and filter if present
const serverId = new URLSearchParams(document.location.search).get('id')
function get_server_log() {
async function get_server_log() {
var token = getCookie("_xsrf")
let colors=true;
if (!$("#stop_scroll").is(':checked')) {
$.ajax({
type: 'GET',
url: '/ajax/server_log?id=' + serverId + '&full=1',
dataType: 'text',
success: function (data) {
let res = await fetch(`/api/v2/servers/${serverId}/logs?colors=${colors}`, {
method: 'GET',
headers: {
'X-XSRFToken': token
},
});
let responseData = await res.json();
html = ``
if (responseData.status === "ok") {
for(i=0; i < responseData.data.length; i++) {
html += `<span class='box'>${responseData.data[i]}<br /></span>`
}
console.log('Got Log From Server')
$('#virt_console').html(data);
$('#virt_console').html(html);
scroll();
lines = document.querySelectorAll('.box');
hideFilteredWords();
},
} else {
bootbox.alert({
title: responseData.status,
message: responseData.error
});
}
}
}
$(document).ready(function () {
console.log("ready!");
get_server_log();

View File

@ -229,17 +229,31 @@
}
//{% end %}
function get_server_log() {
$.ajax({
type: 'GET',
url: '/ajax/server_log?id=' + serverId,
dataType: 'text',
success: function (data) {
console.log('Got Log From Server')
$('#virt_console').html(data);
scrollConsole();
async function get_server_log() {
var token = getCookie("_xsrf")
let colors=true;
let res = await fetch(`/api/v2/servers/${serverId}/logs?colors=${colors}`, {
method: 'GET',
headers: {
'X-XSRFToken': token
},
});
let responseData = await res.json();
html = ``
if (responseData.status === "ok") {
for(i=0; i < responseData.data.length; i++) {
html += `<span class='box'>${responseData.data[i]}<br /></span>`
}
console.log('Got Log From Server')
$('#virt_console').html(html);
scrollConsole();
} else {
bootbox.alert({
title: responseData.status,
message: responseData.error
});
}
}