Merge pull request #1539 from Linden-Ryuujin/feature/coverImage

Prefer cover images called cover
This commit is contained in:
advplyr 2023-02-23 17:55:05 -06:00 committed by GitHub
commit 2db4dd6a40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,9 +197,15 @@ class LibraryItem {
if (key === 'libraryFiles') { if (key === 'libraryFiles') {
this.libraryFiles = payload.libraryFiles.map(lf => lf.clone()) this.libraryFiles = payload.libraryFiles.map(lf => lf.clone())
// Use first image library file as cover // Set cover image
const firstImageFile = this.libraryFiles.find(lf => lf.fileType === 'image') const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image')
if (firstImageFile) this.media.coverPath = firstImageFile.metadata.path const coverMatch = imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path))
if (coverMatch) {
this.media.coverPath = coverMatch.metadata.path
} else if (imageFiles.length) {
this.media.coverPath = imageFiles[0].metadata.path
}
} else if (this[key] !== undefined && key !== 'media') { } else if (this[key] !== undefined && key !== 'media') {
this[key] = payload[key] this[key] = payload[key]
} }
@ -444,8 +450,14 @@ class LibraryItem {
// Set cover image if not set // Set cover image if not set
const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image') const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image')
if (imageFiles.length && !this.media.coverPath) { if (imageFiles.length && !this.media.coverPath) {
// attempt to find a file called cover.<ext> otherwise just fall back to the first image found
const coverMatch = imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path))
if (coverMatch) {
this.media.coverPath = coverMatch.metadata.path
} else {
this.media.coverPath = imageFiles[0].metadata.path this.media.coverPath = imageFiles[0].metadata.path
Logger.debug('[LibraryItem] Set media cover path', this.media.coverPath) }
Logger.info('[LibraryItem] Set media cover path', this.media.coverPath)
hasUpdated = true hasUpdated = true
} }