Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/utils/fetch-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pick from 'lodash/pick';
import { defaultProfiles } from 'cloudinary-video-player-profiles';
import { isRawUrl, getCloudinaryUrlPrefix } from '../plugins/cloudinary/url-helpers';
import { CLOUDINARY_CONFIG_PARAM } from '../video-player.const';
import { utf8ToBase64 } from '../utils/utf8Base64';
import { appendQueryParams } from './querystring';
import { convertKeysToSnakeCase } from './object';

const isDefaultProfile = (profileName) => !!defaultProfiles.find(({ name }) => profileName === name);

Expand All @@ -15,13 +18,23 @@ const getDefaultProfileConfig = (profileName) => {
return profile.config;
};

const getCloudinaryConfigFromOptions = (options) => {
if (options.cloudinaryConfig) {
return options.cloudinaryConfig;
}

const snakeCaseCloudinaryConfig = pick(convertKeysToSnakeCase(options), CLOUDINARY_CONFIG_PARAM);
return Object.assign({}, snakeCaseCloudinaryConfig);
};

const fetchConfig = async (options) => {
const { profile, publicId, cloudinaryConfig, type = 'upload', videoConfig, allowUsageReport = true } = options;
const { profile, publicId, type = 'upload', videoConfig, allowUsageReport = true } = options;

if (profile && isDefaultProfile(profile)) {
return getDefaultProfileConfig(profile);
}

const cloudinaryConfig = getCloudinaryConfigFromOptions(options);
const urlPrefix = getCloudinaryUrlPrefix(cloudinaryConfig) + '/_applet_/video_service';
const queryParams = allowUsageReport ? { _s: `vp-${VERSION}` } : null;

Expand Down
Loading