From 48ab2804bf73a5ea7971ab25412f0b817b4dc79b Mon Sep 17 00:00:00 2001 From: Ryan Hamilton Date: Wed, 23 Jul 2025 19:18:09 +0000 Subject: [PATCH] Fix getImages function: skip non-existent folders and filter out null results --- src/getImages.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/getImages.js b/src/getImages.js index dba4377..615c61f 100644 --- a/src/getImages.js +++ b/src/getImages.js @@ -12,12 +12,17 @@ function getImages() { .filter(line => line.includes(";")) .map(line => { const [hash, filename] = line.split(";"); + const folderPath = `./uploads/${filename.trim()}`; + if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) { + return null; // Skip if folder does not exist + } return { url: `${IMAGE_BASE_URL.replace(/\/$/, "")}/${filename.trim()}`, name: filename.trim(), hash: hash, }; - }); + }) + .filter(Boolean); // Remove nulls from skipped items } module.exports = getImages;