Skip to content

Commit

Permalink
Refactored oembed controller data validation
Browse files Browse the repository at this point in the history
refs #10060

- Uses validation layer for checking url data on oembed requests
- Fixes typo in comment
  • Loading branch information
rishabhgrg committed Aug 1, 2019
1 parent 27bf453 commit 5f9f5ea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/server/api/shared/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions core/server/api/v2/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 4 additions & 0 deletions core/server/api/v2/utils/validators/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ module.exports = {

get images() {
return require('./images');
},

get oembed() {
return require('./oembed');
}
};
12 changes: 12 additions & 0 deletions core/server/api/v2/utils/validators/input/oembed.js
Original file line number Diff line number Diff line change
@@ -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')
}));
}
}
};

0 comments on commit 5f9f5ea

Please sign in to comment.