Fix getImages function: skip non-existent folders and filter out null results
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user