Fix:Server crash when updating cover to a directory #2007

This commit is contained in:
advplyr 2023-08-30 18:05:52 -05:00
parent 4585d2816b
commit 75276f5a44
3 changed files with 28 additions and 5 deletions

View File

@ -283,9 +283,8 @@ export default {
}
if (success) {
this.$toast.success('Update Successful')
// this.$emit('close')
} else {
this.imageUrl = this.media.coverPath || ''
} else if (this.media.coverPath) {
this.imageUrl = this.media.coverPath
}
this.isProcessing = false
},

View File

@ -6,7 +6,7 @@ const imageType = require('../libs/imageType')
const filePerms = require('../utils/filePerms')
const globals = require('../utils/globals')
const { downloadFile, filePathToPOSIX } = require('../utils/fileUtils')
const { downloadFile, filePathToPOSIX, checkPathIsFile } = require('../utils/fileUtils')
const { extractCoverArt } = require('../utils/ffmpegHelpers')
class CoverManager {
@ -180,6 +180,7 @@ class CoverManager {
updated: false
}
}
// Cover path does not exist
if (!await fs.pathExists(coverPath)) {
Logger.error(`[CoverManager] validate cover path does not exist "${coverPath}"`)
@ -187,8 +188,17 @@ class CoverManager {
error: 'Cover path does not exist'
}
}
// Cover path is not a file
if (!await checkPathIsFile(coverPath)) {
Logger.error(`[CoverManager] validate cover path is not a file "${coverPath}"`)
return {
error: 'Cover path is not a file'
}
}
// Check valid image at path
var imgtype = await this.checkFileIsValidImage(coverPath, true)
var imgtype = await this.checkFileIsValidImage(coverPath, false)
if (imgtype.error) {
return imgtype
}

View File

@ -59,6 +59,20 @@ async function getFileSize(path) {
}
module.exports.getFileSize = getFileSize
/**
*
* @param {string} filepath
* @returns {boolean}
*/
async function checkPathIsFile(filepath) {
try {
const stat = await fs.stat(filepath)
return stat.isFile()
} catch (err) {
return false
}
}
module.exports.checkPathIsFile = checkPathIsFile
function getIno(path) {
return fs.stat(path, { bigint: true }).then((data => String(data.ino))).catch((err) => {