parse download as JSON

Since filters are supposed to be in JSON
This commit is contained in:
buzz-lightsnack-2007 2024-04-02 18:14:21 +08:00
parent 912a36a2f6
commit fe41352afd

View file

@ -4,16 +4,16 @@ Manage filters.
export default class filters { export default class filters {
constructor() { constructor() {
this.all = (async() => { this.all = async () => {
// Import the updater. // Import the updater.
const secretariat = await import( const secretariat = await import(
chrome.runtime.getURL("scripts/secretariat.js") chrome.runtime.getURL("scripts/secretariat.js")
); );
return(secretariat.read(`filters`, -1).then((filters) => { return secretariat.read(`filters`, -1).then((filters) => {
return(filters) return filters;
})); });
}) };
} }
/* Select the most appropriate filter based on a URL. /* Select the most appropriate filter based on a URL.
@ -28,13 +28,16 @@ export default class filters {
); );
// Get the filters. // Get the filters.
let filter = (await secretariat.read(`filters`, -1, {"field": "URL", "test value": URL})); let filter = await secretariat.read(`filters`, -1, {
field: "URL",
"test value": URL,
});
// If there are filters, then filter the URL. // If there are filters, then filter the URL.
return (filter); return filter;
})(); })();
return (this.one); return this.one;
} }
/* Update all filters or just one. /* Update all filters or just one.
@ -101,13 +104,11 @@ export default class filters {
// Inform the user of download state. // Inform the user of download state.
alerts.log( alerts.log(
texts.localized(`settings_filters_update_status`, null, [ texts.localized(`settings_filters_update_status`, null, [filter_URL]),
filter_URL,
]),
); );
// Create promise of downloading. // Create promise of downloading.
let filter_download = net.download(filter_URL); let filter_download = net.download(filter_URL, `JSON`);
filter_download filter_download
.then((result) => { .then((result) => {
// Only work when the filter is valid. // Only work when the filter is valid.
@ -122,16 +123,14 @@ export default class filters {
), ),
); );
} }
}) })
.catch((error) => { .catch((error) => {
// Inform the user of the download failure. // Inform the user of the download failure.
alerts.error( alerts.error(
texts.localized( texts.localized(`settings_filters_update_status_failure`, null, [
`settings_filters_update_status_failure`, error,
null, filter_URL,
[error, filter_URL], ]),
),
); );
}); });
} }
@ -141,8 +140,8 @@ export default class filters {
} }
// Regardless of the download result, update will also mean setting the filters object to whatever is in storage. // Regardless of the download result, update will also mean setting the filters object to whatever is in storage.
this.all = (await secretariat.read(`filters`, -1)); this.all = await secretariat.read(`filters`, -1);
return(this.all); return this.all;
} }
} }