Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,10 @@ function build_upload_params(options) {
use_asset_folder_as_public_id_prefix: utils.as_safe_bool(options.use_asset_folder_as_public_id_prefix),
visual_search: utils.as_safe_bool(options.visual_search),
on_success: options.on_success,
auto_transcription: options.auto_transcription,
auto_chaptering: utils.as_safe_bool(options.auto_chaptering)
};

return utils.updateable_resource_params(options, params);
}

Expand Down Expand Up @@ -725,6 +727,17 @@ function updateable_resource_params(options, params = {}) {
if (options.regions != null) {
params.regions = JSON.stringify(options.regions);
}
const autoTranscription = options.auto_transcription;
if (autoTranscription != null) {
if (typeof autoTranscription === 'boolean') {
params.auto_transcription = utils.as_safe_bool(autoTranscription);
} else {
const isAutoTranscriptionObject = typeof autoTranscription === 'object' && !Array.isArray(autoTranscription);
if (isAutoTranscriptionObject && Object.keys(autoTranscription).includes('translate')) {
params.auto_transcription = JSON.stringify(autoTranscription);
}
}
}
return params;
}

Expand Down
43 changes: 43 additions & 0 deletions test/integration/api/uploader/auto_transcription_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const sinon = require('sinon');
const cloudinary = require('../../../../lib/cloudinary');
const helper = require('../../../spechelper');
const ClientRequest = require('_http_client').ClientRequest;

describe('Uploader', () => {
let spy;
let xhr;

before(() => {
xhr = sinon.useFakeXMLHttpRequest();
spy = sinon.spy(ClientRequest.prototype, 'write');
});

after(() => {
spy.restore();
xhr.restore();
});

describe('upload', () => {
it('should send a request with auto_transcription set to true if requested', () => {
cloudinary.v2.uploader.upload('irrelevant', { auto_transcription: true });
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '1')));
});

it('should send a request with auto_transcription config if requested', () => {
cloudinary.v2.uploader.upload('irrelevant', { auto_transcription: { translate: ['pl'] } });
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '{"translate":["pl"]}')));
});
});

describe('explicit', () => {
it('should send a request with auto_transcription set to true if requested', () => {
cloudinary.v2.uploader.explicit('irrelevant', { auto_transcription: true });
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '1')));
});

it('should send a request with auto_transcription config if requested', () => {
cloudinary.v2.uploader.explicit('irrelevant', { auto_transcription: { translate: ['pl'] } });
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '{"translate":["pl"]}')));
});
});
});
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ declare module 'cloudinary' {
use_asset_folder_as_public_id_prefix?: boolean;
regions?: Record<string, [RegionCoordinate, RegionCoordinate, ...Array<RegionCoordinate>]>;
auto_chaptering?: boolean;
auto_transcription?: boolean | { translate: Array<string>; };

[futureKey: string]: any;
}
Expand Down