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}`)
// 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)
const success = await coverFile
.mv(coverFullPath)
.then(() => true)
.catch((error) => {
Logger.error('[CoverManager] Failed to move cover file', coverFullPath, error)
return false
})
@ -124,7 +127,9 @@ class CoverManager {
var temppath = Path.posix.join(coverDirPath, 'cover')
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'
Logger.error(`[CoverManager] Download image file failed for "${url}"`, errorMsg)
return false
@ -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,7 +216,10 @@ 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) => {
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
})
@ -243,7 +251,7 @@ class CoverManager {
* @returns {Promise<string>} 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
@ -328,7 +336,9 @@ class CoverManager {
await fs.ensureDir(coverDirPath)
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)
return false
})