mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-12-26 23:26:47 +01:00
Revise updateBlocklist() w/ more robust error handling
This commit is contained in:
@@ -730,22 +730,68 @@ function setHardwareModeTooltip() {
|
||||
* Interface elements are updated to indicate current progress, status.
|
||||
*/
|
||||
function updateBlocklist() {
|
||||
var opt = $('#cbxblocklist option:selected');
|
||||
var blocklist_id = opt.val();
|
||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||
if (blocklist_id == '') { return; }
|
||||
$('#cbxblocklist-status').find('i').removeClass('fas fa-check').addClass('fas fa-cog fa-spin');
|
||||
$('#cbxblocklist-status').removeClass('check-hidden').addClass('check-progress');
|
||||
$.post('ajax/adblock/update_blocklist.php',{ 'blocklist_id':blocklist_id, 'csrf_token': csrfToken},function(data){
|
||||
var jsonData = JSON.parse(data);
|
||||
if (jsonData['return'] == '0') {
|
||||
$('#cbxblocklist-status').find('i').removeClass('fas fa-cog fa-spin').addClass('fas fa-check');
|
||||
$('#cbxblocklist-status').removeClass('check-progress').addClass('check-updated').delay(500).animate({ opacity: 1 }, 700);
|
||||
$('#blocklist-'+jsonData['list']).text("Just now");
|
||||
const opt = $('#cbxblocklist option:selected');
|
||||
const blocklist_id = opt.val();
|
||||
const csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||
|
||||
if (blocklist_id === '') return;
|
||||
|
||||
const statusIcon = $('#cbxblocklist-status').find('i');
|
||||
const statusWrapper = $('#cbxblocklist-status');
|
||||
|
||||
statusIcon.removeClass('fa-check fa-exclamation-triangle').addClass('fa-cog fa-spin');
|
||||
statusWrapper.removeClass('check-hidden check-error check-updated').addClass('check-progress');
|
||||
|
||||
$.post('ajax/adblock/update_blocklist.php', {
|
||||
'blocklist_id': blocklist_id,
|
||||
'csrf_token': csrfToken
|
||||
}, function (data) {
|
||||
let jsonData;
|
||||
try {
|
||||
jsonData = JSON.parse(data);
|
||||
} catch (e) {
|
||||
showError("Unexpected server response.");
|
||||
return;
|
||||
}
|
||||
})
|
||||
const resultCode = jsonData['return'];
|
||||
const output = jsonData['output']?.join('\n') || '';
|
||||
|
||||
switch (resultCode) {
|
||||
case 0:
|
||||
statusIcon.removeClass('fa-cog fa-spin').addClass('fa-check');
|
||||
statusWrapper.removeClass('check-progress').addClass('check-updated').delay(500).animate({ opacity: 1 }, 700);
|
||||
$('#blocklist-' + jsonData['list']).text("Just now");
|
||||
break;
|
||||
case 1:
|
||||
showError("Invalid blocklist.");
|
||||
break;
|
||||
case 2:
|
||||
showError("No blocklist provided.");
|
||||
break;
|
||||
case 3:
|
||||
showError("Could not parse blocklists.json.");
|
||||
break;
|
||||
case 4:
|
||||
showError("blocklists.json file not found.");
|
||||
break;
|
||||
case 5:
|
||||
showError("Update script not found.");
|
||||
break;
|
||||
default:
|
||||
showError("Unknown error occurred.");
|
||||
}
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
showError(`AJAX request failed: ${textStatus}`);
|
||||
});
|
||||
|
||||
function showError(message) {
|
||||
statusIcon.removeClass('fa-cog fa-spin').addClass('fa-exclamation-triangle');
|
||||
statusWrapper.removeClass('check-progress').addClass('check-error');
|
||||
alert("Blocklist update failed:\n\n" + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function clearBlocklistStatus() {
|
||||
$('#cbxblocklist-status').removeClass('check-updated').addClass('check-hidden');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user