From 8c8d5c70a6546b183854d103534421cb06bb9ad1 Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Tue, 21 Nov 2023 02:57:10 +0700 Subject: [PATCH 1/3] fix list download --- lib/utils.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 42f9ac5..03c9fe9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,7 +1,8 @@ import { once } from "events"; -import { ReadStream, createReadStream, createWriteStream } from "fs"; +import { createReadStream, createWriteStream } from "fs"; import { basename } from "path"; import { createInterface } from "readline"; +import { pipeline } from "stream/promises"; if (!globalThis.fetch) { globalThis.fetch = (await import("node-fetch")).default; @@ -56,11 +57,8 @@ export const downloadFiles = async (filePath, urls) => { for (const response of responses) { const writeStream = createWriteStream(filePath, { flags: "a" }); - ReadStream.from(response.body) - .on("end", () => { - writeStream.write("\n"); - }) - .pipe(writeStream); + await pipeline(response.body, writeStream, { end: false }); + writeStream.end("\n"); } }; From 041970972af4f321273fcdb9f8bd8c0f4597bd96 Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Tue, 21 Nov 2023 02:58:01 +0700 Subject: [PATCH 2/3] use more accurate domain regex pattern --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 03c9fe9..f6b8f86 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -13,7 +13,7 @@ if (!globalThis.fetch) { * @param {string} value The value to be checked. */ export const isValidDomain = (value) => - /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/.test( + /^\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b$/.test( value ); From df2a2d71411376bc8863891e264ca60cb14ba776 Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Tue, 21 Nov 2023 03:00:35 +0700 Subject: [PATCH 3/3] prefix node module import with `node:` --- cf_list_create.js | 4 ++-- download_lists.js | 6 +++--- lib/utils.js | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cf_list_create.js b/cf_list_create.js index bce748b..c9cbaa4 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -1,5 +1,5 @@ -import { existsSync } from "fs"; -import { resolve } from "path"; +import { existsSync } from "node:fs"; +import { resolve } from "node:path"; import { createZeroTrustListsAtOnce, diff --git a/download_lists.js b/download_lists.js index db61951..a43283d 100644 --- a/download_lists.js +++ b/download_lists.js @@ -1,6 +1,6 @@ -import { existsSync } from "fs"; -import { unlink } from "fs/promises"; -import { resolve } from "path"; +import { existsSync } from "node:fs"; +import { unlink } from "node:fs/promises"; +import { resolve } from "node:path"; import { LIST_TYPE, diff --git a/lib/utils.js b/lib/utils.js index f6b8f86..e9ded8a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,8 +1,8 @@ -import { once } from "events"; -import { createReadStream, createWriteStream } from "fs"; -import { basename } from "path"; -import { createInterface } from "readline"; -import { pipeline } from "stream/promises"; +import { once } from "node:events"; +import { createReadStream, createWriteStream } from "node:fs"; +import { basename } from "node:path"; +import { createInterface } from "node:readline"; +import { pipeline } from "node:stream/promises"; if (!globalThis.fetch) { globalThis.fetch = (await import("node-fetch")).default;