Fix:Server crash on uploadCover temp file mv failed #3685

This commit is contained in:
advplyr 2024-12-06 16:59:34 -06:00
parent 890b0b949e
commit 9a1c773b7a

View File

@ -93,8 +93,11 @@ class CoverManager {
const coverFullPath = Path.posix.join(coverDirPath, `cover${extname}`) const coverFullPath = Path.posix.join(coverDirPath, `cover${extname}`)
// Move cover from temp upload dir to destination // Move cover from temp upload dir to destination
const success = await coverFile.mv(coverFullPath).then(() => true).catch((error) => { const success = await coverFile
Logger.error('[CoverManager] Failed to move cover file', path, error) .mv(coverFullPath)
.then(() => true)
.catch((error) => {
Logger.error('[CoverManager] Failed to move cover file', coverFullPath, error)
return false return false
}) })
@ -124,7 +127,9 @@ class CoverManager {
var temppath = Path.posix.join(coverDirPath, 'cover') var temppath = Path.posix.join(coverDirPath, 'cover')
let errorMsg = '' let errorMsg = ''
let success = await downloadImageFile(url, temppath).then(() => true).catch((err) => { let success = await downloadImageFile(url, temppath)
.then(() => true)
.catch((err) => {
errorMsg = err.message || 'Unknown error' errorMsg = err.message || 'Unknown error'
Logger.error(`[CoverManager] Download image file failed for "${url}"`, errorMsg) Logger.error(`[CoverManager] Download image file failed for "${url}"`, errorMsg)
return false return false
@ -180,7 +185,7 @@ class CoverManager {
} }
// Cover path does not exist // 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}"`) Logger.error(`[CoverManager] validate cover path does not exist "${coverPath}"`)
return { return {
error: 'Cover path does not exist' error: 'Cover path does not exist'
@ -188,7 +193,7 @@ class CoverManager {
} }
// Cover path is not a file // 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}"`) Logger.error(`[CoverManager] validate cover path is not a file "${coverPath}"`)
return { return {
error: 'Cover path is not a file' error: 'Cover path is not a file'
@ -211,7 +216,10 @@ class CoverManager {
var newCoverPath = Path.posix.join(coverDirPath, coverFilename) var newCoverPath = Path.posix.join(coverDirPath, coverFilename)
Logger.debug(`[CoverManager] validate cover path copy cover from "${coverPath}" to "${newCoverPath}"`) 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) => { var copySuccess = await fs
.copy(coverPath, newCoverPath, { overwrite: true })
.then(() => true)
.catch((error) => {
Logger.error(`[CoverManager] validate cover path failed to copy cover`, error) Logger.error(`[CoverManager] validate cover path failed to copy cover`, error)
return false return false
}) })
@ -243,7 +251,7 @@ class CoverManager {
* @returns {Promise<string>} returns cover path * @returns {Promise<string>} returns cover path
*/ */
async saveEmbeddedCoverArt(audioFiles, libraryItemId, libraryItemPath) { async saveEmbeddedCoverArt(audioFiles, libraryItemId, libraryItemPath) {
let audioFileWithCover = audioFiles.find(af => af.embeddedCoverArt) let audioFileWithCover = audioFiles.find((af) => af.embeddedCoverArt)
if (!audioFileWithCover) return null if (!audioFileWithCover) return null
let coverDirPath = null let coverDirPath = null
@ -328,7 +336,9 @@ class CoverManager {
await fs.ensureDir(coverDirPath) await fs.ensureDir(coverDirPath)
const temppath = Path.posix.join(coverDirPath, 'cover') const temppath = Path.posix.join(coverDirPath, 'cover')
const success = await downloadImageFile(url, temppath).then(() => true).catch((err) => { const success = await downloadImageFile(url, temppath)
.then(() => true)
.catch((err) => {
Logger.error(`[CoverManager] Download image file failed for "${url}"`, err) Logger.error(`[CoverManager] Download image file failed for "${url}"`, err)
return false return false
}) })