From d20732ce3452b7be6c5ad9912daa64815fbe7bc9 Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 26 Oct 2021 15:57:16 +0400 Subject: [PATCH] Imroved media validation middleware refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter - Error messages are now more specific when uploaded media files fail the validation check --- core/server/web/api/middleware/upload.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/server/web/api/middleware/upload.js b/core/server/web/api/middleware/upload.js index 806c103b56..56df330ae4 100644 --- a/core/server/web/api/middleware/upload.js +++ b/core/server/web/api/middleware/upload.js @@ -31,6 +31,10 @@ const messages = { icons: { missingFile: 'Please select an icon.', invalidFile: 'Icon must be a square .ico or .png file between 60px – 1,000px, under 100kb.' + }, + media: { + missingFile: 'Please select a media file.', + invalidFile: 'Please select a valid media file.' } }; @@ -83,9 +87,13 @@ const checkFileIsValid = (fileData, types, extensions) => { return false; }; -const validation = function (options) { - const type = options.type; - +/** + * + * @param {Object} options + * @param {String} options.type - type of the file + * @returns {Function} + */ +const validation = function ({type}) { // if we finish the data/importer logic, we forward the request to the specified importer return function uploadValidation(req, res, next) { const extensions = (config.get('uploads')[type] && config.get('uploads')[type].extensions) || [];