fix logic

This commit is contained in:
Vito0912 2025-06-12 12:26:26 +02:00
parent 11cc9f2562
commit ce3c08c11c
No known key found for this signature in database
GPG key ID: 29A3D509FE70B237
3 changed files with 34 additions and 31 deletions

View file

@ -598,8 +598,6 @@ module.exports.validatePathExists = async function validatePathExists(
return null;
}
console.log(`[FileSystemController] Checking if path exists: "${filepath}"`);
if (await fs.pathExists(filepath)) {
if (filenames && filenames.length > 0) {
// If any filename exists, not allowed to upload (exists: true)
@ -611,30 +609,32 @@ module.exports.validatePathExists = async function validatePathExists(
};
}
}
} } else if (allowBookFiles || allowAudioFiles) {
let restrictedExtensions = [];
if (allowBookFiles && !allowAudioFiles) {
restrictedExtensions = globals.SupportedAudioTypes; // Block audio files
} else if (allowAudioFiles && !allowBookFiles) {
restrictedExtensions = globals.SupportedEbookTypes; // Block book files
}
console.log(`[FileSystemController] Checking for restricted files in "${filepath}" with extensions: ${restrictedExtensions.join(', ')}`);
if (restrictedExtensions.length > 0) {
const files = await fs.readdir(filepath);
const hasRestrictedFiles = files.some((file) => {
const ext = Path.extname(file).toLowerCase().replace(/^\./, "");
return restrictedExtensions.includes(ext);
});
if (hasRestrictedFiles) {
return { exists: true };
if (allowBookFiles || allowAudioFiles) {
let restrictedExtensions = [];
if (allowBookFiles && !allowAudioFiles) {
restrictedExtensions = globals.SupportedAudioTypes;
} else if (allowAudioFiles && !allowBookFiles) {
restrictedExtensions = globals.SupportedEbookTypes;
} else {
restrictedExtensions = []
}
if (restrictedExtensions.length > 0) {
const files = await fs.readdir(filepath);
const hasRestrictedFiles = files.some((file) => {
const ext = Path.extname(file).toLowerCase().replace(/^\./, "");
return restrictedExtensions.includes(ext);
});
if (hasRestrictedFiles) {
return { exists: true };
}
} else {
return {
exists: true,
};
}
} else {
return {
exists: true,
};
}
}