This commit is contained in:
Rasmus Krämer 2022-04-15 12:59:45 +02:00
commit cd274e0844
No known key found for this signature in database
GPG Key ID: EC9E510611BFDAA2
23 changed files with 586 additions and 319 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="relative w-full py-4 px-6 border border-white border-opacity-10 shadow-lg rounded-md my-6"> <div class="relative w-full py-4 px-6 border border-white border-opacity-10 shadow-lg rounded-md my-6">
<div class="absolute -top-3 -left-3 w-8 h-8 bg-bg border border-white border-opacity-10 flex items-center justify-center rounded-full"> <div class="absolute -top-3 -left-3 w-8 h-8 bg-bg border border-white border-opacity-10 flex items-center justify-center rounded-full">
<p class="text-base text-white text-opacity-80 font-mono">#{{ book.index }}</p> <p class="text-base text-white text-opacity-80 font-mono">#{{ item.index }}</p>
</div> </div>
<div v-if="!processing && !uploadFailed && !uploadSuccess" class="absolute -top-3 -right-3 w-8 h-8 bg-bg border border-white border-opacity-10 flex items-center justify-center rounded-full hover:bg-error cursor-pointer" @click="$emit('remove')"> <div v-if="!processing && !uploadFailed && !uploadSuccess" class="absolute -top-3 -right-3 w-8 h-8 bg-bg border border-white border-opacity-10 flex items-center justify-center rounded-full hover:bg-error cursor-pointer" @click="$emit('remove')">
@ -15,15 +15,19 @@
<div class="flex my-2 -mx-2"> <div class="flex my-2 -mx-2">
<div class="w-1/2 px-2"> <div class="w-1/2 px-2">
<ui-text-input-with-label v-model="bookData.title" :disabled="processing" label="Title" @input="titleUpdated" /> <ui-text-input-with-label v-model="itemData.title" :disabled="processing" label="Title" @input="titleUpdated" />
</div> </div>
<div class="w-1/2 px-2"> <div class="w-1/2 px-2">
<ui-text-input-with-label v-model="bookData.author" :disabled="processing" label="Author" /> <ui-text-input-with-label v-if="!isPodcast" v-model="itemData.author" :disabled="processing" label="Author" />
<div v-else class="w-full">
<p class="px-1 text-sm font-semibold">Directory <em class="font-normal text-xs pl-2">(auto)</em></p>
<ui-text-input :value="directory" disabled class="w-full font-mono text-xs" style="height: 38px" />
</div>
</div> </div>
</div> </div>
<div class="flex my-2 -mx-2"> <div v-if="!isPodcast" class="flex my-2 -mx-2">
<div class="w-1/2 px-2"> <div class="w-1/2 px-2">
<ui-text-input-with-label v-model="bookData.series" :disabled="processing" label="Series" note="(optional)" /> <ui-text-input-with-label v-model="itemData.series" :disabled="processing" label="Series" note="(optional)" />
</div> </div>
<div class="w-1/2 px-2"> <div class="w-1/2 px-2">
<div class="w-full"> <div class="w-full">
@ -33,9 +37,9 @@
</div> </div>
</div> </div>
<tables-uploaded-files-table :files="book.bookFiles" title="Book Files" class="mt-8" /> <tables-uploaded-files-table :files="item.itemFiles" title="Item Files" class="mt-8" />
<tables-uploaded-files-table v-if="book.otherFiles.length" title="Other Files" :files="book.otherFiles" /> <tables-uploaded-files-table v-if="item.otherFiles.length" title="Other Files" :files="item.otherFiles" />
<tables-uploaded-files-table v-if="book.ignoredFiles.length" title="Ignored Files" :files="book.ignoredFiles" /> <tables-uploaded-files-table v-if="item.ignoredFiles.length" title="Ignored Files" :files="item.ignoredFiles" />
</template> </template>
<widgets-alert v-if="uploadSuccess" type="success"> <widgets-alert v-if="uploadSuccess" type="success">
<p class="text-base">Successfully Uploaded!</p> <p class="text-base">Successfully Uploaded!</p>
@ -55,15 +59,16 @@ import Path from 'path'
export default { export default {
props: { props: {
book: { item: {
type: Object, type: Object,
default: () => {} default: () => {}
}, },
mediaType: String,
processing: Boolean processing: Boolean
}, },
data() { data() {
return { return {
bookData: { itemData: {
title: '', title: '',
author: '', author: '',
series: '' series: ''
@ -75,14 +80,19 @@ export default {
} }
}, },
computed: { computed: {
isPodcast() {
return this.mediaType === 'podcast'
},
directory() { directory() {
if (!this.bookData.title) return '' if (!this.itemData.title) return ''
if (this.bookData.series && this.bookData.author) { if (this.isPodcast) return this.itemData.title
return Path.join(this.bookData.author, this.bookData.series, this.bookData.title)
} else if (this.bookData.author) { if (this.itemData.series && this.itemData.author) {
return Path.join(this.bookData.author, this.bookData.title) return Path.join(this.itemData.author, this.itemData.series, this.itemData.title)
} else if (this.itemData.author) {
return Path.join(this.itemData.author, this.itemData.title)
} else { } else {
return this.bookData.title return this.itemData.title
} }
} }
}, },
@ -96,24 +106,24 @@ export default {
this.error = '' this.error = ''
}, },
getData() { getData() {
if (!this.bookData.title) { if (!this.itemData.title) {
this.error = 'Must have a title' this.error = 'Must have a title'
return null return null
} }
this.error = '' this.error = ''
var files = this.book.bookFiles.concat(this.book.otherFiles) var files = this.item.itemFiles.concat(this.item.otherFiles)
return { return {
index: this.book.index, index: this.item.index,
...this.bookData, ...this.itemData,
files files
} }
} }
}, },
mounted() { mounted() {
if (this.book) { if (this.item) {
this.bookData.title = this.book.title this.itemData.title = this.item.title
this.bookData.author = this.book.author this.itemData.author = this.item.author
this.bookData.series = this.book.series this.itemData.series = this.item.series
} }
} }
} }

View File

@ -5,7 +5,7 @@
<p class="font-book text-3xl text-white truncate pointer-events-none">{{ title }}</p> <p class="font-book text-3xl text-white truncate pointer-events-none">{{ title }}</p>
</div> </div>
</template> </template>
<div class="absolute -top-10 left-0 w-full flex"> <div class="absolute -top-10 left-0 z-10 w-full flex">
<template v-for="tab in availableTabs"> <template v-for="tab in availableTabs">
<div :key="tab.id" class="w-28 rounded-t-lg flex items-center justify-center mr-1 cursor-pointer hover:bg-bg font-book border-t border-l border-r border-black-300 tab text-xs sm:text-base" :class="selectedTab === tab.id ? 'tab-selected bg-bg pb-px' : 'bg-primary text-gray-400'" @click="selectTab(tab.id)">{{ tab.title }}</div> <div :key="tab.id" class="w-28 rounded-t-lg flex items-center justify-center mr-1 cursor-pointer hover:bg-bg font-book border-t border-l border-r border-black-300 tab text-xs sm:text-base" :class="selectedTab === tab.id ? 'tab-selected bg-bg pb-px' : 'bg-primary text-gray-400'" @click="selectTab(tab.id)">{{ tab.title }}</div>
</template> </template>
@ -252,7 +252,7 @@ export default {
} }
</script> </script>
<style> <style scoped>
.tab { .tab {
height: 40px; height: 40px;
} }

View File

@ -1,22 +1,18 @@
<template> <template>
<div class="w-full h-full px-4 py-2 mb-4"> <div class="w-full h-full px-4 py-2 mb-4">
<div v-show="showDirectoryPicker" class="flex items-center py-1 mb-2">
<span class="material-icons text-3xl cursor-pointer hover:text-gray-300" @click="backArrowPress">arrow_back</span>
<p class="px-4 text-xl">{{ title }}</p>
</div>
<div v-if="!showDirectoryPicker" class="w-full h-full py-4"> <div v-if="!showDirectoryPicker" class="w-full h-full py-4">
<div class="flex flex-wrap md:flex-nowrap -mx-1"> <div class="flex flex-wrap md:flex-nowrap -mx-1">
<div class="w-2/5 md:w-72 px-1 py-1 md:py-0"> <div class="w-2/5 md:w-72 px-1 py-1 md:py-0">
<ui-dropdown v-model="mediaType" :items="mediaTypes" label="Media Type" :disabled="!!library" small @input="changedMediaType" /> <ui-dropdown v-model="mediaType" :items="mediaTypes" label="Media Type" :disabled="!isNew" small @input="changedMediaType" />
</div> </div>
<div class="w-full md:flex-grow px-1 py-1 md:py-0"> <div class="w-full md:flex-grow px-1 py-1 md:py-0">
<ui-text-input-with-label v-model="name" label="Library Name" /> <ui-text-input-with-label v-model="name" label="Library Name" @blur="nameBlurred" />
</div> </div>
<div class="w-1/5 md:w-18 px-1 py-1 md:py-0"> <div class="w-1/5 md:w-18 px-1 py-1 md:py-0">
<ui-media-icon-picker v-model="icon" /> <ui-media-icon-picker v-model="icon" @input="iconChanged" />
</div> </div>
<div class="w-2/5 md:w-72 px-1 py-1 md:py-0"> <div class="w-2/5 md:w-72 px-1 py-1 md:py-0">
<ui-dropdown v-model="provider" :items="providers" label="Metadata Provider" small /> <ui-dropdown v-model="provider" :items="providers" label="Metadata Provider" small @input="formUpdated" />
</div> </div>
</div> </div>
@ -27,39 +23,23 @@
<ui-editable-text v-model="folder.fullPath" readonly type="text" class="w-full" /> <ui-editable-text v-model="folder.fullPath" readonly type="text" class="w-full" />
<span v-show="folders.length > 1" class="material-icons ml-2 cursor-pointer hover:text-error" @click="removeFolder(folder)">close</span> <span v-show="folders.length > 1" class="material-icons ml-2 cursor-pointer hover:text-error" @click="removeFolder(folder)">close</span>
</div> </div>
<!-- <p v-if="!folders.length" class="text-sm text-gray-300 px-1 py-2">No folders</p> -->
<div class="flex py-1 px-2 items-center w-full"> <div class="flex py-1 px-2 items-center w-full">
<span class="material-icons bg-opacity-50 mr-2 text-yellow-200" style="font-size: 1.2rem">folder</span> <span class="material-icons bg-opacity-50 mr-2 text-yellow-200" style="font-size: 1.2rem">folder</span>
<ui-editable-text v-model="newFolderPath" placeholder="New folder path" type="text" class="w-full" /> <ui-editable-text v-model="newFolderPath" placeholder="New folder path" type="text" class="w-full" @blur="newFolderInputBlurred" />
</div> </div>
<ui-btn class="w-full mt-2" color="primary" @click="showDirectoryPicker = true">Browse for Folder</ui-btn> <ui-btn class="w-full mt-2" color="primary" @click="showDirectoryPicker = true">Browse for Folder</ui-btn>
</div> </div>
<div class="absolute bottom-0 left-0 w-full py-4 px-4">
<div class="flex items-center">
<div class="flex-grow" />
<ui-btn v-show="!disableSubmit" color="success" :disabled="disableSubmit" @click="submit">{{ library ? 'Update Library' : 'Create Library' }}</ui-btn>
</div>
</div>
</div> </div>
<modals-libraries-folder-chooser v-else :paths="folderPaths" @select="selectFolder" /> <modals-libraries-folder-chooser v-else :paths="folderPaths" @back="showDirectoryPicker = false" @select="selectFolder" />
<div v-if="!showDirectoryPicker">
<div class="flex items-center pt-2">
<ui-toggle-switch v-if="!globalWatcherDisabled" v-model="disableWatcher" />
<ui-toggle-switch v-else disabled :value="false" />
<p class="pl-4 text-lg">Disable folder watcher for library</p>
</div>
<p v-if="globalWatcherDisabled" class="text-xs text-warning">*Watcher is disabled globally in server settings</p>
</div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
isNew: Boolean,
library: { library: {
type: Object, type: Object,
default: () => null default: () => null
@ -73,7 +53,6 @@ export default {
icon: '', icon: '',
folders: [], folders: [],
showDirectoryPicker: false, showDirectoryPicker: false,
disableWatcher: false,
newFolderPath: '', newFolderPath: '',
mediaType: null, mediaType: null,
mediaTypes: [ mediaTypes: [
@ -89,36 +68,54 @@ export default {
} }
}, },
computed: { computed: {
title() {
if (this.showDirectoryPicker) return 'Choose a Folder'
return ''
},
folderPaths() { folderPaths() {
return this.folders.map((f) => f.fullPath) return this.folders.map((f) => f.fullPath)
}, },
disableSubmit() {
if (!this.library) {
return false
}
var newfolderpaths = this.folderPaths.join(',')
var origfolderpaths = this.library.folders.map((f) => f.fullPath).join(',')
return newfolderpaths === origfolderpaths && this.name === this.library.name && this.provider === this.library.provider && this.disableWatcher === this.library.disableWatcher && this.icon === this.library.icon && !this.newFolderPath
},
providers() { providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers return this.$store.state.scanners.providers
},
globalWatcherDisabled() {
return this.$store.getters['getServerSetting']('scannerDisableWatcher')
} }
}, },
methods: { methods: {
getLibraryData() {
return {
name: this.name,
provider: this.provider,
folders: this.folders,
icon: this.icon,
mediaType: this.mediaType
}
},
formUpdated() {
this.$emit('update', this.getLibraryData())
},
newFolderInputBlurred() {
if (this.newFolderPath) {
this.folders.push({ fullPath: this.newFolderPath })
this.newFolderPath = ''
this.formUpdated()
}
},
iconChanged() {
this.formUpdated()
},
nameBlurred() {
if (this.name !== this.library.name) {
this.formUpdated()
}
},
changedMediaType() { changedMediaType() {
this.provider = this.providers[0].value this.provider = this.providers[0].value
this.formUpdated()
},
selectFolder(fullPath) {
this.folders.push({ fullPath })
this.showDirectoryPicker = false
this.formUpdated()
}, },
removeFolder(folder) { removeFolder(folder) {
this.folders = this.folders.filter((f) => f.fullPath !== folder.fullPath) this.folders = this.folders.filter((f) => f.fullPath !== folder.fullPath)
this.formUpdated()
}, },
backArrowPress() { backArrowPress() {
if (this.showDirectoryPicker) { if (this.showDirectoryPicker) {
@ -129,95 +126,9 @@ export default {
this.name = this.library ? this.library.name : '' this.name = this.library ? this.library.name : ''
this.provider = this.library ? this.library.provider : 'google' this.provider = this.library ? this.library.provider : 'google'
this.folders = this.library ? this.library.folders.map((p) => ({ ...p })) : [] this.folders = this.library ? this.library.folders.map((p) => ({ ...p })) : []
this.disableWatcher = this.library ? !!this.library.disableWatcher : false
this.icon = this.library ? this.library.icon : 'default' this.icon = this.library ? this.library.icon : 'default'
this.mediaType = this.library ? this.library.mediaType : 'book' this.mediaType = this.library ? this.library.mediaType : 'book'
this.showDirectoryPicker = false this.showDirectoryPicker = false
},
selectFolder(fullPath) {
this.folders.push({ fullPath })
this.showDirectoryPicker = false
},
submit() {
if (this.newFolderPath) {
this.folders.push({ fullPath: this.newFolderPath })
}
if (this.library) {
this.updateLibrary()
} else {
this.createLibrary()
}
},
updateLibrary() {
if (!this.name) {
this.$toast.error('Library must have a name')
return
}
if (!this.folders.length) {
this.$toast.error('Library must have at least 1 path')
return
}
var newLibraryPayload = {
name: this.name,
provider: this.provider,
folders: this.folders,
icon: this.icon,
disableWatcher: this.disableWatcher
}
this.$emit('update:processing', true)
this.$axios
.$patch(`/api/libraries/${this.library.id}`, newLibraryPayload)
.then((res) => {
this.$emit('update:processing', false)
this.$emit('close')
this.$toast.success(`Library "${res.name}" updated successfully`)
})
.catch((error) => {
console.error(error)
if (error.response && error.response.data) {
this.$toast.error(error.response.data)
} else {
this.$toast.error('Failed to update library')
}
this.$emit('update:processing', false)
})
},
createLibrary() {
if (!this.name) {
this.$toast.error('Library must have a name')
return
}
if (!this.folders.length) {
this.$toast.error('Library must have at least 1 path')
return
}
var newLibraryPayload = {
name: this.name,
provider: this.provider,
folders: this.folders,
icon: this.icon,
mediaType: this.mediaType,
disableWatcher: this.disableWatcher
}
this.$emit('update:processing', true)
this.$axios
.$post('/api/libraries', newLibraryPayload)
.then((res) => {
this.$emit('update:processing', false)
this.$emit('close')
this.$toast.success(`Library "${res.name}" created successfully`)
})
.catch((error) => {
console.error(error)
if (error.response && error.response.data) {
this.$toast.error(error.response.data)
} else {
this.$toast.error('Failed to create library')
}
this.$emit('update:processing', false)
})
} }
}, },
mounted() { mounted() {

View File

@ -5,8 +5,20 @@
<p class="font-book text-3xl text-white truncate">{{ title }}</p> <p class="font-book text-3xl text-white truncate">{{ title }}</p>
</div> </div>
</template> </template>
<div class="p-4 w-full text-sm py-6 rounded-lg bg-bg shadow-lg border border-black-300 relative overflow-hidden" style="min-height: 400px; max-height: 80vh"> <div class="absolute -top-10 left-0 z-10 w-full flex">
<modals-libraries-edit-library v-if="show" :library="library" :processing.sync="processing" @close="show = false" /> <template v-for="tab in tabs">
<div :key="tab.id" class="w-28 rounded-t-lg flex items-center justify-center mr-1 cursor-pointer hover:bg-bg font-book border-t border-l border-r border-black-300 tab text-xs sm:text-base" :class="selectedTab === tab.id ? 'tab-selected bg-bg pb-px' : 'bg-primary text-gray-400'" @click="selectTab(tab.id)">{{ tab.title }}</div>
</template>
</div>
<div class="px-4 w-full text-sm pt-6 pb-20 rounded-b-lg rounded-tr-lg bg-bg shadow-lg border border-black-300 relative overflow-hidden" style="min-height: 400px; max-height: 80vh">
<component v-if="libraryCopy && show" :is="tabName" :is-new="!library" :library="libraryCopy" :processing.sync="processing" @update="updateLibrary" @close="show = false" />
<div class="absolute bottom-0 left-0 w-full px-4 py-4 border-t border-opacity-10">
<div class="flex justify-end">
<ui-btn @click="submit">{{ buttonText }}</ui-btn>
</div>
</div>
</div> </div>
</modals-modal> </modals-modal>
</template> </template>
@ -22,7 +34,21 @@ export default {
}, },
data() { data() {
return { return {
processing: false processing: false,
selectedTab: 'details',
tabs: [
{
id: 'details',
title: 'Details',
component: 'modals-libraries-edit-library'
},
{
id: 'settings',
title: 'Settings',
component: 'modals-libraries-library-settings'
}
],
libraryCopy: null
} }
}, },
computed: { computed: {
@ -36,10 +62,157 @@ export default {
}, },
title() { title() {
return this.library ? 'Update Library' : 'New Library' return this.library ? 'Update Library' : 'New Library'
},
buttonText() {
return this.library ? 'Update Library' : 'Create New Library'
},
tabName() {
var _tab = this.tabs.find((t) => t.id === this.selectedTab)
return _tab ? _tab.component : ''
}
},
watch: {
show: {
handler(newVal) {
if (newVal) this.init()
}
}
},
methods: {
selectTab(tab) {
this.selectedTab = tab
},
updateLibrary(library) {
this.mapLibraryToCopy(library)
},
getNewLibraryData() {
return {
name: '',
provider: 'google',
folders: [],
icon: 'database',
mediaType: 'book',
settings: {
disableWatcher: false
}
}
},
init() {
this.selectedTab = 'details'
this.libraryCopy = this.getNewLibraryData()
if (this.library) {
this.mapLibraryToCopy(this.library)
}
},
mapLibraryToCopy(library) {
for (const key in this.libraryCopy) {
if (library[key] !== undefined) {
if (key === 'folders') {
this.libraryCopy.folders = library.folders.map((f) => ({ ...f }))
} else if (key === 'settings') {
this.libraryCopy.settings = { ...library.settings }
} else {
this.libraryCopy[key] = library[key]
}
}
}
},
validate() {
if (!this.libraryCopy.name) {
this.$toast.error('Library must have a name')
return false
}
if (!this.libraryCopy.folders.length) {
this.$toast.error('Library must have at least 1 path')
return false
}
return true
},
submit() {
if (!this.validate()) return
if (this.library) {
this.submitUpdateLibrary()
} else {
this.submitCreateLibrary()
}
},
getLibraryUpdatePayload() {
var updatePayload = {}
for (const key in this.libraryCopy) {
if (key === 'folders') {
if (this.libraryCopy.folders.join(',') !== this.library.folders.join(',')) {
updatePayload.folders = [...this.libraryCopy.folders]
}
} else if (key === 'settings') {
for (const settingsKey in this.libraryCopy.settings) {
if (this.libraryCopy.settings[settingsKey] !== this.library.settings[settingsKey]) {
if (!updatePayload.settings) updatePayload.settings = {}
updatePayload.settings[settingsKey] = this.libraryCopy.settings[settingsKey]
}
}
} else if (key !== 'mediaType' && this.libraryCopy[key] !== this.library[key]) {
updatePayload[key] = this.libraryCopy[key]
}
}
return updatePayload
},
submitUpdateLibrary() {
var newLibraryPayload = this.getLibraryUpdatePayload()
if (!Object.keys(newLibraryPayload).length) {
this.$toast.info('No updates are necessary')
return
}
this.processing = true
this.$axios
.$patch(`/api/libraries/${this.library.id}`, newLibraryPayload)
.then((res) => {
this.processing = false
this.show = false
this.$toast.success(`Library "${res.name}" updated successfully`)
})
.catch((error) => {
console.error(error)
if (error.response && error.response.data) {
this.$toast.error(error.response.data)
} else {
this.$toast.error('Failed to update library')
}
this.processing = false
})
},
submitCreateLibrary() {
this.processing = true
this.$axios
.$post('/api/libraries', this.libraryCopy)
.then((res) => {
this.processing = false
this.show = false
this.$toast.success(`Library "${res.name}" created successfully`)
})
.catch((error) => {
console.error(error)
if (error.response && error.response.data) {
this.$toast.error(error.response.data)
} else {
this.$toast.error('Failed to create library')
}
this.processing = false
})
} }
}, },
methods: {},
mounted() {}, mounted() {},
beforeDestroy() {} beforeDestroy() {}
} }
</script> </script>
<style scoped>
.tab {
height: 40px;
}
.tab.tab-selected {
height: 41px;
}
</style>

View File

@ -1,10 +1,14 @@
<template> <template>
<div class="w-full h-full"> <div class="w-full h-full bg-bg absolute top-0 left-0 px-4 py-4 z-10">
<div class="flex items-center py-1 mb-2">
<span class="material-icons text-3xl cursor-pointer hover:text-gray-300" @click="$emit('back')">arrow_back</span>
<p class="px-4 text-xl">Choose a Folder</p>
</div>
<div v-if="allFolders.length" class="w-full bg-primary bg-opacity-70 py-1 px-4 mb-2"> <div v-if="allFolders.length" class="w-full bg-primary bg-opacity-70 py-1 px-4 mb-2">
<p class="font-mono truncate">{{ selectedPath || '\\' }}</p> <p class="font-mono truncate">{{ selectedPath || '\\' }}</p>
</div> </div>
<div v-if="allFolders.length" class="flex bg-primary bg-opacity-50 p-4"> <div v-if="allFolders.length" class="flex bg-primary bg-opacity-50 p-4 folder-container">
<div class="w-1/2 border-r border-bg"> <div class="w-1/2 border-r border-bg h-full overflow-y-auto">
<div v-if="level > 0" class="w-full p-1 cursor-pointer flex items-center" @click="goBack"> <div v-if="level > 0" class="w-full p-1 cursor-pointer flex items-center" @click="goBack">
<span class="material-icons bg-opacity-50 text-yellow-200" style="font-size: 1.2rem">folder</span> <span class="material-icons bg-opacity-50 text-yellow-200" style="font-size: 1.2rem">folder</span>
<p class="text-base font-mono px-2">..</p> <p class="text-base font-mono px-2">..</p>
@ -15,7 +19,7 @@
<span v-if="dir.dirs && dir.dirs.length && dir.path === selectedPath" class="material-icons" style="font-size: 1.1rem">arrow_right</span> <span v-if="dir.dirs && dir.dirs.length && dir.path === selectedPath" class="material-icons" style="font-size: 1.1rem">arrow_right</span>
</div> </div>
</div> </div>
<div class="w-1/2"> <div class="w-1/2 h-full overflow-y-auto">
<div v-for="dir in _subdirs" :key="dir.path" :class="dir.className" class="dir-item w-full p-1 cursor-pointer flex items-center hover:text-white text-gray-200" @click="selectSubDir(dir)"> <div v-for="dir in _subdirs" :key="dir.path" :class="dir.className" class="dir-item w-full p-1 cursor-pointer flex items-center hover:text-white text-gray-200" @click="selectSubDir(dir)">
<span class="material-icons bg-opacity-50 text-yellow-200" style="font-size: 1.2rem">folder</span> <span class="material-icons bg-opacity-50 text-yellow-200" style="font-size: 1.2rem">folder</span>
<p class="text-base font-mono px-2 truncate">{{ dir.dirname }}</p> <p class="text-base font-mono px-2 truncate">{{ dir.dirname }}</p>
@ -30,12 +34,8 @@
<p class="text-gray-300">Note: folders already mapped will not be shown</p> <p class="text-gray-300">Note: folders already mapped will not be shown</p>
</div> </div>
<div class="absolute bottom-0 left-0 w-full py-4 px-8"> <div class="w-full py-2">
<ui-btn :disabled="!selectedPath" color="primary" class="w-full mt-2" @click="selectFolder">Select Folder Path</ui-btn> <ui-btn :disabled="!selectedPath" color="primary" class="w-full mt-2" @click="selectFolder">Select Folder Path</ui-btn>
<!-- <div class="flex items-center">
<div class="flex-grow" />
<ui-btn color="success" @click="selectFolder">Select</ui-btn>
</div> -->
</div> </div>
</div> </div>
</template> </template>
@ -161,4 +161,9 @@ export default {
.dir-item.dir-used { .dir-item.dir-used {
background-color: rgba(255, 25, 0, 0.1); background-color: rgba(255, 25, 0, 0.1);
} }
.folder-container {
max-height: calc(100% - 130px);
height: calc(100% - 130px);
min-height: calc(100% - 130px);
}
</style> </style>

View File

@ -0,0 +1,63 @@
<template>
<div class="w-full h-full px-4 py-1 mb-4">
<div class="py-3">
<div class="flex items-center">
<ui-toggle-switch v-if="!globalWatcherDisabled" v-model="disableWatcher" @input="formUpdated" />
<ui-toggle-switch v-else disabled :value="false" />
<p class="pl-4 text-lg">Disable folder watcher for library</p>
</div>
<p v-if="globalWatcherDisabled" class="text-xs text-warning">*Watcher is disabled globally in server settings</p>
</div>
</div>
</template>
<script>
export default {
props: {
library: {
type: Object,
default: () => null
},
processing: Boolean
},
data() {
return {
provider: null,
disableWatcher: false
}
},
computed: {
librarySettings() {
return this.library.settings || {}
},
globalWatcherDisabled() {
return this.$store.getters['getServerSetting']('scannerDisableWatcher')
},
mediaType() {
return this.library.mediaType
},
providers() {
if (this.mediaType === 'podcast') return this.$store.state.scanners.podcastProviders
return this.$store.state.scanners.providers
}
},
methods: {
getLibraryData() {
return {
settings: {
disableWatcher: !!this.disableWatcher
}
}
},
formUpdated() {
this.$emit('update', this.getLibraryData())
},
init() {
this.disableWatcher = !!this.librarySettings.disableWatcher
}
},
mounted() {
this.init()
}
}
</script>

View File

@ -40,8 +40,8 @@ export default {
showMenu: false, showMenu: false,
types: [ types: [
{ {
id: 'default', id: 'database',
name: 'Default' name: 'Database'
}, },
{ {
id: 'audiobook', id: 'audiobook',
@ -65,7 +65,7 @@ export default {
computed: { computed: {
selected: { selected: {
get() { get() {
return this.value || 'default' return this.value || 'database'
}, },
set(val) { set(val) {
this.$emit('input', val) this.$emit('input', val)
@ -75,7 +75,7 @@ export default {
return this.types.find((t) => t.id === this.selected) return this.types.find((t) => t.id === this.selected)
}, },
selectedName() { selectedName() {
return this.selectedItem ? this.selectedItem.name : 'Default' return this.selectedItem ? this.selectedItem.name : 'Database'
} }
}, },
methods: { methods: {

View File

@ -3,7 +3,7 @@
<p class="px-1 text-sm font-semibold" :class="disabled ? 'text-gray-400' : ''"> <p class="px-1 text-sm font-semibold" :class="disabled ? 'text-gray-400' : ''">
{{ label }}<em v-if="note" class="font-normal text-xs pl-2">{{ note }}</em> {{ label }}<em v-if="note" class="font-normal text-xs pl-2">{{ note }}</em>
</p> </p>
<ui-text-input ref="input" v-model="inputValue" :disabled="disabled" :readonly="readonly" :type="type" class="w-full" /> <ui-text-input ref="input" v-model="inputValue" :disabled="disabled" :readonly="readonly" :type="type" class="w-full" @blur="inputBlurred" />
</div> </div>
</template> </template>
@ -38,6 +38,9 @@ export default {
if (this.$refs.input && this.$refs.input.blur) { if (this.$refs.input && this.$refs.input.blur) {
this.$refs.input.blur() this.$refs.input.blur()
} }
},
inputBlurred() {
this.$emit('blur')
} }
}, },
mounted() {} mounted() {}

View File

@ -4,8 +4,8 @@ export default {
data() { data() {
return { return {
uploadHelpers: { uploadHelpers: {
getBooksFromDrop: this.getBooksFromDataTransferItems, getItemsFromDrop: this.getItemsFromDataTransferItems,
getBooksFromPicker: this.getBooksFromFileList getItemsFromPicker: this.getItemsFromFilelist
} }
} }
}, },
@ -23,8 +23,8 @@ export default {
} }
return false return false
}, },
filterAudiobookFiles(files) { filterItemFiles(files, mediaType) {
var validBookFiles = [] var validItemFiles = []
var validOtherFiles = [] var validOtherFiles = []
var ignoredFiles = [] var ignoredFiles = []
files.forEach((file) => { files.forEach((file) => {
@ -32,60 +32,60 @@ export default {
if (!filetype) ignoredFiles.push(file) if (!filetype) ignoredFiles.push(file)
else { else {
file.filetype = filetype file.filetype = filetype
if (filetype === 'audio' || filetype === 'ebook') validBookFiles.push(file) if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) validItemFiles.push(file)
else validOtherFiles.push(file) else validOtherFiles.push(file)
} }
}) })
return { return {
bookFiles: validBookFiles, itemFiles: validItemFiles,
otherFiles: validOtherFiles, otherFiles: validOtherFiles,
ignoredFiles ignoredFiles
} }
}, },
audiobookFromItems(items) { itemFromTreeItems(items, mediaType) {
var { bookFiles, otherFiles, ignoredFiles } = this.filterAudiobookFiles(items) var { itemFiles, otherFiles, ignoredFiles } = this.filterItemFiles(items, mediaType)
if (!bookFiles.length) { if (!itemFiles.length) {
ignoredFiles = ignoredFiles.concat(otherFiles) ignoredFiles = ignoredFiles.concat(otherFiles)
otherFiles = [] otherFiles = []
} }
return [ return [
{ {
bookFiles, itemFiles,
otherFiles, otherFiles,
ignoredFiles ignoredFiles
} }
] ]
}, },
traverseForAudiobook(folder, depth = 1) { traverseForItem(folder, mediaType, depth = 1) {
if (folder.items.some((f) => f.isDirectory)) { if (folder.items.some((f) => f.isDirectory)) {
var audiobooks = [] var items = []
folder.items.forEach((file) => { folder.items.forEach((file) => {
if (file.isDirectory) { if (file.isDirectory) {
var audiobookResults = this.traverseForAudiobook(file, ++depth) var itemResults = this.traverseForItem(file, mediaType, ++depth)
audiobooks = audiobooks.concat(audiobookResults) items = items.concat(itemResults)
} }
}) })
return audiobooks return items
} else { } else {
return this.audiobookFromItems(folder.items) return this.itemFromTreeItems(folder.items, mediaType)
} }
}, },
fileTreeToAudiobooks(filetree) { fileTreeToItems(filetree, mediaType) {
// Has directores - Is Multi Book Drop // Has directores - Is Multi Book Drop
if (filetree.some((f) => f.isDirectory)) { if (filetree.some((f) => f.isDirectory)) {
var ignoredFilesInRoot = filetree.filter((f) => !f.isDirectory) var ignoredFilesInRoot = filetree.filter((f) => !f.isDirectory)
if (ignoredFilesInRoot.length) filetree = filetree.filter((f) => f.isDirectory) if (ignoredFilesInRoot.length) filetree = filetree.filter((f) => f.isDirectory)
var audiobookResults = this.traverseForAudiobook({ items: filetree }) var itemResults = this.traverseForItem({ items: filetree }, mediaType)
return { return {
audiobooks: audiobookResults, items: itemResults,
ignoredFiles: ignoredFilesInRoot ignoredFiles: ignoredFilesInRoot
} }
} else { } else {
// Single Book drop // Single Book drop
return { return {
audiobooks: this.audiobookFromItems(filetree), items: this.itemFromTreeItems(filetree, mediaType),
ignoredFiles: [] ignoredFiles: []
} }
} }
@ -140,7 +140,7 @@ export default {
series: '', series: '',
...book ...book
} }
var firstBookFile = book.bookFiles[0] 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) var firstBookPath = Path.dirname(firstBookFile.filepath)
@ -157,32 +157,49 @@ export default {
} }
return audiobook return audiobook
}, },
async getBooksFromDataTransferItems(items) { cleanPodcast(item, index) {
var podcast = {
index,
title: '',
...item
}
var firstAudioFile = podcast.itemFiles[0]
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]
return podcast
},
cleanItem(item, mediaType, index) {
if (mediaType === 'podcast') return this.cleanPodcast(item, index)
return this.cleanBook(item, index)
},
async getItemsFromDataTransferItems(items, mediaType) {
var files = await this.getFilesDropped(items) var files = await this.getFilesDropped(items)
if (!files || !files.length) return { error: 'No files found ' } if (!files || !files.length) return { error: 'No files found ' }
var audiobooksData = this.fileTreeToAudiobooks(files) var itemData = this.fileTreeToItems(files, mediaType)
if (!audiobooksData.audiobooks.length && !audiobooksData.ignoredFiles.length) { if (!itemData.items.length && !itemData.ignoredFiles.length) {
return { error: 'Invalid file drop' } return { error: 'Invalid file drop' }
} }
var ignoredFiles = audiobooksData.ignoredFiles var ignoredFiles = itemData.ignoredFiles
var index = 1 var index = 1
var books = audiobooksData.audiobooks.filter((ab) => { var items = itemData.items.filter((ab) => {
if (!ab.bookFiles.length) { if (!ab.itemFiles.length) {
if (ab.otherFiles.length) ignoredFiles = ignoredFiles.concat(ab.otherFiles) if (ab.otherFiles.length) ignoredFiles = ignoredFiles.concat(ab.otherFiles)
if (ab.ignoredFiles.length) ignoredFiles = ignoredFiles.concat(ab.ignoredFiles) if (ab.ignoredFiles.length) ignoredFiles = ignoredFiles.concat(ab.ignoredFiles)
} }
return ab.bookFiles.length return ab.itemFiles.length
}).map(ab => this.cleanBook(ab, index++)) }).map(ab => this.cleanItem(ab, index++))
return { return {
books, items,
ignoredFiles ignoredFiles
} }
}, },
getBooksFromFileList(filelist) { getItemsFromFilelist(filelist, mediaType) {
var ignoredFiles = [] var ignoredFiles = []
var otherFiles = [] var otherFiles = []
var bookMap = {} var itemMap = {}
filelist.forEach((file) => { filelist.forEach((file) => {
var filetype = this.checkFileType(file.name) var filetype = this.checkFileType(file.name)
@ -191,17 +208,17 @@ export default {
file.filetype = filetype file.filetype = filetype
if (file.webkitRelativePath) file.filepath = file.webkitRelativePath if (file.webkitRelativePath) file.filepath = file.webkitRelativePath
if (filetype === 'audio' || filetype === 'ebook') { if (filetype === 'audio' || (filetype === 'ebook' && mediaType === 'book')) {
var dir = file.filepath ? Path.dirname(file.filepath) : '' var dir = file.filepath ? Path.dirname(file.filepath) : ''
if (!bookMap[dir]) { if (!itemMap[dir]) {
bookMap[dir] = { itemMap[dir] = {
path: dir, path: dir,
ignoredFiles: [], ignoredFiles: [],
bookFiles: [], itemFiles: [],
otherFiles: [] otherFiles: []
} }
} }
bookMap[dir].bookFiles.push(file) itemMap[dir].itemFiles.push(file)
} else { } else {
otherFiles.push(file) otherFiles.push(file)
} }
@ -210,18 +227,18 @@ export default {
otherFiles.forEach((file) => { otherFiles.forEach((file) => {
var dir = Path.dirname(file.filepath) var dir = Path.dirname(file.filepath)
var findBook = Object.values(bookMap).find(b => dir.startsWith(b.path)) var findItem = Object.values(itemMap).find(b => dir.startsWith(b.path))
if (findBook) { if (findItem) {
bookMap[dir].otherFiles.push(file) findItem.otherFiles.push(file)
} else { } else {
ignoredFiles.push(file) ignoredFiles.push(file)
} }
}) })
var index = 1 var index = 1
var books = Object.values(bookMap).map(ab => this.cleanBook(ab, index++)) var items = Object.values(itemMap).map(i => this.cleanItem(i, mediaType, index++))
return { return {
books, items,
ignoredFiles: ignoredFiles ignoredFiles: ignoredFiles
} }
}, },

View File

@ -51,6 +51,7 @@ export default {
if (!collection) { if (!collection) {
return redirect('/') return redirect('/')
} }
store.commit('user/addUpdateCollection', collection) store.commit('user/addUpdateCollection', collection)
return { return {
collectionId: collection.id collectionId: collection.id

View File

@ -23,11 +23,16 @@
export default { export default {
async asyncData({ store, params, redirect, query, app }) { async asyncData({ store, params, redirect, query, app }) {
var libraryId = params.library var libraryId = params.library
var library = await store.dispatch('libraries/fetch', libraryId) var libraryData = await store.dispatch('libraries/fetch', libraryId)
if (!library) { if (!libraryData) {
return redirect('/oops?message=Library not found') return redirect('/oops?message=Library not found')
} }
const library = libraryData.library
if (library.mediaType === 'podcast') {
return redirect(`/library/${libraryId}`)
}
return { return {
libraryId libraryId
} }

View File

@ -14,8 +14,8 @@
export default { export default {
async asyncData({ params, query, store, app, redirect }) { async asyncData({ params, query, store, app, redirect }) {
var libraryId = params.library var libraryId = params.library
var library = await store.dispatch('libraries/fetch', libraryId) var libraryData = await store.dispatch('libraries/fetch', libraryId)
if (!library) { if (!libraryData) {
return redirect('/oops?message=Library not found') return redirect('/oops?message=Library not found')
} }
@ -23,6 +23,13 @@ export default {
if (query.filter) { if (query.filter) {
store.dispatch('user/updateUserSettings', { filterBy: query.filter }) store.dispatch('user/updateUserSettings', { filterBy: query.filter })
} }
// Redirect podcast libraries
const library = libraryData.library
if (library.mediaType === 'podcast' && (params.id === 'collections' || params.id === 'series')) {
return redirect(`/library/${libraryId}`)
}
return { return {
id: params.id || '', id: params.id || '',
libraryId libraryId

View File

@ -44,10 +44,17 @@
export default { export default {
async asyncData({ params, query, store, app, redirect }) { async asyncData({ params, query, store, app, redirect }) {
var libraryId = params.library var libraryId = params.library
var library = await store.dispatch('libraries/fetch', libraryId) var libraryData = await store.dispatch('libraries/fetch', libraryId)
if (!library) { if (!libraryData) {
return redirect('/oops?message=Library not found') return redirect('/oops?message=Library not found')
} }
// Redirect book libraries
const library = libraryData.library
if (library.mediaType === 'book') {
return redirect(`/library/${libraryId}`)
}
return { return {
libraryId libraryId
} }

View File

@ -14,10 +14,16 @@
export default { export default {
async asyncData({ store, params, redirect, query, app }) { async asyncData({ store, params, redirect, query, app }) {
var libraryId = params.library var libraryId = params.library
var library = await store.dispatch('libraries/fetch', libraryId) var libraryData = await store.dispatch('libraries/fetch', libraryId)
if (!library) { if (!libraryData) {
return redirect('/oops?message=Library not found') return redirect('/oops?message=Library not found')
} }
const library = libraryData.library
if (library.mediaType === 'podcast') {
return redirect(`/library/${libraryId}`)
}
var series = await app.$axios.$get(`/api/series/${params.id}`).catch((error) => { var series = await app.$axios.$get(`/api/series/${params.id}`).catch((error) => {
console.error('Failed', error) console.error('Failed', error)
return false return false

View File

@ -3,11 +3,14 @@
<div class="w-full max-w-6xl mx-auto"> <div class="w-full max-w-6xl mx-auto">
<!-- Library & folder picker --> <!-- Library & folder picker -->
<div class="flex my-6 -mx-2"> <div class="flex my-6 -mx-2">
<div class="w-1/3 px-2"> <div class="w-1/5 px-2">
<ui-dropdown v-model="selectedLibraryId" :items="libraryItems" label="Library" :disabled="processing" @input="libraryChanged" /> <ui-dropdown v-model="selectedLibraryId" :items="libraryItems" label="Library" :disabled="!!items.length" @input="libraryChanged" />
</div> </div>
<div class="w-2/3 px-2"> <div class="w-3/5 px-2">
<ui-dropdown v-model="selectedFolderId" :items="folderItems" :disabled="!selectedLibraryId || processing" label="Folder" /> <ui-dropdown v-model="selectedFolderId" :items="folderItems" :disabled="!selectedLibraryId || !!items.length" label="Folder" />
</div>
<div class="w-1/5 px-2">
<ui-text-input-with-label :value="selectedLibraryMediaType" readonly label="Media Type" />
</div> </div>
</div> </div>
@ -16,7 +19,7 @@
</widgets-alert> </widgets-alert>
<!-- Picker display --> <!-- Picker display -->
<div v-if="!books.length && !ignoredFiles.length" class="w-full mx-auto border border-white border-opacity-20 px-12 pt-12 pb-4 my-12 relative" :class="isDragging ? 'bg-primary bg-opacity-40' : 'border-dashed'"> <div v-if="!items.length && !ignoredFiles.length" class="w-full mx-auto border border-white border-opacity-20 px-12 pt-12 pb-4 my-12 relative" :class="isDragging ? 'bg-primary bg-opacity-40' : 'border-dashed'">
<p class="text-2xl text-center">{{ isDragging ? 'Drop files' : "Drag n' drop files or folders" }}</p> <p class="text-2xl text-center">{{ isDragging ? 'Drop files' : "Drag n' drop files or folders" }}</p>
<p class="text-center text-sm my-5">or</p> <p class="text-center text-sm my-5">or</p>
<div class="w-full max-w-xl mx-auto"> <div class="w-full max-w-xl mx-auto">
@ -29,33 +32,33 @@
<p class="text-xs text-white text-opacity-50 font-mono"><strong>Supported File Types: </strong>{{ inputAccept.join(', ') }}</p> <p class="text-xs text-white text-opacity-50 font-mono"><strong>Supported File Types: </strong>{{ inputAccept.join(', ') }}</p>
</div> </div>
</div> </div>
<!-- Book list header --> <!-- Item list header -->
<div v-else class="w-full flex items-center pb-4 border-b border-white border-opacity-10"> <div v-else class="w-full flex items-center pb-4 border-b border-white border-opacity-10">
<p class="text-lg">{{ books.length }} book{{ books.length === 1 ? '' : 's' }}</p> <p class="text-lg">{{ items.length }} item{{ items.length === 1 ? '' : 's' }}</p>
<p v-if="ignoredFiles.length" class="text-lg">&nbsp;|&nbsp;{{ ignoredFiles.length }} file{{ ignoredFiles.length === 1 ? '' : 's' }} ignored</p> <p v-if="ignoredFiles.length" class="text-lg">&nbsp;|&nbsp;{{ ignoredFiles.length }} file{{ ignoredFiles.length === 1 ? '' : 's' }} ignored</p>
<div class="flex-grow" /> <div class="flex-grow" />
<ui-btn :disabled="processing" small @click="reset">Reset</ui-btn> <ui-btn :disabled="processing" small @click="reset">Reset</ui-btn>
</div> </div>
<!-- Alerts --> <!-- Alerts -->
<widgets-alert v-if="!books.length && !uploadReady" type="error" class="my-4"> <widgets-alert v-if="!items.length && !uploadReady" type="error" class="my-4">
<p class="text-lg">No books found</p> <p class="text-lg">No items found</p>
</widgets-alert> </widgets-alert>
<widgets-alert v-if="ignoredFiles.length" type="warning" class="my-4"> <widgets-alert v-if="ignoredFiles.length" type="warning" class="my-4">
<div class="w-full pr-12"> <div class="w-full pr-12">
<p class="text-base mb-1">Unsupported files are ignored. When choosing or dropping a folder, other files that are not in a book folder are ignored.</p> <p class="text-base mb-1">Unsupported files are ignored. When choosing or dropping a folder, other files that are not in an item folder are ignored.</p>
<tables-uploaded-files-table :files="ignoredFiles" title="Ignored Files" class="text-white" /> <tables-uploaded-files-table :files="ignoredFiles" title="Ignored Files" class="text-white" />
<p class="text-xs text-white text-opacity-50 font-mono pt-1"><strong>Supported File Types: </strong>{{ inputAccept.join(', ') }}</p> <p class="text-xs text-white text-opacity-50 font-mono pt-1"><strong>Supported File Types: </strong>{{ inputAccept.join(', ') }}</p>
</div> </div>
</widgets-alert> </widgets-alert>
<!-- Book Upload cards --> <!-- Item Upload cards -->
<template v-for="(book, index) in books"> <template v-for="(item, index) in items">
<cards-book-upload-card :ref="`bookCard-${book.index}`" :key="index" :book="book" :processing="processing" @remove="removeBook(book)" /> <cards-item-upload-card :ref="`itemCard-${item.index}`" :key="index" :media-type="selectedLibraryMediaType" :item="item" :processing="processing" @remove="removeItem(item)" />
</template> </template>
<!-- Upload/Reset btns --> <!-- Upload/Reset btns -->
<div v-show="books.length" class="flex justify-end pb-8 pt-4"> <div v-show="items.length" class="flex justify-end pb-8 pt-4">
<ui-btn v-if="!uploadFinished" color="success" :loading="processing" @click="submit">Upload</ui-btn> <ui-btn v-if="!uploadFinished" color="success" :loading="processing" @click="submit">Upload</ui-btn>
<ui-btn v-else @click="reset">Reset</ui-btn> <ui-btn v-else @click="reset">Reset</ui-btn>
</div> </div>
@ -75,7 +78,7 @@ export default {
return { return {
isDragging: false, isDragging: false,
error: '', error: '',
books: [], items: [],
ignoredFiles: [], ignoredFiles: [],
selectedLibraryId: null, selectedLibraryId: null,
selectedFolderId: null, selectedFolderId: null,
@ -108,6 +111,12 @@ export default {
selectedLibrary() { selectedLibrary() {
return this.libraries.find((lib) => lib.id === this.selectedLibraryId) return this.libraries.find((lib) => lib.id === this.selectedLibraryId)
}, },
selectedLibraryMediaType() {
return this.selectedLibrary ? this.selectedLibrary.mediaType : null
},
selectedLibraryIsPodcast() {
return this.selectedLibraryMediaType === 'podcast'
},
selectedFolder() { selectedFolder() {
if (!this.selectedLibrary) return null if (!this.selectedLibrary) return null
return this.selectedLibrary.folders.find((fold) => fold.id === this.selectedFolderId) return this.selectedLibrary.folders.find((fold) => fold.id === this.selectedFolderId)
@ -122,7 +131,7 @@ export default {
}) })
}, },
uploadReady() { uploadReady() {
return !this.books.length && !this.ignoredFiles.length && !this.uploadFinished return !this.items.length && !this.ignoredFiles.length && !this.uploadFinished
} }
}, },
methods: { methods: {
@ -141,15 +150,15 @@ export default {
this.selectedFolderId = this.selectedLibrary.folders[0].id this.selectedFolderId = this.selectedLibrary.folders[0].id
} }
}, },
removeBook(book) { removeItem(item) {
this.books = this.books.filter((b) => b.index !== book.index) this.items = this.items.filter((b) => b.index !== item.index)
if (!this.books.length) { if (!this.items.length) {
this.reset() this.reset()
} }
}, },
reset() { reset() {
this.error = '' this.error = ''
this.books = [] this.items = []
this.ignoredFiles = [] this.ignoredFiles = []
this.uploadFinished = false this.uploadFinished = false
if (this.$refs.fileInput) this.$refs.fileInput.value = '' if (this.$refs.fileInput) this.$refs.fileInput.value = ''
@ -186,31 +195,31 @@ export default {
e.preventDefault() e.preventDefault()
this.isDragging = false this.isDragging = false
var items = e.dataTransfer.items || [] var items = e.dataTransfer.items || []
var bookResults = await this.uploadHelpers.getBooksFromDrop(items) var itemResults = await this.uploadHelpers.getItemsFromDrop(items)
this.setResults(bookResults) this.setResults(itemResults)
}, },
inputChanged(e) { inputChanged(e) {
if (!e.target || !e.target.files) return if (!e.target || !e.target.files) return
var _files = Array.from(e.target.files) var _files = Array.from(e.target.files)
if (_files && _files.length) { if (_files && _files.length) {
var bookResults = this.uploadHelpers.getBooksFromPicker(_files) var itemResults = this.uploadHelpers.getItemsFromPicker(_files, this.selectedLibraryMediaType)
this.setResults(bookResults) this.setResults(itemResults)
} }
}, },
setResults(bookResults) { setResults(itemResults) {
if (bookResults.error) { if (itemResults.error) {
this.error = bookResults.error this.error = itemResults.error
this.books = [] this.items = []
this.ignoredFiles = [] this.ignoredFiles = []
} else { } else {
this.error = '' this.error = ''
this.books = bookResults.books this.items = itemResults.items
this.ignoredFiles = bookResults.ignoredFiles this.ignoredFiles = itemResults.ignoredFiles
} }
console.log('Upload results', bookResults) console.log('Upload results', itemResults)
}, },
updateBookCardStatus(index, status) { updateItemCardStatus(index, status) {
var ref = this.$refs[`bookCard-${index}`] var ref = this.$refs[`itemCard-${index}`]
if (ref && ref.length) ref = ref[0] if (ref && ref.length) ref = ref[0]
if (!ref) { if (!ref) {
console.error('Book card ref not found', index, this.$refs) console.error('Book card ref not found', index, this.$refs)
@ -218,16 +227,18 @@ export default {
ref.setUploadStatus(status) ref.setUploadStatus(status)
} }
}, },
uploadBook(book) { uploadItem(item) {
var form = new FormData() var form = new FormData()
form.set('title', book.title) form.set('title', item.title)
form.set('author', book.author) if (!this.selectedLibraryIsPodcast) {
form.set('series', book.series) form.set('author', item.author)
form.set('series', item.series)
}
form.set('library', this.selectedLibraryId) form.set('library', this.selectedLibraryId)
form.set('folder', this.selectedFolderId) form.set('folder', this.selectedFolderId)
var index = 0 var index = 0
book.files.forEach((file) => { item.files.forEach((file) => {
form.set(`${index++}`, file) form.set(`${index++}`, file)
}) })
@ -241,24 +252,24 @@ export default {
return false return false
}) })
}, },
validateBooks() { validateItems() {
var bookData = [] var itemData = []
for (var book of this.books) { for (var item of this.items) {
var bookref = this.$refs[`bookCard-${book.index}`] var itemref = this.$refs[`itemCard-${item.index}`]
if (bookref && bookref.length) bookref = bookref[0] if (itemref && itemref.length) itemref = itemref[0]
if (!bookref) { if (!itemref) {
console.error('Invalid book index no ref', book.index, this.$refs.bookCard) console.error('Invalid item index no ref', item.index, this.$refs.itemCard)
return false return false
} else { } else {
var data = bookref.getData() var data = itemref.getData()
if (!data) { if (!data) {
return false return false
} }
bookData.push(data) itemData.push(data)
} }
} }
return bookData return itemData
}, },
async submit() { async submit() {
if (!this.selectedFolderId || !this.selectedLibraryId) { if (!this.selectedFolderId || !this.selectedLibraryId) {
@ -267,27 +278,27 @@ export default {
return return
} }
var books = this.validateBooks() var items = this.validateItems()
if (!books) { if (!items) {
this.$toast.error('Some invalid books') this.$toast.error('Some invalid items')
return return
} }
this.processing = true this.processing = true
var booksUploaded = 0 var itemsUploaded = 0
var booksFailed = 0 var itemsFailed = 0
for (let i = 0; i < books.length; i++) { for (let i = 0; i < items.length; i++) {
var book = books[i] var item = items[i]
this.updateBookCardStatus(book.index, 'uploading') this.updateItemCardStatus(item.index, 'uploading')
var result = await this.uploadBook(book) var result = await this.uploadItem(item)
if (result) booksUploaded++ if (result) itemsUploaded++
else booksFailed++ else itemsFailed++
this.updateBookCardStatus(book.index, result ? 'success' : 'failed') this.updateItemCardStatus(item.index, result ? 'success' : 'failed')
} }
if (booksUploaded) { if (itemsUploaded) {
this.$toast.success(`Successfully uploaded ${booksUploaded} book${booksUploaded > 1 ? 's' : ''}`) this.$toast.success(`Successfully uploaded ${itemsUploaded} item${itemsUploaded > 1 ? 's' : ''}`)
} }
if (booksFailed) { if (itemsFailed) {
this.$toast.success(`Failed to upload ${booksFailed} book${booksFailed > 1 ? 's' : ''}`) this.$toast.success(`Failed to upload ${itemsFailed} item${itemsFailed > 1 ? 's' : ''}`)
} }
this.processing = false this.processing = false
this.uploadFinished = true this.uploadFinished = true

View File

@ -4,7 +4,7 @@ const SupportedFileTypes = {
ebook: ['epub', 'pdf', 'mobi', 'azw3', 'cbr', 'cbz'], ebook: ['epub', 'pdf', 'mobi', 'azw3', 'cbr', 'cbz'],
info: ['nfo'], info: ['nfo'],
text: ['txt'], text: ['txt'],
opf: ['opf'] metadata: ['opf', 'abs']
} }
const DownloadStatus = { const DownloadStatus = {

View File

@ -9,7 +9,7 @@ const UserCollection = require('./objects/UserCollection')
const Library = require('./objects/Library') const Library = require('./objects/Library')
const Author = require('./objects/entities/Author') const Author = require('./objects/entities/Author')
const Series = require('./objects/entities/Series') const Series = require('./objects/entities/Series')
const ServerSettings = require('./objects/ServerSettings') const ServerSettings = require('./objects/settings/ServerSettings')
const PlaybackSession = require('./objects/PlaybackSession') const PlaybackSession = require('./objects/PlaybackSession')
class Db { class Db {

View File

@ -69,19 +69,19 @@ class FolderWatcher extends EventEmitter {
initWatcher(libraries) { initWatcher(libraries) {
libraries.forEach((lib) => { libraries.forEach((lib) => {
if (!lib.disableWatcher) { if (!lib.settings.disableWatcher) {
this.buildLibraryWatcher(lib) this.buildLibraryWatcher(lib)
} }
}) })
} }
addLibrary(library) { addLibrary(library) {
if (this.disabled || library.disableWatcher) return if (this.disabled || library.settings.disableWatcher) return
this.buildLibraryWatcher(library) this.buildLibraryWatcher(library)
} }
updateLibrary(library) { updateLibrary(library) {
if (this.disabled || library.disableWatcher) return if (this.disabled || library.settings.disableWatcher) return
var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id) var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
if (libwatcher) { if (libwatcher) {
libwatcher.name = library.name libwatcher.name = library.name

View File

@ -1,6 +1,7 @@
const Path = require('path') const Path = require('path')
const fs = require('fs-extra') const fs = require('fs-extra')
const Logger = require('../Logger') const Logger = require('../Logger')
const filePerms = require('../utils/filePerms')
const { isObject } = require('../utils/index') const { isObject } = require('../utils/index')
@ -37,15 +38,21 @@ class MiscController {
} }
// For setting permissions recursively // For setting permissions recursively
var firstDirPath = Path.join(folder.fullPath, author)
var outputDirectory = '' var outputDirectory = ''
if (series && author) { var firstDirPath = ''
outputDirectory = Path.join(folder.fullPath, author, series, title)
} else if (author) { if (library.isPodcast) { // Podcasts only in 1 folder
outputDirectory = Path.join(folder.fullPath, author, title)
} else {
outputDirectory = Path.join(folder.fullPath, title) outputDirectory = Path.join(folder.fullPath, title)
firstDirPath = outputDirectory
} else {
firstDirPath = Path.join(folder.fullPath, author)
if (series && author) {
outputDirectory = Path.join(folder.fullPath, author, series, title)
} else if (author) {
outputDirectory = Path.join(folder.fullPath, author, title)
} else {
outputDirectory = Path.join(folder.fullPath, title)
}
} }
var exists = await fs.pathExists(outputDirectory) var exists = await fs.pathExists(outputDirectory)

View File

@ -139,31 +139,30 @@ class PodcastManager {
} }
async checkForNewEpisodes() { async checkForNewEpisodes() {
var podcastsWithAutoDownload = this.db.libraryItems.find(li => li.mediaType === 'podcast' && li.media.autoDownloadEpisodes) var podcastsWithAutoDownload = this.db.libraryItems.filter(li => li.mediaType === 'podcast' && li.media.autoDownloadEpisodes)
if (!podcastsWithAutoDownload.length) { if (!podcastsWithAutoDownload.length) {
this.cancelCron() this.cancelCron()
return return
} }
for (const libraryItem of podcastsWithAutoDownload) { for (const libraryItem of podcastsWithAutoDownload) {
Logger.info(`[PodcastManager] checkForNewEpisodes Cron for "${libraryItem.media.metadata.title}"`) const lastEpisodeCheckDate = new Date(libraryItem.media.lastEpisodeCheck || 0)
Logger.info(`[PodcastManager] checkForNewEpisodes Cron for "${libraryItem.media.metadata.title}" - Last episode check: ${lastEpisodeCheckDate}`)
var newEpisodes = await this.checkPodcastForNewEpisodes(libraryItem) var newEpisodes = await this.checkPodcastForNewEpisodes(libraryItem)
var hasUpdates = false
if (!newEpisodes) { // Failed if (!newEpisodes) { // Failed
libraryItem.media.autoDownloadEpisodes = false libraryItem.media.autoDownloadEpisodes = false
hasUpdates = true
} else if (newEpisodes.length) { } else if (newEpisodes.length) {
Logger.info(`[PodcastManager] Found ${newEpisodes.length} new episodes for podcast "${libraryItem.media.metadata.title}" - starting download`) Logger.info(`[PodcastManager] Found ${newEpisodes.length} new episodes for podcast "${libraryItem.media.metadata.title}" - starting download`)
this.downloadPodcastEpisodes(libraryItem, newEpisodes) this.downloadPodcastEpisodes(libraryItem, newEpisodes)
hasUpdates = true } else {
Logger.debug(`[PodcastManager] No new episodes for "${libraryItem.media.metadata.title}"`)
} }
if (hasUpdates) { libraryItem.media.lastEpisodeCheck = Date.now()
libraryItem.media.lastEpisodeCheck = Date.now() libraryItem.updatedAt = Date.now()
libraryItem.updatedAt = Date.now() await this.db.updateLibraryItem(libraryItem)
await this.db.updateLibraryItem(libraryItem) this.emitter('item_updated', libraryItem.toJSONExpanded())
this.emitter('item_updated', libraryItem.toJSONExpanded())
}
} }
} }

View File

@ -1,4 +1,5 @@
const Folder = require('./Folder') const Folder = require('./Folder')
const LibrarySettings = require('./settings/LibrarySettings')
const { getId } = require('../utils/index') const { getId } = require('../utils/index')
class Library { class Library {
@ -10,9 +11,9 @@ class Library {
this.icon = 'database' // database, podcast, book, audiobook, comic this.icon = 'database' // database, podcast, book, audiobook, comic
this.mediaType = 'book' // book, podcast this.mediaType = 'book' // book, podcast
this.provider = 'google' this.provider = 'google'
this.disableWatcher = false
this.lastScan = 0 this.lastScan = 0
this.settings = null
this.createdAt = null this.createdAt = null
this.lastUpdate = null this.lastUpdate = null
@ -25,6 +26,9 @@ class Library {
get folderPaths() { get folderPaths() {
return this.folders.map(f => f.fullPath) return this.folders.map(f => f.fullPath)
} }
get isPodcast() {
return this.mediaType === 'podcast'
}
construct(library) { construct(library) {
this.id = library.id this.id = library.id
@ -34,7 +38,11 @@ class Library {
this.icon = library.icon || 'database' this.icon = library.icon || 'database'
this.mediaType = library.mediaType this.mediaType = library.mediaType
this.provider = library.provider || 'google' this.provider = library.provider || 'google'
this.disableWatcher = !!library.disableWatcher
this.settings = new LibrarySettings(library.settings)
if (library.settings === undefined) { // LibrarySettings added in v2, migrate settings
this.settings.disableWatcher = !!library.disableWatcher
}
this.createdAt = library.createdAt this.createdAt = library.createdAt
this.lastUpdate = library.lastUpdate this.lastUpdate = library.lastUpdate
@ -62,7 +70,7 @@ class Library {
icon: this.icon, icon: this.icon,
mediaType: this.mediaType, mediaType: this.mediaType,
provider: this.provider, provider: this.provider,
disableWatcher: this.disableWatcher, settings: this.settings.toJSON(),
createdAt: this.createdAt, createdAt: this.createdAt,
lastUpdate: this.lastUpdate lastUpdate: this.lastUpdate
} }
@ -89,7 +97,7 @@ class Library {
this.icon = data.icon || 'database' this.icon = data.icon || 'database'
this.mediaType = data.mediaType || 'book' this.mediaType = data.mediaType || 'book'
this.provider = data.provider || 'google' this.provider = data.provider || 'google'
this.disableWatcher = !!data.disableWatcher this.settings = new LibrarySettings(data.settings)
this.createdAt = Date.now() this.createdAt = Date.now()
this.lastUpdate = Date.now() this.lastUpdate = Date.now()
} }
@ -105,10 +113,10 @@ class Library {
} }
}) })
if (payload.disableWatcher !== this.disableWatcher) { if (payload.settings && this.settings.update(payload.settings)) {
this.disableWatcher = !!payload.disableWatcher
hasUpdates = true hasUpdates = true
} }
if (!isNaN(payload.displayOrder) && payload.displayOrder !== this.displayOrder) { if (!isNaN(payload.displayOrder) && payload.displayOrder !== this.displayOrder) {
this.displayOrder = Number(payload.displayOrder) this.displayOrder = Number(payload.displayOrder)
hasUpdates = true hasUpdates = true

View File

@ -0,0 +1,34 @@
const { BookCoverAspectRatio } = require('../../utils/constants')
const Logger = require('../../Logger')
class LibrarySettings {
constructor(settings) {
this.disableWatcher = false
if (settings) {
this.construct(settings)
}
}
construct(settings) {
this.disableWatcher = !!settings.disableWatcher
}
toJSON() {
return {
disableWatcher: this.disableWatcher
}
}
update(payload) {
var hasUpdates = false
for (const key in payload) {
if (this[key] !== payload[key]) {
this[key] = payload[key]
hasUpdates = true
}
}
return hasUpdates
}
}
module.exports = LibrarySettings

View File

@ -1,5 +1,5 @@
const { BookCoverAspectRatio, BookshelfView } = require('../utils/constants') const { BookCoverAspectRatio, BookshelfView } = require('../../utils/constants')
const Logger = require('../Logger') const Logger = require('../../Logger')
class ServerSettings { class ServerSettings {
constructor(settings) { constructor(settings) {