diff --git a/client/mixins/uploadHelpers.js b/client/mixins/uploadHelpers.js index cc4b1997..2d7a554f 100644 --- a/client/mixins/uploadHelpers.js +++ b/client/mixins/uploadHelpers.js @@ -28,11 +28,11 @@ export default { var validOtherFiles = [] var ignoredFiles = [] files.forEach((file) => { - var filetype = this.checkFileType(file.name) - if (!filetype) ignoredFiles.push(file) + // var filetype = this.checkFileType(file.name) + if (!file.filetype) ignoredFiles.push(file) else { - file.filetype = filetype - if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file) + // file.filetype = filetype + if (file.filetype === 'audio' || (file.filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file) else validOtherFiles.push(file) } }) @@ -82,12 +82,18 @@ export default { items: itemResults, ignoredFiles: ignoredFilesInRoot } - } else { + } else if (filetree.some((f) => f.filetype !== 'audio') || mediaType !== 'book') { // Single Book drop return { items: this.itemFromTreeItems(filetree, mediaType), ignoredFiles: [] } + } else { + // Only audio files dropped so treat each one as an audiobook + return { + items: filetree.map((audioFile) => ({ itemFiles: [audioFile], otherFiles: [], ignoredFiles: [] })), + ignoredFiles: [] + } } }, getFilesDropped(dataTransferItems) { @@ -95,11 +101,12 @@ export default { path: '/', items: [] } - function traverseFileTreePromise(item, currtreemap) { + function traverseFileTreePromise(item, currtreemap, checkFileType) { return new Promise((resolve) => { if (item.isFile) { item.file((file) => { file.filepath = currtreemap.path + file.name //save full path + file.filetype = checkFileType(file.name) currtreemap.items.push(file) resolve(file) }) @@ -119,7 +126,7 @@ export default { dirReader.readEntries((entries) => { if (entries.length > 0) { for (let entr of entries) { - entriesPromises.push(traverseFileTreePromise(entr, newtreemap)) + entriesPromises.push(traverseFileTreePromise(entr, newtreemap, checkFileType)) } readEntries() } else { @@ -135,7 +142,7 @@ export default { return new Promise((resolve, reject) => { let entriesPromises = [] for (let it of dataTransferItems) { - var filetree = traverseFileTreePromise(it.webkitGetAsEntry(), treemap) + var filetree = traverseFileTreePromise(it.webkitGetAsEntry(), treemap, this.checkFileType) entriesPromises.push(filetree) } Promise.all(entriesPromises).then(() => { @@ -152,7 +159,9 @@ export default { ...book } var firstBookFile = book.itemFiles[0] - if (!firstBookFile.filepath) return audiobook // No path + if (!firstBookFile.filepath) { + return audiobook // No path + } var firstBookPath = Path.dirname(firstBookFile.filepath) @@ -165,6 +174,9 @@ export default { if (dirs.length) { audiobook.author = dirs.pop() } + } else { + // Use file basename as title + audiobook.title = Path.basename(firstBookFile.name, Path.extname(firstBookFile.name)) } return audiobook }, @@ -178,7 +190,12 @@ export default { if (!firstAudioFile.filepath) return podcast // No path var firstPath = Path.dirname(firstAudioFile.filepath) var dirs = firstPath.split('/').filter(d => !!d && d !== '.') - podcast.title = dirs.length > 1 ? dirs[1] : dirs[0] + if (dirs.length) { + podcast.title = dirs.length > 1 ? dirs[1] : dirs[0] + } else { + podcast.title = Path.basename(firstAudioFile.name, Path.extname(firstAudioFile.name)) + } + return podcast }, cleanItem(item, mediaType, index) { @@ -188,6 +205,7 @@ export default { async getItemsFromDataTransferItems(dataTransferItems, mediaType) { var files = await this.getFilesDropped(dataTransferItems) if (!files || !files.length) return { error: 'No files found ' } + var itemData = this.fileTreeToItems(files, mediaType) if (!itemData.items.length && !itemData.ignoredFiles.length) { return { error: 'Invalid file drop' } @@ -218,9 +236,12 @@ export default { else { file.filetype = filetype if (file.webkitRelativePath) file.filepath = file.webkitRelativePath + else file.filepath = file.name if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) { var dir = file.filepath ? Path.dirname(file.filepath) : '' + if (dir === '.') dir = '' + if (!itemMap[dir]) { itemMap[dir] = { path: dir, @@ -246,8 +267,17 @@ export default { } }) + var items = [] var index = 1 - var items = Object.values(itemMap).map(i => this.cleanItem(i, mediaType, index++)) + // If book media type and all files are audio files then treat each one as an audiobook + if (itemMap[''] && !otherFiles.length && mediaType === 'book' && !itemMap[''].itemFiles.some(f => f.filetype !== 'audio')) { + items = itemMap[''].itemFiles.map((audioFile) => { + return this.cleanItem({ itemFiles: [audioFile], otherFiles: [], ignoredFiles: [] }, mediaType, index++) + }) + } else { + items = Object.values(itemMap).map(i => this.cleanItem(i, mediaType, index++)) + } + return { items, ignoredFiles: ignoredFiles diff --git a/client/pages/upload/index.vue b/client/pages/upload/index.vue index e4dd8311..3abce01d 100644 --- a/client/pages/upload/index.vue +++ b/client/pages/upload/index.vue @@ -29,7 +29,9 @@
Supported File Types: {{ inputAccept.join(', ') }}
+Supported File Types: {{ inputAccept.join(', ') }}
+ +Folders with media files will be treated as separate library items. If uploading only audio files then each audio file will be treated as a separate audiobook.