From aa7cec1e1574826e5067a253e27a29eff1006cac Mon Sep 17 00:00:00 2001 From: mrrfv Date: Mon, 11 Sep 2023 18:42:36 +0200 Subject: [PATCH 1/2] Warn if using an unsupported Node version --- lib/helpers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/helpers.js b/lib/helpers.js index 40c7b14..5fb9e89 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,6 +1,10 @@ import { ACCOUNT_EMAIL, ACCOUNT_ID, API_HOST, API_TOKEN } from "./constants.js"; if (!globalThis.fetch) { + console.warn("\nIMPORTANT: Your Node.js version doesn't have native fetch support and may not be supported in the future. Please update to v18 or later.\n") + // Advise what to do if running in GitHub Actions + if (process.env.GITHUB_WORKSPACE) console.warn("Since you're running in GitHub Actions, you should update your Actions workflow configuration to use Node v18 or higher.") + // Import node-fetch since there's no native fetch in this environment globalThis.fetch = (await import("node-fetch")).default; } From 27f6e9f0d3a72d381e1bc752d0a7dceba27b4671 Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Sun, 17 Sep 2023 19:55:43 +0700 Subject: [PATCH 2/2] added code comments --- cf_list_create.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cf_list_create.js b/cf_list_create.js index fb0e81b..3671642 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -55,22 +55,32 @@ await readFile(resolve(blocklistFilename), (line, rl) => { if (!_line) return; + // Check if the current line is a comment in any format if (isComment(_line)) return; + // Remove prefixes and suffixes in hosts, wildcard or adblock format const domain = normalizeDomain(_line); + // Check if it is a valid domain which is not a URL or does not contain + // characters like * in the middle of the domain if (!isValidDomain(domain)) return; processedDomainCount++; + // Get all the levels of the domain and check from the highest + // because we are blocking all subdomains + // Example: fourth.third.example.com => ["example.com", "third.example.com", "fourth.third.example.com"] const anyDomainExists = extractDomain(domain) .reverse() .some((item) => { if (blocklist.has(item)) { if (item === domain) { + // The exact domain is already blocked console.log(`Found ${item} in blocklist already - Skipping`); duplicateDomainCount++; } else { + // The higher-level domain is already blocked + // so it's not necessary to block this domain console.log( `Found ${item} in blocklist already - Skipping ${domain}` );