Skip to content

Commit

Permalink
Fix:Server crash when updating cover to a directory #2007
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Aug 30, 2023
1 parent 4585d28 commit 75276f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
5 changes: 2 additions & 3 deletions client/components/modals/item/tabs/Cover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
14 changes: 12 additions & 2 deletions server/managers/CoverManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -180,15 +180,25 @@ class CoverManager {
updated: false
}
}

// Cover path does not exist
if (!await fs.pathExists(coverPath)) {
Logger.error(`[CoverManager] validate cover path does not exist "${coverPath}"`)
return {
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
}
Expand Down
14 changes: 14 additions & 0 deletions server/utils/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 75276f5

Please sign in to comment.