From 5f9f5ea0d5663263fdd7c4a0fb3ab7f6601179ec Mon Sep 17 00:00:00 2001 From: Rish Date: Thu, 1 Aug 2019 16:30:13 +0530 Subject: [PATCH] Refactored oembed controller data validation refs #10060 - Uses validation layer for checking url data on oembed requests - Fixes typo in comment --- core/server/api/shared/pipeline.js | 4 ++-- core/server/api/v2/oembed.js | 6 ------ core/server/api/v2/utils/validators/input/index.js | 4 ++++ core/server/api/v2/utils/validators/input/oembed.js | 12 ++++++++++++ 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 core/server/api/v2/utils/validators/input/oembed.js diff --git a/core/server/api/shared/pipeline.js b/core/server/api/shared/pipeline.js index 1ea6490661f4..a37af2a5eb10 100644 --- a/core/server/api/shared/pipeline.js +++ b/core/server/api/shared/pipeline.js @@ -12,8 +12,8 @@ const STAGES = { * * We call the shared validator which runs the request through: * - * 1. Shared serializers - * 2. Custom API serializers + * 1. Shared validator + * 2. Custom API validators * * @param {Object} apiUtils - Local utils of target API version. * @param {Object} apiConfig - Docname & Method of ctrl. diff --git a/core/server/api/v2/oembed.js b/core/server/api/v2/oembed.js index e7dff7cfa5c0..4efd21df4c1f 100644 --- a/core/server/api/v2/oembed.js +++ b/core/server/api/v2/oembed.js @@ -44,12 +44,6 @@ module.exports = { query({data}) { let {url} = data; - if (!url || !url.trim()) { - return Promise.reject(new common.errors.BadRequestError({ - message: common.i18n.t('errors.api.oembed.noUrlProvided') - })); - } - function unknownProvider() { return Promise.reject(new common.errors.ValidationError({ message: common.i18n.t('errors.api.oembed.unknownProvider'), diff --git a/core/server/api/v2/utils/validators/input/index.js b/core/server/api/v2/utils/validators/input/index.js index ade462c797bd..e028d441d078 100644 --- a/core/server/api/v2/utils/validators/input/index.js +++ b/core/server/api/v2/utils/validators/input/index.js @@ -37,5 +37,9 @@ module.exports = { get images() { return require('./images'); + }, + + get oembed() { + return require('./oembed'); } }; diff --git a/core/server/api/v2/utils/validators/input/oembed.js b/core/server/api/v2/utils/validators/input/oembed.js new file mode 100644 index 000000000000..9ebbf25a766b --- /dev/null +++ b/core/server/api/v2/utils/validators/input/oembed.js @@ -0,0 +1,12 @@ +const Promise = require('bluebird'); +const common = require('../../../../../lib/common'); + +module.exports = { + read(apiConfig, frame) { + if (!frame.data.url || !frame.data.url.trim()) { + return Promise.reject(new common.errors.BadRequestError({ + message: common.i18n.t('errors.api.oembed.noUrlProvided') + })); + } + } +};