`;
document.getElementById('cache').innerHTML = html;
add_to_cache_log('Creating new cache request. Maximum ' + days + ' days.')
get_stats(days);
}
function cache_log(days, result, complete) {
if(result) {
add_to_cache_log('Completed caching with a maximum of ' + days + ' days.', false, '');
} else {
add_to_cache_log('Error caching ' + days + ' days. Stopping.', true, 'var(--red)');
document.getElementById('loading_icon').style.display = "none";
document.getElementById("cache_button").disabled = false;
document.getElementById("cache_button").style.opacity = '1';
}
if(complete) {
add_to_cache_log('Finished caching request.', true, 'var(--green)');
document.getElementById('loading_icon').style.display = "none";
document.getElementById("cache_button").disabled = false;
document.getElementById("cache_button").style.opacity = '1';
} else {
add_to_cache_log('Requesting new cache from Wrapperr. Maximum ' + days + ' days.', false, '');
}
var cache_results = document.getElementById("cache_results");
cache_results.scrollTop = cache_results.scrollHeight;
}
function get_stats(days) {
document.getElementById("cache_button").disabled = true;
document.getElementById("cache_button").style.opacity = '0.5';
stats_form = {
"caching" : true,
"cache_limit" : days
};
var stats_data = JSON.stringify(stats_form);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
try {
var result= JSON.parse(this.responseText);
} catch(error) {
if(this.responseText.includes('Maximum execution time of')) {
cache_log(days, false, true);
document.getElementById("cache_button").disabled = false;
document.getElementById("cache_button").style.opacity = '1';
alert('PHP runtime was exceeded and stopped execution. Lower days cached to prevent this.');
console.log('Failed to parse API response. Error: ' + this.responseText);
} else {
cache_log(days, false, true);
alert('Failed to parse API response.');
console.log('Failed to parse API response. Error: ' + this.responseText);
document.getElementById("cache_button").disabled = false;
document.getElementById("cache_button").style.opacity = '1';
}
return;
}
if(result.error) {
alert(result.error);
cache_log(days, false, true);
} else {
if(!result.data) {
cache_log(days, true, result.data);
get_stats(days);
} else {
cache_log(days, true, result.data);
}
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", api_url + "get/statistics", );
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", cookie);
xhttp.send(stats_data);
return;
}