Bugfix: only use cache with no additional blocklists

This commit is contained in:
TC
2020-12-06 17:55:51 +01:00
parent 3022facbea
commit 467171a17e
2 changed files with 11 additions and 13 deletions

View File

@ -1,4 +1,4 @@
const { existsSync, promises, unlinkSync } = require("fs"); // used for caching
const { promises } = require("fs"); // used for caching
const path = require("path");
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
@ -13,17 +13,15 @@ const loadAdBlockerEngine = (
cache = true,
additionalBlockLists = []
) => {
const adBlockerCache = path.resolve(__dirname, "ad-blocker-engine.bin");
if (!cache && existsSync(adBlockerCache)) {
unlinkSync(adBlockerCache);
}
const cachingOptions = cache
? {
path: adBlockerCache,
read: promises.readFile,
write: promises.writeFile,
}
: undefined;
// Only use cache if no additional blocklists are passed
const cachingOptions =
cache && additionalBlockLists.length === 0
? {
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
read: promises.readFile,
write: promises.writeFile,
}
: undefined;
ElectronBlocker.fromLists(
fetch,