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 42f9ac5..e9ded8a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,7 +1,8 @@ -import { once } from "events"; -import { ReadStream, createReadStream, createWriteStream } from "fs"; -import { basename } from "path"; -import { createInterface } from "readline"; +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; @@ -12,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 ); @@ -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"); } };