1+ import pick from 'lodash/pick' ;
12import { defaultProfiles } from 'cloudinary-video-player-profiles' ;
23import { isRawUrl , getCloudinaryUrlPrefix } from '../plugins/cloudinary/url-helpers' ;
4+ import { CLOUDINARY_CONFIG_PARAM } from '../video-player.const' ;
35import { utf8ToBase64 } from '../utils/utf8Base64' ;
46import { appendQueryParams } from './querystring' ;
7+ import { convertKeysToSnakeCase } from './object' ;
58
69const isDefaultProfile = ( profileName ) => ! ! defaultProfiles . find ( ( { name } ) => profileName === name ) ;
710
@@ -15,13 +18,23 @@ const getDefaultProfileConfig = (profileName) => {
1518 return profile . config ;
1619} ;
1720
21+ const getCloudinaryConfigFromOptions = ( options ) => {
22+ if ( options . cloudinaryConfig ) {
23+ return options . cloudinaryConfig ;
24+ }
25+
26+ const fromFlat = pick ( convertKeysToSnakeCase ( options ) , CLOUDINARY_CONFIG_PARAM ) ;
27+ return Object . assign ( { } , fromFlat , options . cloudinary || { } ) ;
28+ } ;
29+
1830const fetchConfig = async ( options ) => {
19- const { profile, publicId, cloudinaryConfig , type = 'upload' , videoConfig, allowUsageReport = true } = options ;
31+ const { profile, publicId, type = 'upload' , videoConfig, allowUsageReport = true } = options ;
2032
2133 if ( profile && isDefaultProfile ( profile ) ) {
2234 return getDefaultProfileConfig ( profile ) ;
2335 }
2436
37+ const cloudinaryConfig = getCloudinaryConfigFromOptions ( options ) ;
2538 const urlPrefix = getCloudinaryUrlPrefix ( cloudinaryConfig ) + '/_applet_/video_service' ;
2639 const queryParams = allowUsageReport ? { _s : `vp-${ VERSION } ` } : null ;
2740
0 commit comments