mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Fix:Set full cover path for extracted covers & use temp fix to update books without a full cover path
This commit is contained in:
		
							parent
							
								
									d6ae50f89a
								
							
						
					
					
						commit
						57b464c867
					
				| @ -36,7 +36,7 @@ class CacheManager { | |||||||
|     // Write cache
 |     // Write cache
 | ||||||
|     await fs.ensureDir(this.CoverCachePath) |     await fs.ensureDir(this.CoverCachePath) | ||||||
| 
 | 
 | ||||||
|     let writtenFile = await resizeImage(audiobook.book.coverFullPath || audiobook.book.cover, path, width, height) |     let writtenFile = await resizeImage(audiobook.book.coverFullPath, path, width, height) | ||||||
|     var readStream = fs.createReadStream(writtenFile) |     var readStream = fs.createReadStream(writtenFile) | ||||||
|     readStream.pipe(res) |     readStream.pipe(res) | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -234,13 +234,23 @@ class BookController { | |||||||
|   async getCover(req, res) { |   async getCover(req, res) { | ||||||
|     let { query: { width, height, format }, params: { id } } = req |     let { query: { width, height, format }, params: { id } } = req | ||||||
|     var audiobook = this.db.audiobooks.find(a => a.id === id) |     var audiobook = this.db.audiobooks.find(a => a.id === id) | ||||||
|     if (!audiobook || (!audiobook.book.coverFullPath && !audiobook.book.cover)) return res.sendStatus(404) |     if (!audiobook || !audiobook.book.cover) return res.sendStatus(404) | ||||||
| 
 | 
 | ||||||
|     // Check user can access this audiobooks library
 |     // Check user can access this audiobooks library
 | ||||||
|     if (!req.user.checkCanAccessLibrary(audiobook.libraryId)) { |     if (!req.user.checkCanAccessLibrary(audiobook.libraryId)) { | ||||||
|       return res.sendStatus(403) |       return res.sendStatus(403) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     // Temp fix for books without a full cover path
 | ||||||
|  |     if (audiobook.book.cover && !audiobook.book.coverFullPath) { | ||||||
|  |       var isFixed = audiobook.fixFullCoverPath() | ||||||
|  |       if (!isFixed) { | ||||||
|  |         Logger.warn(`[BookController] Failed to fix full cover path "${audiobook.book.cover}" for "${audiobook.book.title}"`) | ||||||
|  |         return res.sendStatus(404) | ||||||
|  |       } | ||||||
|  |       await this.db.updateEntity('audiobook', audiobook) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const options = { |     const options = { | ||||||
|       format: format || (reqSupportsWebp(req) ? 'webp' : 'jpeg'), |       format: format || (reqSupportsWebp(req) ? 'webp' : 'jpeg'), | ||||||
|       height: height ? parseInt(height) : null, |       height: height ? parseInt(height) : null, | ||||||
|  | |||||||
| @ -801,7 +801,7 @@ class Audiobook { | |||||||
|     var success = await extractCoverArt(audioFileWithCover.fullPath, coverFilePath) |     var success = await extractCoverArt(audioFileWithCover.fullPath, coverFilePath) | ||||||
|     if (success) { |     if (success) { | ||||||
|       var coverRelPath = Path.join(coverDirRelPath, coverFilename).replace(/\\/g, '/').replace(/\/\//g, '/') |       var coverRelPath = Path.join(coverDirRelPath, coverFilename).replace(/\\/g, '/').replace(/\/\//g, '/') | ||||||
|       this.update({ book: { cover: coverRelPath } }) |       this.update({ book: { cover: coverRelPath, coverFullPath: audioFileWithCover.fullPath } }) | ||||||
|       return coverRelPath |       return coverRelPath | ||||||
|     } |     } | ||||||
|     return false |     return false | ||||||
| @ -1022,5 +1022,23 @@ class Audiobook { | |||||||
|       existingOtherFileData |       existingOtherFileData | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   // Temp fix for cover is set but coverFullPath is not set
 | ||||||
|  |   fixFullCoverPath(metadataPath) { | ||||||
|  |     if (!this.book.cover) return | ||||||
|  |     var bookCoverPath = this.book.cover.replace(/\\/g, '/') | ||||||
|  |     var newFullCoverPath = null | ||||||
|  |     if (bookCoverPath.startsWith('/s/book/')) { | ||||||
|  |       newFullCoverPath = Path.join(this.fullPath, bookCoverPath.substr(`/s/book/${this.id}`.length)).replace(/\/\//g, '/') | ||||||
|  |     } else if (bookCoverPath.startsWith('/metadata/')) { | ||||||
|  |       newFullCoverPath = Path.join(metadataPath, bookCoverPath.substr('/metadata/'.length)).replace(/\/\//g, '/') | ||||||
|  |     } | ||||||
|  |     if (newFullCoverPath) { | ||||||
|  |       Logger.debug(`[Audiobook] "${this.title}" fixing full cover path "${this.book.cover}" => "${newFullCoverPath}"`) | ||||||
|  |       this.update({ book: { fullCoverPath: newFullCoverPath } }) | ||||||
|  |       return true | ||||||
|  |     } | ||||||
|  |     return false | ||||||
|  |   } | ||||||
| } | } | ||||||
| module.exports = Audiobook | module.exports = Audiobook | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user