fix: don't crash if profile folder doesn't exist

This commit is contained in:
Barış Soner Uşaklı
2024-10-23 11:25:32 -04:00
parent e780120a62
commit 8a89c5d759

View File

@@ -19,9 +19,15 @@ module.exports = {
const folder = path.join(nconf.get('upload_path'), 'profile'); const folder = path.join(nconf.get('upload_path'), 'profile');
const userPicRegex = /^\d+-profile/; const userPicRegex = /^\d+-profile/;
const files = (await fs.promises.readdir(folder, { withFileTypes: true })) let files = [];
try {
files = (await fs.promises.readdir(folder, { withFileTypes: true }))
.filter(item => !item.isDirectory() && String(item.name).match(userPicRegex)) .filter(item => !item.isDirectory() && String(item.name).match(userPicRegex))
.map(item => item.name); .map(item => item.name);
} catch (err) {
console.error(err.stack);
return;
}
progress.total = files.length; progress.total = files.length;
await batch.processArray(files, async (files) => { await batch.processArray(files, async (files) => {