mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 01:18:59 +02:00
fix logic
This commit is contained in:
parent
11cc9f2562
commit
ce3c08c11c
@ -91,6 +91,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Path from 'path'
|
import Path from 'path'
|
||||||
import uploadHelpers from '@/mixins/uploadHelpers'
|
import uploadHelpers from '@/mixins/uploadHelpers'
|
||||||
|
import globals from '../../../server/utils/globals'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [uploadHelpers],
|
mixins: [uploadHelpers],
|
||||||
@ -359,8 +360,11 @@ export default {
|
|||||||
// Check if path already exists before starting upload
|
// Check if path already exists before starting upload
|
||||||
// uploading fails if path already exists
|
// uploading fails if path already exists
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
const containsBook = item.files.some(file => globals.SupportedEbookTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
||||||
|
const containsAudio = item.files.some(file => globals.SupportedAudioTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
||||||
|
|
||||||
const exists = await this.$axios
|
const exists = await this.$axios
|
||||||
.$post(`/api/filesystem/pathexists`, { directory: item.directory, folderPath: this.selectedFolder.fullPath, filenames: item.files.map((f) => f.name) })
|
.$post(`/api/filesystem/pathexists`, { directory: item.directory, folderPath: this.selectedFolder.fullPath, filenames: item.files.map((f) => f.name), allowBookFiles: !containsBook, allowAudioFiles: !containsAudio })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.exists) {
|
if (data.exists) {
|
||||||
if (data.libraryItemTitle) {
|
if (data.libraryItemTitle) {
|
||||||
|
@ -44,7 +44,8 @@ class MiscController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const files = Object.values(req.files)
|
const files = Object.values(req.files)
|
||||||
let { title, author, series, folder: folderId, library: libraryId } = req.body
|
// If allowAdditionalFiles the upload endpoint allows adding items even if the type of file already exists in the library.
|
||||||
|
let { title, author, series, folder: folderId, library: libraryId, allowAdditionalFiles } = req.body
|
||||||
// Validate request body
|
// Validate request body
|
||||||
if (!libraryId || !folderId || typeof libraryId !== 'string' || typeof folderId !== 'string' || !title || typeof title !== 'string') {
|
if (!libraryId || !folderId || typeof libraryId !== 'string' || typeof folderId !== 'string' || !title || typeof title !== 'string') {
|
||||||
return res.status(400).send('Invalid request body')
|
return res.status(400).send('Invalid request body')
|
||||||
@ -79,12 +80,10 @@ class MiscController {
|
|||||||
const cleanedOutputDirectoryParts = outputDirectoryParts.filter(Boolean).map((part) => sanitizeFilename(part))
|
const cleanedOutputDirectoryParts = outputDirectoryParts.filter(Boolean).map((part) => sanitizeFilename(part))
|
||||||
const outputDirectory = Path.join(...[folder.path, ...cleanedOutputDirectoryParts])
|
const outputDirectory = Path.join(...[folder.path, ...cleanedOutputDirectoryParts])
|
||||||
|
|
||||||
const containsBook = files.some(file => globals.SupportedEbookTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
const containsBook = allowAdditionalFiles || files.some(file => globals.SupportedEbookTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
||||||
const containsAudio = files.some(file => globals.SupportedAudioTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
const containsAudio = allowAdditionalFiles || files.some(file => globals.SupportedAudioTypes.includes(Path.extname(file.name).toLowerCase().slice(1)))
|
||||||
|
|
||||||
console.log(`Uploading files to ${outputDirectory} with containsBook: ${containsBook}, containsAudio: ${containsAudio}`)
|
if ((await validatePathExists(folder, outputDirectory, files.map((f) => f.name), !containsBook, !containsAudio, true)).exists) {
|
||||||
|
|
||||||
if ((await validatePathExists(folder, outputDirectory, undefined, !containsBook, !containsAudio, true)).exists) {
|
|
||||||
Logger.error(`Upload path already exists: ${outputDirectory}`)
|
Logger.error(`Upload path already exists: ${outputDirectory}`)
|
||||||
return res.status(400).send('Uploaded file already exists')
|
return res.status(400).send('Uploaded file already exists')
|
||||||
}
|
}
|
||||||
|
@ -598,8 +598,6 @@ module.exports.validatePathExists = async function validatePathExists(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[FileSystemController] Checking if path exists: "${filepath}"`);
|
|
||||||
|
|
||||||
if (await fs.pathExists(filepath)) {
|
if (await fs.pathExists(filepath)) {
|
||||||
if (filenames && filenames.length > 0) {
|
if (filenames && filenames.length > 0) {
|
||||||
// If any filename exists, not allowed to upload (exists: true)
|
// 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
|
|
||||||
}
|
}
|
||||||
|
if (allowBookFiles || allowAudioFiles) {
|
||||||
console.log(`[FileSystemController] Checking for restricted files in "${filepath}" with extensions: ${restrictedExtensions.join(', ')}`);
|
let restrictedExtensions = [];
|
||||||
|
if (allowBookFiles && !allowAudioFiles) {
|
||||||
if (restrictedExtensions.length > 0) {
|
restrictedExtensions = globals.SupportedAudioTypes;
|
||||||
const files = await fs.readdir(filepath);
|
} else if (allowAudioFiles && !allowBookFiles) {
|
||||||
const hasRestrictedFiles = files.some((file) => {
|
restrictedExtensions = globals.SupportedEbookTypes;
|
||||||
const ext = Path.extname(file).toLowerCase().replace(/^\./, "");
|
} else {
|
||||||
return restrictedExtensions.includes(ext);
|
restrictedExtensions = []
|
||||||
});
|
}
|
||||||
|
|
||||||
if (hasRestrictedFiles) {
|
if (restrictedExtensions.length > 0) {
|
||||||
return { exists: true };
|
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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user