diff --git a/server/managers/CoverManager.js b/server/managers/CoverManager.js index 9b4aa32d..2b3a697d 100644 --- a/server/managers/CoverManager.js +++ b/server/managers/CoverManager.js @@ -12,7 +12,7 @@ const parseEbookMetadata = require('../utils/parsers/parseEbookMetadata') const CacheManager = require('../managers/CacheManager') class CoverManager { - constructor() { } + constructor() {} getCoverDirectory(libraryItem) { if (global.ServerSettings.storeCoverWithItem && !libraryItem.isFile) { @@ -93,10 +93,13 @@ class CoverManager { const coverFullPath = Path.posix.join(coverDirPath, `cover${extname}`) // Move cover from temp upload dir to destination - const success = await coverFile.mv(coverFullPath).then(() => true).catch((error) => { - Logger.error('[CoverManager] Failed to move cover file', path, error) - return false - }) + const success = await coverFile + .mv(coverFullPath) + .then(() => true) + .catch((error) => { + Logger.error('[CoverManager] Failed to move cover file', coverFullPath, error) + return false + }) if (!success) { return { @@ -124,11 +127,13 @@ class CoverManager { var temppath = Path.posix.join(coverDirPath, 'cover') let errorMsg = '' - let success = await downloadImageFile(url, temppath).then(() => true).catch((err) => { - errorMsg = err.message || 'Unknown error' - Logger.error(`[CoverManager] Download image file failed for "${url}"`, errorMsg) - return false - }) + let success = await downloadImageFile(url, temppath) + .then(() => true) + .catch((err) => { + errorMsg = err.message || 'Unknown error' + Logger.error(`[CoverManager] Download image file failed for "${url}"`, errorMsg) + return false + }) if (!success) { return { error: 'Failed to download image from url: ' + errorMsg @@ -180,7 +185,7 @@ class CoverManager { } // Cover path does not exist - if (!await fs.pathExists(coverPath)) { + if (!(await fs.pathExists(coverPath))) { Logger.error(`[CoverManager] validate cover path does not exist "${coverPath}"`) return { error: 'Cover path does not exist' @@ -188,7 +193,7 @@ class CoverManager { } // Cover path is not a file - if (!await checkPathIsFile(coverPath)) { + if (!(await checkPathIsFile(coverPath))) { Logger.error(`[CoverManager] validate cover path is not a file "${coverPath}"`) return { error: 'Cover path is not a file' @@ -211,10 +216,13 @@ class CoverManager { var newCoverPath = Path.posix.join(coverDirPath, coverFilename) Logger.debug(`[CoverManager] validate cover path copy cover from "${coverPath}" to "${newCoverPath}"`) - var copySuccess = await fs.copy(coverPath, newCoverPath, { overwrite: true }).then(() => true).catch((error) => { - Logger.error(`[CoverManager] validate cover path failed to copy cover`, error) - return false - }) + var copySuccess = await fs + .copy(coverPath, newCoverPath, { overwrite: true }) + .then(() => true) + .catch((error) => { + Logger.error(`[CoverManager] validate cover path failed to copy cover`, error) + return false + }) if (!copySuccess) { return { error: 'Failed to copy cover to dir' @@ -236,14 +244,14 @@ class CoverManager { /** * Extract cover art from audio file and save for library item - * - * @param {import('../models/Book').AudioFileObject[]} audioFiles - * @param {string} libraryItemId - * @param {string} [libraryItemPath] null for isFile library items + * + * @param {import('../models/Book').AudioFileObject[]} audioFiles + * @param {string} libraryItemId + * @param {string} [libraryItemPath] null for isFile library items * @returns {Promise} returns cover path */ async saveEmbeddedCoverArt(audioFiles, libraryItemId, libraryItemPath) { - let audioFileWithCover = audioFiles.find(af => af.embeddedCoverArt) + let audioFileWithCover = audioFiles.find((af) => af.embeddedCoverArt) if (!audioFileWithCover) return null let coverDirPath = null @@ -273,10 +281,10 @@ class CoverManager { /** * Extract cover art from ebook and save for library item - * - * @param {import('../utils/parsers/parseEbookMetadata').EBookFileScanData} ebookFileScanData - * @param {string} libraryItemId - * @param {string} [libraryItemPath] null for isFile library items + * + * @param {import('../utils/parsers/parseEbookMetadata').EBookFileScanData} ebookFileScanData + * @param {string} libraryItemId + * @param {string} [libraryItemPath] null for isFile library items * @returns {Promise} returns cover path */ async saveEbookCoverArt(ebookFileScanData, libraryItemId, libraryItemPath) { @@ -310,9 +318,9 @@ class CoverManager { } /** - * - * @param {string} url - * @param {string} libraryItemId + * + * @param {string} url + * @param {string} libraryItemId * @param {string} [libraryItemPath] null if library item isFile or is from adding new podcast * @returns {Promise<{error:string}|{cover:string}>} */ @@ -328,10 +336,12 @@ class CoverManager { await fs.ensureDir(coverDirPath) const temppath = Path.posix.join(coverDirPath, 'cover') - const success = await downloadImageFile(url, temppath).then(() => true).catch((err) => { - Logger.error(`[CoverManager] Download image file failed for "${url}"`, err) - return false - }) + const success = await downloadImageFile(url, temppath) + .then(() => true) + .catch((err) => { + Logger.error(`[CoverManager] Download image file failed for "${url}"`, err) + return false + }) if (!success) { return { error: 'Failed to download image from url' @@ -361,4 +371,4 @@ class CoverManager { } } } -module.exports = new CoverManager() \ No newline at end of file +module.exports = new CoverManager()