Fix Cover modal showing error image for items with no cover, update placeholder cover url to all come from global store

This commit is contained in:
advplyr 2025-03-27 17:37:25 -05:00
parent 7f3421f78a
commit 718433183b
7 changed files with 22 additions and 15 deletions

View File

@ -223,8 +223,7 @@ export default {
return this.mediaMetadata.explicit || false return this.mediaMetadata.explicit || false
}, },
placeholderUrl() { placeholderUrl() {
const config = this.$config || this.$nuxt.$config return this.store.getters['globals/getPlaceholderCoverSrc']
return `${config.routerBasePath}/book_placeholder.jpg`
}, },
bookCoverSrc() { bookCoverSrc() {
return this.store.getters['globals/getLibraryItemCoverSrc'](this._libraryItem, this.placeholderUrl) return this.store.getters['globals/getLibraryItemCoverSrc'](this._libraryItem, this.placeholderUrl)

View File

@ -96,8 +96,8 @@ export default {
return this.author return this.author
}, },
placeholderUrl() { placeholderUrl() {
const config = this.$config || this.$nuxt.$config const store = this.$store || this.$nuxt.$store
return `${config.routerBasePath}/book_placeholder.jpg` return store.getters['globals/getPlaceholderCoverSrc']
}, },
fullCoverUrl() { fullCoverUrl() {
if (!this.libraryItem) return null if (!this.libraryItem) return null

View File

@ -18,7 +18,7 @@
</div> </div>
</div> </div>
<p v-if="!imageFailed && showResolution" class="absolute -bottom-5 left-0 right-0 mx-auto text-xs text-gray-300 text-center">{{ resolution }}</p> <p v-if="!imageFailed && showResolution && resolution" class="absolute -bottom-5 left-0 right-0 mx-auto text-xs text-gray-300 text-center">{{ resolution }}</p>
</div> </div>
</template> </template>
@ -65,11 +65,12 @@ export default {
return 0.8 * this.sizeMultiplier return 0.8 * this.sizeMultiplier
}, },
resolution() { resolution() {
if (!this.naturalWidth || !this.naturalHeight) return null
return `${this.naturalWidth}×${this.naturalHeight}px` return `${this.naturalWidth}×${this.naturalHeight}px`
}, },
placeholderUrl() { placeholderUrl() {
const config = this.$config || this.$nuxt.$config const store = this.$store || this.$nuxt.$store
return `${config.routerBasePath}/book_placeholder.jpg` return store.getters['globals/getPlaceholderCoverSrc']
} }
}, },
methods: { methods: {

View File

@ -2,7 +2,7 @@
<div class="w-full h-full overflow-hidden overflow-y-auto px-2 sm:px-4 py-6 relative"> <div class="w-full h-full overflow-hidden overflow-y-auto px-2 sm:px-4 py-6 relative">
<div class="flex flex-col sm:flex-row mb-4"> <div class="flex flex-col sm:flex-row mb-4">
<div class="relative self-center md:self-start"> <div class="relative self-center md:self-start">
<covers-preview-cover :src="$store.getters['globals/getLibraryItemCoverSrcById'](libraryItemId, libraryItemUpdatedAt, true)" :width="120" :book-cover-aspect-ratio="bookCoverAspectRatio" /> <covers-preview-cover :src="coverUrl" :width="120" :book-cover-aspect-ratio="bookCoverAspectRatio" />
<!-- book cover overlay --> <!-- book cover overlay -->
<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"> <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">
@ -157,6 +157,12 @@ export default {
coverPath() { coverPath() {
return this.media.coverPath return this.media.coverPath
}, },
coverUrl() {
if (!this.coverPath) {
return this.$store.getters['globals/getPlaceholderCoverSrc']
}
return this.$store.getters['globals/getLibraryItemCoverSrcById'](this.libraryItemId, this.libraryItemUpdatedAt, true)
},
mediaMetadata() { mediaMetadata() {
return this.media.metadata || {} return this.media.metadata || {}
}, },

View File

@ -55,7 +55,7 @@ export default {
return this.item.coverPath return this.item.coverPath
}, },
coverUrl() { coverUrl() {
if (!this.coverPath) return `${this.$config.routerBasePath}/book_placeholder.jpg` if (!this.coverPath) return this.$store.getters['globals/getPlaceholderCoverSrc']
return this.$store.getters['globals/getLibraryItemCoverSrcById'](this.libraryItemId) return this.$store.getters['globals/getLibraryItemCoverSrcById'](this.libraryItemId)
}, },
bookCoverAspectRatio() { bookCoverAspectRatio() {

View File

@ -64,7 +64,7 @@ export default {
return this.mediaItemShare.playbackSession return this.mediaItemShare.playbackSession
}, },
coverUrl() { coverUrl() {
if (!this.playbackSession.coverPath) return `${this.$config.routerBasePath}/book_placeholder.jpg` if (!this.playbackSession.coverPath) return this.$store.getters['globals/getPlaceholderCoverSrc']
return `${this.$config.routerBasePath}/public/share/${this.mediaItemShare.slug}/cover` return `${this.$config.routerBasePath}/public/share/${this.mediaItemShare.slug}/cover`
}, },
downloadUrl() { downloadUrl() {

View File

@ -87,7 +87,7 @@ export const getters = {
getLibraryItemCoverSrc: getLibraryItemCoverSrc:
(state, getters, rootState, rootGetters) => (state, getters, rootState, rootGetters) =>
(libraryItem, placeholder = null, raw = false) => { (libraryItem, placeholder = null, raw = false) => {
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg` if (!placeholder) placeholder = getters.getPlaceholderCoverSrc
if (!libraryItem) return placeholder if (!libraryItem) return placeholder
const media = libraryItem.media const media = libraryItem.media
if (!media?.coverPath || media.coverPath === placeholder) return placeholder if (!media?.coverPath || media.coverPath === placeholder) return placeholder
@ -95,7 +95,6 @@ export const getters = {
// Absolute URL covers (should no longer be used) // Absolute URL covers (should no longer be used)
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
const userToken = rootGetters['user/getToken']
const lastUpdate = libraryItem.updatedAt || Date.now() const lastUpdate = libraryItem.updatedAt || Date.now()
const libraryItemId = libraryItem.libraryItemId || libraryItem.id // Workaround for /users/:id page showing media progress covers const libraryItemId = libraryItem.libraryItemId || libraryItem.id // Workaround for /users/:id page showing media progress covers
return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?ts=${lastUpdate}${raw ? '&raw=1' : ''}` return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?ts=${lastUpdate}${raw ? '&raw=1' : ''}`
@ -103,11 +102,13 @@ export const getters = {
getLibraryItemCoverSrcById: getLibraryItemCoverSrcById:
(state, getters, rootState, rootGetters) => (state, getters, rootState, rootGetters) =>
(libraryItemId, timestamp = null, raw = false) => { (libraryItemId, timestamp = null, raw = false) => {
const placeholder = `${rootState.routerBasePath}/book_placeholder.jpg` if (!libraryItemId) return getters.getPlaceholderCoverSrc
if (!libraryItemId) return placeholder
const userToken = rootGetters['user/getToken']
return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?${raw ? '&raw=1' : ''}${timestamp ? `&ts=${timestamp}` : ''}` return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?${raw ? '&raw=1' : ''}${timestamp ? `&ts=${timestamp}` : ''}`
}, },
getPlaceholderCoverSrc: (state, getters, rootState, rootGetters) => {
return `${rootState.routerBasePath}/book_placeholder.jpg`
},
getIsBatchSelectingMediaItems: (state) => { getIsBatchSelectingMediaItems: (state) => {
return state.selectedMediaItems.length return state.selectedMediaItems.length
} }