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

Function getHash

clearurls.js:264–292  ·  view source on GitHub ↗

* Get the hash for the rule file on GitLab. * Check the hash with the hash form the local file. * If the hash has changed, then download the new rule file. * Else do nothing.

()

Source from the content-addressed store, hash-verified

262 * Else do nothing.
263 */
264 function getHash() {
265 //Get the target hash from GitLab
266 const response = fetch(storage.hashURL).then(async response => {
267 return {
268 hash: (await response.text()).trim(),
269 status: response.status
270 }
271 });
272
273 response.then(result => {
274 if (result.status === 200 && result.hash) {
275 dataHash = result.hash;
276
277 if (dataHash !== localDataHash.trim()) {
278 fetchFromURL();
279 } else {
280 toObject(storage.ClearURLsData);
281 storeHashStatus(1);
282 saveOnDisk(['hashStatus']);
283 }
284 } else {
285 throw "The status code was not okay or the given hash were empty.";
286 }
287 }).catch(error => {
288 console.error("[ClearURLs]: Could not download the rules hash from the given URL due to the following error: ", error);
289 dataHash = false;
290 deactivateOnFailure();
291 });
292 }
293
294 /*
295 * ##################################################################

Callers 1

startFunction · 0.85

Calls 5

fetchFromURLFunction · 0.85
toObjectFunction · 0.85
storeHashStatusFunction · 0.85
saveOnDiskFunction · 0.85
deactivateOnFailureFunction · 0.85

Tested by

no test coverage detected