From 64c99e8e6fccd43d5a83de56d8235639d1aca9c2 Mon Sep 17 00:00:00 2001 From: jihad Date: Wed, 25 Sep 2024 04:34:26 +0300 Subject: [PATCH] using image names instead of index --- mkbsd.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mkbsd.js b/mkbsd.js index d02593a..5ef5ac7 100644 --- a/mkbsd.js +++ b/mkbsd.js @@ -24,19 +24,18 @@ async function main() { fs.mkdirSync(downloadDir); console.info(`📁 Created directory: ${downloadDir}`); } - let fileIndex = 1; + for (const key in data) { const subproperty = data[key]; if (subproperty && subproperty.dhd) { const imageUrl = subproperty.dhd; console.info(`🔍 Found image URL!`); await delay(100); - const ext = path.extname(new URL(imageUrl).pathname) || '.jpg'; - const filename = `${fileIndex}${ext}`; + // Extract the actual filename from the URL + const filename = path.basename(new URL(imageUrl).pathname); const filePath = path.join(downloadDir, filename); await downloadImage(imageUrl, filePath); console.info(`🖼️ Saved image to ${filePath}`); - fileIndex++; await delay(250); } }