diff --git a/client/components/modals/item/tabs/Cover.vue b/client/components/modals/item/tabs/Cover.vue index 184d2036..09329482 100644 --- a/client/components/modals/item/tabs/Cover.vue +++ b/client/components/modals/item/tabs/Cover.vue @@ -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 }, diff --git a/server/managers/CoverManager.js b/server/managers/CoverManager.js index eba4f44f..1f36d545 100644 --- a/server/managers/CoverManager.js +++ b/server/managers/CoverManager.js @@ -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 } diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index c74909c0..87bacac0 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -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) => {