2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2022-06-26 18:15:19 +02:00
|
|
|
<div class="w-full h-full overflow-hidden overflow-y-auto px-2 sm:px-4 py-6 relative">
|
2024-04-07 23:24:23 +02:00
|
|
|
<div class="flex flex-col sm:flex-row mb-4">
|
|
|
|
<div class="relative self-center">
|
2023-07-15 19:37:33 +02:00
|
|
|
<covers-preview-cover :src="$store.getters['globals/getLibraryItemCoverSrcById'](libraryItemId, libraryItemUpdatedAt, true)" :width="120" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2023-04-01 00:42:52 +02:00
|
|
|
|
2021-08-26 02:15:00 +02:00
|
|
|
<!-- book cover overlay -->
|
2022-03-11 01:45:02 +01:00
|
|
|
<div v-if="media.coverPath" class="absolute top-0 left-0 w-full h-full z-10 opacity-0 hover:opacity-100 transition-opacity duration-100">
|
2021-08-26 02:15:00 +02:00
|
|
|
<div class="absolute top-0 left-0 w-full h-16 bg-gradient-to-b from-black-600 to-transparent" />
|
2023-10-13 23:33:47 +02:00
|
|
|
<div v-if="userCanDelete" 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">
|
2022-11-20 18:50:34 +01:00
|
|
|
<ui-tooltip direction="top" :text="$strings.LabelRemoveCover">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols text-2xl">delete</span>
|
2022-11-20 18:50:34 +01:00
|
|
|
</ui-tooltip>
|
2021-08-26 02:15:00 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-07 23:24:23 +02:00
|
|
|
<div class="flex-grow sm:pl-2 md:pl-6 sm:pr-2 mt-6 md:mt-0">
|
2021-09-22 03:57:33 +02:00
|
|
|
<div class="flex items-center">
|
2023-10-13 23:33:47 +02:00
|
|
|
<div v-if="userCanUpload" class="w-10 md:w-40 pr-2 md:min-w-32">
|
2023-05-10 01:26:37 +02:00
|
|
|
<ui-file-input ref="fileInput" @change="fileUploadSelected">
|
|
|
|
<span class="hidden md:inline-block">{{ $strings.ButtonUploadCover }}</span>
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols text-2xl inline-block md:!hidden">upload</span>
|
2023-05-10 01:26:37 +02:00
|
|
|
</ui-file-input>
|
2021-09-22 03:57:33 +02:00
|
|
|
</div>
|
2023-10-13 23:33:47 +02:00
|
|
|
|
2021-09-22 03:57:33 +02:00
|
|
|
<form @submit.prevent="submitForm" class="flex flex-grow">
|
2023-10-13 23:33:47 +02:00
|
|
|
<ui-text-input v-model="imageUrl" :placeholder="$strings.LabelImageURLFromTheWeb" class="h-9 w-full" />
|
|
|
|
<ui-btn color="success" type="submit" :padding-x="4" :disabled="!imageUrl" class="ml-2 sm:ml-3 w-24 h-9">{{ $strings.ButtonSubmit }}</ui-btn>
|
2021-09-22 03:57:33 +02:00
|
|
|
</form>
|
|
|
|
</div>
|
2021-08-21 16:15:44 +02:00
|
|
|
|
2023-04-01 00:42:52 +02:00
|
|
|
<div v-if="localCovers.length" class="mb-4 mt-6 border-t border-b border-white border-opacity-10">
|
2021-08-21 23:23:35 +02:00
|
|
|
<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" />
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-btn small @click="showLocalCovers = !showLocalCovers">{{ showLocalCovers ? $strings.ButtonHide : $strings.ButtonShow }}</ui-btn>
|
2021-08-21 23:23:35 +02:00
|
|
|
</div>
|
|
|
|
|
2023-04-01 00:42:52 +02:00
|
|
|
<div v-if="showLocalCovers" class="flex items-center justify-center pb-2">
|
2023-05-28 19:34:22 +02:00
|
|
|
<template v-for="localCoverFile in localCovers">
|
|
|
|
<div :key="localCoverFile.ino" class="m-0.5 mb-5 border-2 border-transparent hover:border-yellow-300 cursor-pointer" :class="localCoverFile.metadata.path === coverPath ? 'border-yellow-300' : ''" @click="setCover(localCoverFile)">
|
2021-12-03 02:02:38 +01:00
|
|
|
<div class="h-24 bg-primary" :style="{ width: 96 / bookCoverAspectRatio + 'px' }">
|
2023-05-28 19:34:22 +02:00
|
|
|
<covers-preview-cover :src="localCoverFile.localPath" :width="96 / bookCoverAspectRatio" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
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">
|
2024-04-07 23:24:23 +02:00
|
|
|
<div class="flex flex-wrap sm:flex-nowrap items-center justify-start -mx-1">
|
|
|
|
<div class="w-48 flex-grow p-1">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-dropdown v-model="provider" :items="providers" :label="$strings.LabelProvider" small />
|
2021-12-08 01:42:56 +01:00
|
|
|
</div>
|
2024-04-07 23:24:23 +02:00
|
|
|
<div class="w-72 flex-grow p-1">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-text-input-with-label v-model="searchTitle" :label="searchTitleLabel" :placeholder="$strings.PlaceholderSearch" />
|
2021-12-08 01:42:56 +01:00
|
|
|
</div>
|
2024-04-07 23:24:23 +02:00
|
|
|
<div v-show="provider != 'itunes' && provider != 'audiobookcovers'" class="w-72 flex-grow p-1">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-text-input-with-label v-model="searchAuthor" :label="$strings.LabelAuthor" />
|
2021-08-21 16:15:44 +02:00
|
|
|
</div>
|
2024-04-07 23:24:23 +02:00
|
|
|
<ui-btn class="mt-5 ml-1 md:min-w-24" :padding-x="4" type="submit">{{ $strings.ButtonSearch }}</ui-btn>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
2021-12-08 01:42:56 +01:00
|
|
|
</form>
|
2024-04-07 23:24:23 +02:00
|
|
|
<div v-if="hasSearched" class="flex items-center flex-wrap justify-center sm:max-h-80 sm:overflow-y-scroll mt-2 max-w-full">
|
2022-11-08 01:27:17 +01:00
|
|
|
<p v-if="!coversFound.length">{{ $strings.MessageNoCoversFound }}</p>
|
2021-12-08 01:42:56 +01:00
|
|
|
<template v-for="cover in coversFound">
|
2023-10-13 23:33:47 +02:00
|
|
|
<div :key="cover" class="m-0.5 mb-5 border-2 border-transparent hover:border-yellow-300 cursor-pointer" :class="cover === coverPath ? 'border-yellow-300' : ''" @click="updateCover(cover)">
|
2021-12-08 01:42:56 +01:00
|
|
|
<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">
|
2022-11-08 01:27:17 +01:00
|
|
|
<p class="text-lg">{{ $strings.HeaderPreviewCover }}</p>
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="absolute top-4 right-4 material-symbols text-2xl cursor-pointer" @click="resetCoverPreview">close</span>
|
2021-09-22 03:57:33 +02:00
|
|
|
<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">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-btn :disabled="processingUpload" class="mx-2" @click="resetCoverPreview">{{ $strings.ButtonReset }}</ui-btn>
|
|
|
|
<ui-btn :loading="processingUpload" color="success" @click="submitCoverUpload">{{ $strings.ButtonUpload }}</ui-btn>
|
2021-09-22 03:57:33 +02:00
|
|
|
</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,
|
2022-03-11 01:45:02 +01:00
|
|
|
libraryItem: {
|
2021-08-18 00:01:11 +02:00
|
|
|
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: {
|
2022-03-11 01:45:02 +01:00
|
|
|
libraryItem: {
|
2021-08-18 00:01:11 +02:00
|
|
|
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() {
|
2022-04-14 01:13:39 +02:00
|
|
|
if (this.isPodcast) return this.$store.state.scanners.podcastProviders
|
2023-05-14 20:43:20 +02:00
|
|
|
return [{ text: 'All', value: 'all' }, ...this.$store.state.scanners.providers, ...this.$store.state.scanners.coverOnlyProviders]
|
2022-03-07 00:26:35 +01:00
|
|
|
},
|
|
|
|
searchTitleLabel() {
|
2022-11-08 01:27:17 +01:00
|
|
|
if (this.provider.startsWith('audible')) return this.$strings.LabelSearchTitleOrASIN
|
|
|
|
else if (this.provider == 'itunes') return this.$strings.LabelSearchTerm
|
|
|
|
return this.$strings.LabelSearchTitle
|
2022-03-07 00:26:35 +01:00
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
bookCoverAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
libraryItemId() {
|
2023-07-15 19:37:33 +02:00
|
|
|
return this.libraryItem?.id || null
|
|
|
|
},
|
|
|
|
libraryItemUpdatedAt() {
|
|
|
|
return this.libraryItem?.updatedAt || null
|
2021-10-06 04:10:49 +02:00
|
|
|
},
|
2022-04-14 01:13:39 +02:00
|
|
|
mediaType() {
|
2023-07-15 19:37:33 +02:00
|
|
|
return this.libraryItem?.mediaType || null
|
2022-04-14 01:13:39 +02:00
|
|
|
},
|
|
|
|
isPodcast() {
|
|
|
|
return this.mediaType == 'podcast'
|
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
media() {
|
2023-07-15 19:37:33 +02:00
|
|
|
return this.libraryItem?.media || {}
|
2021-08-21 23:23:35 +02:00
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
coverPath() {
|
|
|
|
return this.media.coverPath
|
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || {}
|
2021-10-06 04:10:49 +02:00
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
libraryFiles() {
|
2023-07-15 19:37:33 +02:00
|
|
|
return this.libraryItem?.libraryFiles || []
|
2021-08-21 23:23:35 +02:00
|
|
|
},
|
2021-09-22 03:57:33 +02:00
|
|
|
userCanUpload() {
|
|
|
|
return this.$store.getters['user/getUserCanUpload']
|
|
|
|
},
|
2023-10-13 23:33:47 +02:00
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
|
|
|
},
|
2021-10-06 04:10:49 +02:00
|
|
|
userToken() {
|
|
|
|
return this.$store.getters['user/getToken']
|
|
|
|
},
|
2021-08-21 23:23:35 +02:00
|
|
|
localCovers() {
|
2022-03-11 01:45:02 +01:00
|
|
|
return this.libraryFiles
|
|
|
|
.filter((f) => f.fileType === 'image')
|
2021-08-21 23:23:35 +02:00
|
|
|
.map((file) => {
|
2023-05-28 19:34:22 +02:00
|
|
|
const _file = { ...file }
|
|
|
|
_file.localPath = `${process.env.serverUrl}/api/items/${this.libraryItemId}/file/${file.ino}?token=${this.userToken}`
|
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
|
2022-03-13 00:45:32 +01:00
|
|
|
.$post(`/api/items/${this.libraryItemId}/cover`, form)
|
2021-09-22 03:57:33 +02:00
|
|
|
.then((data) => {
|
|
|
|
if (data.error) {
|
|
|
|
this.$toast.error(data.error)
|
|
|
|
} else {
|
|
|
|
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 {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastUnknownError)
|
2021-10-02 01:42:48 +02:00
|
|
|
}
|
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
|
2022-03-11 01:45:02 +01:00
|
|
|
if (this.coversFound.length && (this.searchTitle !== this.mediaMetadata.title || this.searchAuthor !== this.mediaMetadata.authorName)) {
|
2021-08-21 16:15:44 +02:00
|
|
|
this.coversFound = []
|
|
|
|
this.hasSearched = false
|
|
|
|
}
|
2023-10-13 23:33:47 +02:00
|
|
|
this.imageUrl = ''
|
2022-03-11 01:45:02 +01:00
|
|
|
this.searchTitle = this.mediaMetadata.title || ''
|
|
|
|
this.searchAuthor = this.mediaMetadata.authorName || ''
|
2022-04-14 01:13:39 +02:00
|
|
|
if (this.isPodcast) this.provider = 'itunes'
|
2023-05-10 01:26:37 +02:00
|
|
|
else this.provider = localStorage.getItem('book-cover-provider') || localStorage.getItem('book-provider') || 'google'
|
2021-08-21 16:15:44 +02:00
|
|
|
},
|
2021-08-26 02:15:00 +02:00
|
|
|
removeCover() {
|
2023-10-13 23:33:47 +02:00
|
|
|
if (!this.coverPath) {
|
2021-08-26 02:15:00 +02:00
|
|
|
return
|
|
|
|
}
|
2023-10-13 23:33:47 +02:00
|
|
|
this.isProcessing = true
|
|
|
|
this.$axios
|
|
|
|
.$delete(`/api/items/${this.libraryItemId}/cover`)
|
|
|
|
.then(() => {})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove cover', error)
|
|
|
|
if (error.response?.data) {
|
|
|
|
this.$toast.error(error.response.data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.isProcessing = false
|
|
|
|
})
|
2021-08-26 02:15:00 +02:00
|
|
|
},
|
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) {
|
2023-10-13 23:33:47 +02:00
|
|
|
if (!cover.startsWith('http:') && !cover.startsWith('https:')) {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastInvalidUrl)
|
2021-08-26 02:15:00 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-18 00:43:29 +02:00
|
|
|
this.isProcessing = true
|
2023-10-13 23:33:47 +02:00
|
|
|
this.$axios
|
|
|
|
.$post(`/api/items/${this.libraryItemId}/cover`, { url: cover })
|
|
|
|
.then(() => {
|
|
|
|
this.imageUrl = ''
|
2021-10-02 01:42:48 +02:00
|
|
|
})
|
2023-10-13 23:33:47 +02:00
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update cover', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(error.response?.data || this.$strings.ToastCoverUpdateFailed)
|
2023-10-13 23:33:47 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.isProcessing = false
|
2021-10-02 01:42:48 +02:00
|
|
|
})
|
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}`
|
2023-05-14 20:43:20 +02:00
|
|
|
if (this.searchAuthor) searchQuery += `&author=${this.searchAuthor || ''}`
|
2022-04-14 01:13:39 +02:00
|
|
|
if (this.isPodcast) searchQuery += '&podcast=1'
|
2021-08-21 16:15:44 +02:00
|
|
|
return searchQuery
|
|
|
|
},
|
2021-12-08 01:42:56 +01:00
|
|
|
persistProvider() {
|
|
|
|
try {
|
2023-05-10 01:26:37 +02:00
|
|
|
localStorage.setItem('book-cover-provider', this.provider)
|
2021-12-08 01:42:56 +01:00
|
|
|
} 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
|
2022-12-13 00:45:51 +01:00
|
|
|
const searchQuery = this.getSearchQuery()
|
|
|
|
const results = await this.$axios
|
|
|
|
.$get(`/api/search/covers?${searchQuery}`)
|
|
|
|
.then((res) => res.results)
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
return []
|
|
|
|
})
|
2021-08-21 16:15:44 +02:00
|
|
|
this.coversFound = results
|
|
|
|
this.isProcessing = false
|
|
|
|
this.hasSearched = true
|
|
|
|
},
|
2021-10-16 03:31:00 +02:00
|
|
|
setCover(coverFile) {
|
2023-10-13 23:33:47 +02:00
|
|
|
this.isProcessing = true
|
|
|
|
this.$axios
|
|
|
|
.$patch(`/api/items/${this.libraryItemId}/cover`, { cover: coverFile.metadata.path })
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to set local cover', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(error.response?.data || this.$strings.ToastCoverUpdateFailed)
|
2023-10-13 23:33:47 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.isProcessing = false
|
|
|
|
})
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-31 00:47:49 +02:00
|
|
|
</script>
|