Fix getImages function: skip non-existent folders and filter out null results

This commit is contained in:
2025-07-23 19:18:09 +00:00
parent 0c253268ea
commit 48ab2804bf

View File

@@ -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;