Catch update complete + error states

This commit is contained in:
billz 2023-11-23 07:54:38 +00:00
parent 37dcaa41f1
commit f6d7e9a2d1
2 changed files with 21 additions and 13 deletions

View file

@ -262,7 +262,3 @@ button > i.fas {
border-bottom-right-radius: 0.35rem;
}
.cmd-copy {
width: 95%;
height: 6rem;
}

View file

@ -320,27 +320,39 @@ $('#performupdateModal').on('shown.bs.modal', function (e) {
function fetchUpdateResponse() {
const xhr = new XMLHttpRequest();
const complete = 6;
const error = 7;
let phpFile = 'ajax/system/sys_read_logfile.php';
$.ajax({
url: phpFile,
type: 'GET',
success: function(response) {
let endPolling = false;
for (let i = 1; i <= 6; i++) {
let divId = '#updateStep' + i;
if (response.includes(i)) {
if (response.includes(i.toString())) {
$(divId).removeClass('invisible');
if (response.includes('6')) {
$('#updateStep6').removeClass('invisible');
$('#updateSync2').removeClass("fa-spin");
break;
} else {
setTimeout(fetchUpdateResponse, 1000);
}
}
if (response.includes(complete)) {
$('#updateStep6').removeClass('invisible');
$('#updateSync2').removeClass("fa-spin");
endPolling = true;
break;
} else if (response.includes(error)) {
var errorMsg = $('#errorMsg').data('message');
$('#updateErr').after('<span class="small">' + errorMsg + '</span>');
$('#updateErr').removeClass('invisible');
$('#updateSync2').removeClass("fa-spin");
endPolling = true;
break;
}
}
if (!endPolling) {
setTimeout(fetchUpdateResponse, 500);
}
},
error: function(xhr, status, error) {
setTimeout(fetchUpdateResponse, 1000);
console.error(error);
}
});
}