Skip to content

Commit 94d21ab

Browse files
feat: auto_transcription on upload and explicit support (#690)
1 parent 7deaf1b commit 94d21ab

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

lib/utils/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ function build_upload_params(options) {
417417
use_asset_folder_as_public_id_prefix: utils.as_safe_bool(options.use_asset_folder_as_public_id_prefix),
418418
visual_search: utils.as_safe_bool(options.visual_search),
419419
on_success: options.on_success,
420+
auto_transcription: options.auto_transcription,
420421
auto_chaptering: utils.as_safe_bool(options.auto_chaptering)
421422
};
423+
422424
return utils.updateable_resource_params(options, params);
423425
}
424426

@@ -725,6 +727,17 @@ function updateable_resource_params(options, params = {}) {
725727
if (options.regions != null) {
726728
params.regions = JSON.stringify(options.regions);
727729
}
730+
const autoTranscription = options.auto_transcription;
731+
if (autoTranscription != null) {
732+
if (typeof autoTranscription === 'boolean') {
733+
params.auto_transcription = utils.as_safe_bool(autoTranscription);
734+
} else {
735+
const isAutoTranscriptionObject = typeof autoTranscription === 'object' && !Array.isArray(autoTranscription);
736+
if (isAutoTranscriptionObject && Object.keys(autoTranscription).includes('translate')) {
737+
params.auto_transcription = JSON.stringify(autoTranscription);
738+
}
739+
}
740+
}
728741
return params;
729742
}
730743

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const sinon = require('sinon');
2+
const cloudinary = require('../../../../lib/cloudinary');
3+
const helper = require('../../../spechelper');
4+
const ClientRequest = require('_http_client').ClientRequest;
5+
6+
describe('Uploader', () => {
7+
let spy;
8+
let xhr;
9+
10+
before(() => {
11+
xhr = sinon.useFakeXMLHttpRequest();
12+
spy = sinon.spy(ClientRequest.prototype, 'write');
13+
});
14+
15+
after(() => {
16+
spy.restore();
17+
xhr.restore();
18+
});
19+
20+
describe('upload', () => {
21+
it('should send a request with auto_transcription set to true if requested', () => {
22+
cloudinary.v2.uploader.upload('irrelevant', { auto_transcription: true });
23+
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '1')));
24+
});
25+
26+
it('should send a request with auto_transcription config if requested', () => {
27+
cloudinary.v2.uploader.upload('irrelevant', { auto_transcription: { translate: ['pl'] } });
28+
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '{"translate":["pl"]}')));
29+
});
30+
});
31+
32+
describe('explicit', () => {
33+
it('should send a request with auto_transcription set to true if requested', () => {
34+
cloudinary.v2.uploader.explicit('irrelevant', { auto_transcription: true });
35+
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '1')));
36+
});
37+
38+
it('should send a request with auto_transcription config if requested', () => {
39+
cloudinary.v2.uploader.explicit('irrelevant', { auto_transcription: { translate: ['pl'] } });
40+
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('auto_transcription', '{"translate":["pl"]}')));
41+
});
42+
});
43+
});

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ declare module 'cloudinary' {
542542
use_asset_folder_as_public_id_prefix?: boolean;
543543
regions?: Record<string, [RegionCoordinate, RegionCoordinate, ...Array<RegionCoordinate>]>;
544544
auto_chaptering?: boolean;
545+
auto_transcription?: boolean | { translate: Array<string>; };
545546

546547
[futureKey: string]: any;
547548
}

0 commit comments

Comments
 (0)