MCPcopy Index your code
hub / github.com/ClearURLs/Addon / fetchFromURL

Function fetchFromURL

clearurls.js:299–328  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

297 * ##################################################################
298 */
299 function fetchFromURL() {
300 const response = fetch(storage.ruleURL).then(async response => {
301 return {
302 data: (await response.clone().text()).trim(),
303 hash: await sha256((await response.text()).trim()),
304 status: response.status
305 }
306 })
307
308 response.then(result => {
309 if (result.status === 200 && result.data) {
310 if (result.hash === dataHash.trim()) {
311 storage.ClearURLsData = result.data;
312 storage.dataHash = result.hash;
313 storeHashStatus(2);
314 } else {
315 storeHashStatus(3);
316 console.error("The hash does not match. Expected `" + result.hash + "` got `" + dataHash.trim() + "`");
317 }
318 storage.ClearURLsData = JSON.parse(storage.ClearURLsData);
319 toObject(storage.ClearURLsData);
320 saveOnDisk(['ClearURLsData', 'dataHash', 'hashStatus']);
321 } else {
322 throw "The status code was not okay or the given rules were empty."
323 }
324 }).catch(error => {
325 console.error("[ClearURLs]: Could not download the rules from the given URL due to the following error: ", error);
326 deactivateOnFailure();
327 });
328 }
329
330 // ##################################################################
331

Callers 1

getHashFunction · 0.85

Calls 5

sha256Function · 0.85
storeHashStatusFunction · 0.85
toObjectFunction · 0.85
saveOnDiskFunction · 0.85
deactivateOnFailureFunction · 0.85

Tested by

no test coverage detected