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(";"))
|
.filter(line => line.includes(";"))
|
||||||
.map(line => {
|
.map(line => {
|
||||||
const [hash, filename] = line.split(";");
|
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 {
|
return {
|
||||||
url: `${IMAGE_BASE_URL.replace(/\/$/, "")}/${filename.trim()}`,
|
url: `${IMAGE_BASE_URL.replace(/\/$/, "")}/${filename.trim()}`,
|
||||||
name: filename.trim(),
|
name: filename.trim(),
|
||||||
hash: hash,
|
hash: hash,
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.filter(Boolean); // Remove nulls from skipped items
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getImages;
|
module.exports = getImages;
|
||||||
|
|||||||
Reference in New Issue
Block a user