From c2b0510cfc009ca3b5dfb7bd683bf0b21963833e Mon Sep 17 00:00:00 2001 From: Viet Huynh Date: Fri, 29 Sep 2023 06:44:19 +0700 Subject: [PATCH] remove existing lists before downloading --- download_lists.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/download_lists.js b/download_lists.js index 3f04054..fb0d952 100644 --- a/download_lists.js +++ b/download_lists.js @@ -1,3 +1,5 @@ +import { existsSync } from "fs"; +import { unlink } from "fs/promises"; import { resolve } from "path"; import { @@ -15,7 +17,13 @@ const blocklistUrls = USER_DEFINED_BLOCKLIST_URLS || RECOMMENDED_BLOCKLIST_URLS; const listType = process.argv[2]; const downloadLists = async (filename, urls) => { - await downloadFiles(resolve(`./${filename}`), urls); + const filePath = resolve(`./${filename}`); + + if (existsSync(filePath)) { + await unlink(filePath); + } + + await downloadFiles(filePath, urls); console.log( `Done. The ${filename} file contains merged data from the following list(s):` );