2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-09-22 03:57:33 +02:00
|
|
|
<div class="w-full h-full overflow-hidden overflow-y-auto px-4 py-6 relative">
|
2021-08-18 00:01:11 +02:00
|
|
|
<div class="flex">
|
2021-08-26 02:15:00 +02:00
|
|
|
<div class="relative">
|
2021-12-03 02:02:38 +01:00
|
|
|
<covers-book-cover :audiobook="audiobook" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-08-26 02:15:00 +02:00
|
|
|
<!-- book cover overlay -->
|
|
|
|
<div v-if="book.cover" class="absolute top-0 left-0 w-full h-full z-10 opacity-0 hover:opacity-100 transition-opacity duration-100">
|
|
|
|
<div class="absolute top-0 left-0 w-full h-16 bg-gradient-to-b from-black-600 to-transparent" />
|
|
|
|
<div class="p-1 absolute top-1 right-1 text-red-500 rounded-full w-8 h-8 cursor-pointer hover:text-red-400 shadow-sm" @click="removeCover">
|
|
|
|
<span class="material-icons">delete</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-21 16:15:44 +02:00
|
|
|
<div class="flex-grow pl-6 pr-2">
|
2021-09-22 03:57:33 +02:00
|
|
|
<div class="flex items-center">
|
2021-10-09 00:30:20 +02:00
|
|
|
<div v-if="userCanUpload" class="w-40 pr-2 pt-4" style="min-width: 160px">
|
|
|
|
<ui-file-input ref="fileInput" @change="fileUploadSelected">Upload Cover</ui-file-input>
|
2021-09-22 03:57:33 +02:00
|
|
|
</div>
|
|
|
|
<form @submit.prevent="submitForm" class="flex flex-grow">
|
2021-08-18 00:43:29 +02:00
|
|
|
<ui-text-input-with-label v-model="imageUrl" label="Cover Image URL" />
|
2021-08-21 16:15:44 +02:00
|
|
|
<ui-btn color="success" type="submit" :padding-x="4" class="mt-5 ml-3 w-24">Update</ui-btn>
|
2021-09-22 03:57:33 +02:00
|
|
|
</form>
|
|
|
|
</div>
|
2021-08-21 16:15:44 +02:00
|
|
|
|
2021-08-21 23:23:35 +02:00
|
|
|
<div v-if="localCovers.length" class="mb-4 mt-6 border-t border-b border-primary">
|
|
|
|
<div class="flex items-center justify-center py-2">
|
2021-10-09 00:30:20 +02:00
|
|
|
<p>{{ localCovers.length }} local image{{ localCovers.length !== 1 ? 's' : '' }}</p>
|
2021-08-21 23:23:35 +02:00
|
|
|
<div class="flex-grow" />
|
|
|
|
<ui-btn small @click="showLocalCovers = !showLocalCovers">{{ showLocalCovers ? 'Hide' : 'Show' }}</ui-btn>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="showLocalCovers" class="flex items-center justify-center">
|
|
|
|
<template v-for="cover in localCovers">
|
2021-10-16 03:31:00 +02:00
|
|
|
<div :key="cover.path" class="m-0.5 border-2 border-transparent hover:border-yellow-300 cursor-pointer" :class="cover.localPath === imageUrl ? 'border-yellow-300' : ''" @click="setCover(cover)">
|
2021-12-03 02:02:38 +01:00
|
|
|
<div class="h-24 bg-primary" :style="{ width: 96 / bookCoverAspectRatio + 'px' }">
|
2021-10-06 04:10:49 +02:00
|
|
|
<img :src="`${cover.localPath}?token=${userToken}`" class="h-full w-full object-contain" />
|
2021-08-26 15:04:52 +02:00
|
|
|
</div>
|
2021-08-21 23:23:35 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-08 01:42:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<form @submit.prevent="submitSearchForm">
|
|
|
|
<div class="flex items-center justify-start -mx-1 h-20">
|
|
|
|
<div class="w-40 px-1">
|
|
|
|
<ui-dropdown v-model="provider" :items="providers" label="Provider" small />
|
|
|
|
</div>
|
|
|
|
<div class="w-72 px-1">
|
2022-03-07 00:26:35 +01:00
|
|
|
<ui-text-input-with-label v-model="searchTitle" :label="searchTitleLabel" placeholder="Search" />
|
2021-12-08 01:42:56 +01:00
|
|
|
</div>
|
2022-03-07 00:26:35 +01:00
|
|
|
<div v-show="provider != 'itunes'" class="w-72 px-1">
|
2021-12-08 01:42:56 +01:00
|
|
|
<ui-text-input-with-label v-model="searchAuthor" label="Author" />
|
2021-08-21 16:15:44 +02:00
|
|
|
</div>
|
2021-12-08 01:42:56 +01:00
|
|
|
<ui-btn class="mt-5 ml-1" type="submit">Search</ui-btn>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
2021-12-08 01:42:56 +01:00
|
|
|
</form>
|
|
|
|
<div v-if="hasSearched" class="flex items-center flex-wrap justify-center max-h-80 overflow-y-scroll mt-2 max-w-full">
|
|
|
|
<p v-if="!coversFound.length">No Covers Found</p>
|
|
|
|
<template v-for="cover in coversFound">
|
|
|
|
<div :key="cover" class="m-0.5 border-2 border-transparent hover:border-yellow-300 cursor-pointer" :class="cover === imageUrl ? 'border-yellow-300' : ''" @click="updateCover(cover)">
|
|
|
|
<covers-preview-cover :src="cover" :width="80" show-open-new-tab :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
2021-09-22 03:57:33 +02:00
|
|
|
|
|
|
|
<div v-if="previewUpload" class="absolute top-0 left-0 w-full h-full z-10 bg-bg p-8">
|
|
|
|
<p class="text-lg">Preview Cover</p>
|
|
|
|
<span class="absolute top-4 right-4 material-icons text-2xl cursor-pointer" @click="resetCoverPreview">close</span>
|
|
|
|
<div class="flex justify-center py-4">
|
2021-12-03 02:02:38 +01:00
|
|
|
<covers-preview-cover :src="previewUpload" :width="240" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-09-22 03:57:33 +02:00
|
|
|
</div>
|
|
|
|
<div class="absolute bottom-0 right-0 flex py-4 px-5">
|
|
|
|
<ui-btn :disabled="processingUpload" class="mx-2" @click="resetCoverPreview">Clear</ui-btn>
|
|
|
|
<ui-btn :loading="processingUpload" color="success" @click="submitCoverUpload">Upload</ui-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
2021-08-18 00:43:29 +02:00
|
|
|
processing: Boolean,
|
2021-08-18 00:01:11 +02:00
|
|
|
audiobook: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-09-22 03:57:33 +02:00
|
|
|
processingUpload: false,
|
2021-08-21 16:15:44 +02:00
|
|
|
searchTitle: null,
|
|
|
|
searchAuthor: null,
|
|
|
|
imageUrl: null,
|
|
|
|
coversFound: [],
|
2021-08-21 23:23:35 +02:00
|
|
|
hasSearched: false,
|
2021-09-22 03:57:33 +02:00
|
|
|
showLocalCovers: false,
|
|
|
|
previewUpload: null,
|
2021-12-08 01:42:56 +01:00
|
|
|
selectedFile: null,
|
|
|
|
provider: 'google'
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
audiobook: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newVal) {
|
2021-08-26 02:15:00 +02:00
|
|
|
if (newVal) {
|
|
|
|
this.init()
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-08-18 00:43:29 +02:00
|
|
|
computed: {
|
|
|
|
isProcessing: {
|
|
|
|
get() {
|
|
|
|
return this.processing
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('update:processing', val)
|
|
|
|
}
|
|
|
|
},
|
2022-03-07 00:26:35 +01:00
|
|
|
providers() {
|
|
|
|
return this.$store.state.scanners.providers
|
|
|
|
},
|
|
|
|
searchTitleLabel() {
|
|
|
|
if (this.provider == 'audible') return 'Search Title or ASIN'
|
|
|
|
else if (this.provider == 'itunes') return 'Search Term'
|
|
|
|
return 'Search Title'
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
coverAspectRatio() {
|
|
|
|
return this.$store.getters['getServerSetting']('coverAspectRatio')
|
|
|
|
},
|
|
|
|
bookCoverAspectRatio() {
|
|
|
|
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE ? 1 : 1.6
|
|
|
|
},
|
2021-10-06 04:10:49 +02:00
|
|
|
audiobookId() {
|
|
|
|
return this.audiobook ? this.audiobook.id : null
|
|
|
|
},
|
2021-08-18 00:43:29 +02:00
|
|
|
book() {
|
|
|
|
return this.audiobook ? this.audiobook.book || {} : {}
|
2021-08-21 23:23:35 +02:00
|
|
|
},
|
2021-10-06 04:10:49 +02:00
|
|
|
audiobookPath() {
|
|
|
|
return this.audiobook ? this.audiobook.path : null
|
|
|
|
},
|
2021-08-21 23:23:35 +02:00
|
|
|
otherFiles() {
|
|
|
|
return this.audiobook ? this.audiobook.otherFiles || [] : []
|
|
|
|
},
|
2021-09-22 03:57:33 +02:00
|
|
|
userCanUpload() {
|
|
|
|
return this.$store.getters['user/getUserCanUpload']
|
|
|
|
},
|
2021-10-06 04:10:49 +02:00
|
|
|
userToken() {
|
|
|
|
return this.$store.getters['user/getToken']
|
|
|
|
},
|
2021-08-21 23:23:35 +02:00
|
|
|
localCovers() {
|
|
|
|
return this.otherFiles
|
|
|
|
.filter((f) => f.filetype === 'image')
|
|
|
|
.map((file) => {
|
|
|
|
var _file = { ...file }
|
2021-10-06 04:10:49 +02:00
|
|
|
var imgRelPath = _file.path.replace(this.audiobookPath, '')
|
2021-11-06 23:26:44 +01:00
|
|
|
_file.localPath = `/s/book/${this.audiobookId}/${imgRelPath}`
|
2021-08-21 23:23:35 +02:00
|
|
|
return _file
|
|
|
|
})
|
2021-08-18 00:43:29 +02:00
|
|
|
}
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
methods: {
|
2021-09-22 03:57:33 +02:00
|
|
|
submitCoverUpload() {
|
|
|
|
this.processingUpload = true
|
|
|
|
var form = new FormData()
|
|
|
|
form.set('cover', this.selectedFile)
|
|
|
|
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$post(`/api/books/${this.audiobook.id}/cover`, form)
|
2021-09-22 03:57:33 +02:00
|
|
|
.then((data) => {
|
|
|
|
if (data.error) {
|
|
|
|
this.$toast.error(data.error)
|
|
|
|
} else {
|
|
|
|
this.$toast.success('Cover Uploaded')
|
|
|
|
this.resetCoverPreview()
|
|
|
|
}
|
|
|
|
this.processingUpload = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
2021-10-02 01:42:48 +02:00
|
|
|
if (error.response && error.response.data) {
|
|
|
|
this.$toast.error(error.response.data)
|
|
|
|
} else {
|
|
|
|
this.$toast.error('Oops, something went wrong...')
|
|
|
|
}
|
2021-09-22 03:57:33 +02:00
|
|
|
this.processingUpload = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
resetCoverPreview() {
|
|
|
|
if (this.$refs.fileInput) {
|
|
|
|
this.$refs.fileInput.reset()
|
|
|
|
}
|
|
|
|
this.previewUpload = null
|
|
|
|
this.selectedFile = null
|
|
|
|
},
|
|
|
|
fileUploadSelected(file) {
|
|
|
|
this.previewUpload = URL.createObjectURL(file)
|
|
|
|
this.selectedFile = file
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
init() {
|
2021-08-21 23:23:35 +02:00
|
|
|
this.showLocalCovers = false
|
2021-10-24 03:31:48 +02:00
|
|
|
if (this.coversFound.length && (this.searchTitle !== this.book.title || this.searchAuthor !== this.book.authorFL)) {
|
2021-08-21 16:15:44 +02:00
|
|
|
this.coversFound = []
|
|
|
|
this.hasSearched = false
|
|
|
|
}
|
2021-08-18 00:43:29 +02:00
|
|
|
this.imageUrl = this.book.cover || ''
|
2021-08-21 16:15:44 +02:00
|
|
|
this.searchTitle = this.book.title || ''
|
2021-10-24 03:31:48 +02:00
|
|
|
this.searchAuthor = this.book.authorFL || ''
|
2021-12-08 01:42:56 +01:00
|
|
|
this.provider = localStorage.getItem('book-provider') || 'openlibrary'
|
2021-08-21 16:15:44 +02:00
|
|
|
},
|
2021-08-26 02:15:00 +02:00
|
|
|
removeCover() {
|
|
|
|
if (!this.book.cover) {
|
|
|
|
this.imageUrl = ''
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.updateCover('')
|
|
|
|
},
|
2021-08-21 16:15:44 +02:00
|
|
|
submitForm() {
|
|
|
|
this.updateCover(this.imageUrl)
|
2021-08-18 00:43:29 +02:00
|
|
|
},
|
2021-08-21 16:15:44 +02:00
|
|
|
async updateCover(cover) {
|
2021-08-26 02:15:00 +02:00
|
|
|
if (cover === this.book.cover) {
|
|
|
|
console.warn('Cover has not changed..', cover)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-18 00:43:29 +02:00
|
|
|
this.isProcessing = true
|
2021-10-02 01:42:48 +02:00
|
|
|
var success = false
|
|
|
|
|
|
|
|
// Download cover from url and use
|
|
|
|
if (cover.startsWith('http:') || cover.startsWith('https:')) {
|
2021-11-22 03:00:40 +01:00
|
|
|
success = await this.$axios.$post(`/api/books/${this.audiobook.id}/cover`, { url: cover }).catch((error) => {
|
2021-10-02 01:42:48 +02:00
|
|
|
console.error('Failed to download cover from url', error)
|
|
|
|
if (error.response && error.response.data) {
|
|
|
|
this.$toast.error(error.response.data)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// Update local cover url
|
|
|
|
const updatePayload = {
|
|
|
|
book: {
|
|
|
|
cover: cover
|
|
|
|
}
|
2021-08-18 00:43:29 +02:00
|
|
|
}
|
2021-11-22 03:00:40 +01:00
|
|
|
success = await this.$axios.$patch(`/api/books/${this.audiobook.id}`, updatePayload).catch((error) => {
|
2021-10-02 01:42:48 +02:00
|
|
|
console.error('Failed to update', error)
|
|
|
|
if (error.response && error.response.data) {
|
|
|
|
this.$toast.error(error.response.data)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2021-08-18 00:43:29 +02:00
|
|
|
}
|
2021-10-02 01:42:48 +02:00
|
|
|
if (success) {
|
2021-08-18 00:43:29 +02:00
|
|
|
this.$toast.success('Update Successful')
|
|
|
|
this.$emit('close')
|
2021-10-02 01:42:48 +02:00
|
|
|
} else {
|
|
|
|
this.imageUrl = this.book.cover || ''
|
2021-08-18 00:43:29 +02:00
|
|
|
}
|
2021-10-02 01:42:48 +02:00
|
|
|
this.isProcessing = false
|
2021-08-21 16:15:44 +02:00
|
|
|
},
|
|
|
|
getSearchQuery() {
|
2021-12-08 01:42:56 +01:00
|
|
|
var searchQuery = `provider=${this.provider}&title=${this.searchTitle}`
|
2021-08-21 16:15:44 +02:00
|
|
|
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor}`
|
|
|
|
return searchQuery
|
|
|
|
},
|
2021-12-08 01:42:56 +01:00
|
|
|
persistProvider() {
|
|
|
|
try {
|
|
|
|
localStorage.setItem('book-provider', this.provider)
|
|
|
|
} catch (error) {
|
|
|
|
console.error('PersistProvider', error)
|
|
|
|
}
|
|
|
|
},
|
2021-08-21 16:15:44 +02:00
|
|
|
async submitSearchForm() {
|
2021-12-08 01:42:56 +01:00
|
|
|
// Store provider in local storage
|
|
|
|
this.persistProvider()
|
|
|
|
|
2021-08-21 16:15:44 +02:00
|
|
|
this.isProcessing = true
|
|
|
|
var searchQuery = this.getSearchQuery()
|
2021-12-08 01:42:56 +01:00
|
|
|
var results = await this.$axios.$get(`/api/search/covers?${searchQuery}`).catch((error) => {
|
2021-08-21 16:15:44 +02:00
|
|
|
console.error('Failed', error)
|
|
|
|
return []
|
|
|
|
})
|
|
|
|
this.coversFound = results
|
|
|
|
this.isProcessing = false
|
|
|
|
this.hasSearched = true
|
|
|
|
},
|
2021-10-16 03:31:00 +02:00
|
|
|
setCover(coverFile) {
|
|
|
|
this.isProcessing = true
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$patch(`/api/books/${this.audiobook.id}/coverfile`, coverFile)
|
2021-10-16 03:31:00 +02:00
|
|
|
.then((data) => {
|
|
|
|
console.log('response data', data)
|
|
|
|
if (data && typeof data === 'string') {
|
|
|
|
this.$toast.success(data)
|
|
|
|
}
|
|
|
|
this.isProcessing = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update', error)
|
|
|
|
if (error.response && error.response.data) {
|
|
|
|
this.$toast.error(error.response.data)
|
|
|
|
}
|
|
|
|
this.isProcessing = false
|
|
|
|
})
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|