Skip to content

Commit

Permalink
fix: raw URLs from CORs restricted origin
Browse files Browse the repository at this point in the history
* fix: raw URLs from CORs restricted origin

* test: left-over DEFAULT_VIDEO_SOURCE_TYPES
  • Loading branch information
tsi authored Feb 1, 2024
1 parent 4b31b6a commit 3b1baed
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/raw-url.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

player = cloudinary.videoPlayer('player', config);

player.source('https://res.cloudinary.com/demo/video/upload/sea_turtle.mp4');
player.source('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_10mb.mp4');

adpPlayer = cloudinary.videoPlayer('adpPlayer',config);

Expand Down
26 changes: 22 additions & 4 deletions src/plugins/cloudinary/models/video-source/video-source.const.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
export const DEFAULT_POSTER_PARAMS = { format: 'jpg', resource_type: 'video' };

const DEFAULT_VIDEO_SOURCE_TYPES = ['webm/vp9', 'mp4/h265', 'mp4'];

export const DEFAULT_VIDEO_PARAMS = {
resource_type: 'video',
type: 'upload',
transformation: [],
sourceTransformation: {},
sourceTypes: DEFAULT_VIDEO_SOURCE_TYPES,
sourceTypes: ['auto'],
recommendations: null,
info: {},
interactionAreas: {},
chapters: {}
};

export const VIDEO_SUFFIX_REMOVAL_PATTERN = RegExp(`\\.(${DEFAULT_VIDEO_SOURCE_TYPES.join('|')})$$`);
const COMMON_VIDEO_EXTENSIONS = [
'3g2',
'3gp',
'avi',
'flv',
'm3u8',
'ts',
'm2ts',
'mts',
'mov',
'mkv',
'mp4',
'mpeg',
'mpd',
'mxf',
'ogv',
'webm',
'wmv'
]; // https://cloudinary.com/documentation/video_manipulation_and_delivery#supported_video_formats

export const VIDEO_SUFFIX_REMOVAL_PATTERN = RegExp(`\\.(${COMMON_VIDEO_EXTENSIONS.join('|')})$$`);

// eslint-disable-next-line no-control-regex
export const URL_PATTERN = RegExp('https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\+.~#?&/=]*)');
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cloudinary/models/video-source/video-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class VideoSource extends BaseSource {

generateSources() {
if (this.isRawUrl) {
const type = this.sourceTypes().length > 1 ? null : this.sourceTypes()[0];
const type = this.sourceTypes()[0] === 'auto' ? null : this.sourceTypes()[0];
return [this.generateRawSource(this.publicId(), type)];
}

Expand Down
3 changes: 2 additions & 1 deletion src/video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ class VideoPlayer extends Utils.mixin(Eventable) {

const transformation = Utils.assign({}, source.transformation());

if (transformation && transformation.streaming_profile) {
if (transformation) {
delete transformation.streaming_profile;
delete transformation.video_codec;
}

transformation.flags = transformation.flags || [];
Expand Down
34 changes: 22 additions & 12 deletions test/unit/videoSource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,14 @@ describe('test isCodecAlreadyExist method', () => {
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_vp9/sea_turtle.webm');
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/f_auto:video/sea_turtle');
});

it('check if codec has NOT bee added to the ur twice', () => {
it('with codec and sourceType', () => {

const source = new VideoSource('sea_turtle', {
cloudinaryConfig: cld,
sourceTypes: ['webm'],
transformation: {
video_codec: 'vp9'
}
Expand All @@ -377,6 +378,19 @@ describe('test isCodecAlreadyExist method', () => {
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_vp9/sea_turtle.webm');
});

it('codec with no sourceType', () => {

const source = new VideoSource('sea_turtle', {
cloudinaryConfig: cld,
transformation: {
video_codec: 'vp9'
}
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_vp9/f_auto:video/sea_turtle');
});

it('check if codec has been changed', () => {

const source = new VideoSource('sea_turtle', {
Expand All @@ -387,19 +401,19 @@ describe('test isCodecAlreadyExist method', () => {
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_h265/sea_turtle.webm');
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_h265/f_auto:video/sea_turtle');
});


it('check if codec has been NOT add twice using raw_transformation', () => {
it('raw_transformation codec with no sourceType', () => {

const source = new VideoSource('sea_turtle', {
cloudinaryConfig: cld,
raw_transformation: 'vc_vp9'
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_vp9/sea_turtle.webm');
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/f_auto:video/vc_vp9/sea_turtle');
});

it('check if codec has been change using raw_transformation', () => {
Expand All @@ -410,7 +424,7 @@ describe('test isCodecAlreadyExist method', () => {
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/h265/sea_turtle.webm');
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/f_auto:video/h265/sea_turtle');
});


Expand All @@ -424,7 +438,7 @@ describe('test isCodecAlreadyExist method', () => {
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/w_400/vc_vp9/sea_turtle.webm');
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/w_400/f_auto:video/sea_turtle');
});

it('check array of transformations with codec', () => {
Expand All @@ -437,12 +451,8 @@ describe('test isCodecAlreadyExist method', () => {
});

const srcs = source.generateSources();
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_h265/sea_turtle.webm');
expect(srcs[0].src).toEqual('http://res.cloudinary.com/demo/video/upload/vc_h265/f_auto:video/sea_turtle');
});


});

});


0 comments on commit 3b1baed

Please sign in to comment.