diff --git a/cf_list_create.js b/cf_list_create.js index b57afea..e079709 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -10,6 +10,7 @@ import { FAST_MODE, LIST_ITEM_LIMIT, LIST_ITEM_SIZE, + PROCESSING_FILENAME, } from "./lib/constants.js"; import { normalizeDomain } from "./lib/helpers.js"; import { @@ -19,12 +20,12 @@ import { readFile, } from "./lib/utils.js"; -const allowlistFilename = existsSync("whitelist.csv") - ? "whitelist.csv" - : "allowlist.txt"; -const blocklistFilename = existsSync("input.csv") - ? "input.csv" - : "blocklist.txt"; +const allowlistFilename = existsSync(PROCESSING_FILENAME.OLD_ALLOWLIST) + ? PROCESSING_FILENAME.OLD_ALLOWLIST + : PROCESSING_FILENAME.ALLOWLIST; +const blocklistFilename = existsSync(PROCESSING_FILENAME.OLD_BLOCKLIST) + ? PROCESSING_FILENAME.OLD_BLOCKLIST + : PROCESSING_FILENAME.BLOCKLIST; const allowlist = new Map(); const blocklist = new Map(); const domains = []; diff --git a/download_lists.js b/download_lists.js index ee6c082..56e4a19 100644 --- a/download_lists.js +++ b/download_lists.js @@ -1,5 +1,6 @@ import { resolve } from "path"; +import { LIST_TYPE, PROCESSING_FILENAME } from "./lib/constants.js"; import { downloadFiles } from "./lib/utils.js"; const allowlistUrls = [ @@ -40,25 +41,31 @@ const blocklistUrls = [ const listType = process.argv[2]; const downloadAllowlists = async () => { - await downloadFiles(resolve("./allowlist.txt"), allowlistUrls); + await downloadFiles( + resolve(`./${PROCESSING_FILENAME.ALLOWLIST}`), + allowlistUrls + ); console.log( - "Done. The allowlist.txt file contains merged data from recommended whitelists." + `Done. The ${PROCESSING_FILENAME.ALLOWLIST} file contains merged data from recommended allowlists.` ); }; const downloadBlocklists = async () => { - await downloadFiles(resolve("./blocklist.txt"), blocklistUrls); + await downloadFiles( + resolve(`./${PROCESSING_FILENAME.BLOCKLIST}`), + blocklistUrls + ); console.log( - "Done. The blocklist.txt file contains merged data from recommended filter lists." + `Done. The ${PROCESSING_FILENAME.BLOCKLIST} file contains merged data from recommended blocklists.` ); }; switch (listType) { - case "allowlist": { + case LIST_TYPE.ALLOWLIST: { await downloadAllowlists(); break; } - case "blocklist": { + case LIST_TYPE.BLOCKLIST: { await downloadBlocklists(); break; } diff --git a/lib/constants.js b/lib/constants.js index 5a77df5..9d5e124 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -19,3 +19,15 @@ export const API_HOST = "https://api.cloudflare.com/client/v4"; export const DRY_RUN = !!parseInt(process.env.DRY_RUN, 10); export const FAST_MODE = !!parseInt(process.env.FAST_MODE, 10); + +export const PROCESSING_FILENAME = { + ALLOWLIST: "allowlist.txt", + BLOCKLIST: "blocklist.txt", + OLD_ALLOWLIST: "whitelist.csv", + OLD_BLOCKLIST: "input.csv", +}; + +export const LIST_TYPE = { + ALLOWLIST: "allowlist", + BLOCKLIST: "blocklist", +}; diff --git a/lib/helpers.js b/lib/helpers.js index 93e6ed0..702b4f3 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,9 +1,14 @@ 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") + 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.") + 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; } @@ -48,7 +53,7 @@ export const requestGateway = (path, options) => /** * Normalizes a domain. * @param {string} value The value to be normalized. - * @param {boolean} isAllowlisting Whether the value is to be whitelisted. + * @param {boolean} isAllowlisting Whether the value is to be allowlisted. * @returns {string} */ export const normalizeDomain = (value, isAllowlisting) => {