Skip to content

Commit 79827a8

Browse files
Add support for create_slideshow Upload API (#508)
* Add an API endpoint for create_slideshow
1 parent bbdf850 commit 79827a8

File tree

8 files changed

+176
-5
lines changed

8 files changed

+176
-5
lines changed

lib-es5/uploader.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var Cache = require('./cache');
3434
var utils = require("./utils");
3535
var UploadStream = require('./upload_stream');
3636
var config = require("./config");
37+
var ensureOption = require('./utils/ensureOption').defaults(config());
3738

3839
var build_upload_params = utils.build_upload_params,
3940
extend = utils.extend,
@@ -219,6 +220,29 @@ exports.create_zip = function create_zip(callback) {
219220
return exports.create_archive(callback, options, "zip");
220221
};
221222

223+
exports.create_slideshow = function create_slideshow(options, callback) {
224+
options.resource_type = ensureOption(options, "resource_type", "video");
225+
return call_api("create_slideshow", callback, options, function () {
226+
// Generate a transformation from the manifest_transformation key, which should be a valid transformation
227+
var manifest_transformation = utils.generate_transformation_string(extend({}, options.manifest_transformation));
228+
229+
// Try to use all the options to generate a transformation (Example: options.width and options.height)
230+
var transformation = utils.generate_transformation_string(extend({}, ensureOption(options, 'transformation', {})));
231+
232+
return [{
233+
timestamp: utils.timestamp(),
234+
manifest_transformation: manifest_transformation,
235+
upload_preset: options.upload_preset,
236+
overwrite: options.overwrite,
237+
public_id: options.public_id,
238+
notification_url: options.notification_url,
239+
manifest_json: options.manifest_json,
240+
tags: options.tags,
241+
transformation: transformation
242+
}];
243+
});
244+
};
245+
222246
exports.destroy = function destroy(public_id, callback) {
223247
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
224248

lib-es5/v2/uploader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ exports.direct_upload = uploader.direct_upload;
3434
exports.upload_tag_params = uploader.upload_tag_params;
3535
exports.upload_url = uploader.upload_url;
3636
exports.image_upload_tag = uploader.image_upload_tag;
37-
exports.unsigned_image_upload_tag = uploader.unsigned_image_upload_tag;
37+
exports.unsigned_image_upload_tag = uploader.unsigned_image_upload_tag;
38+
exports.create_slideshow = uploader.create_slideshow;

lib/uploader.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Cache = require('./cache');
1414
const utils = require("./utils");
1515
const UploadStream = require('./upload_stream');
1616
const config = require("./config");
17+
const ensureOption = require('./utils/ensureOption').defaults(config());
1718

1819
const {
1920
build_upload_params,
@@ -167,6 +168,33 @@ exports.create_zip = function create_zip(callback, options = {}) {
167168
return exports.create_archive(callback, options, "zip");
168169
};
169170

171+
172+
exports.create_slideshow = function create_slideshow(options, callback) {
173+
options.resource_type = ensureOption(options, "resource_type", "video");
174+
return call_api("create_slideshow", callback, options, function () {
175+
// Generate a transformation from the manifest_transformation key, which should be a valid transformation
176+
const manifest_transformation = utils.generate_transformation_string(extend({}, options.manifest_transformation));
177+
178+
// Try to use {options.transformation} to generate a transformation (Example: options.transformation.width, options.transformation.height)
179+
const transformation = utils.generate_transformation_string(extend({}, ensureOption(options, 'transformation', {})));
180+
181+
return [
182+
{
183+
timestamp: utils.timestamp(),
184+
manifest_transformation: manifest_transformation,
185+
upload_preset: options.upload_preset,
186+
overwrite: options.overwrite,
187+
public_id: options.public_id,
188+
notification_url: options.notification_url,
189+
manifest_json: options.manifest_json,
190+
tags: options.tags,
191+
transformation: transformation
192+
}
193+
];
194+
});
195+
};
196+
197+
170198
exports.destroy = function destroy(public_id, callback, options = {}) {
171199
return call_api("destroy", callback, options, function () {
172200
return [

lib/v2/uploader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ exports.upload_tag_params = uploader.upload_tag_params;
3333
exports.upload_url = uploader.upload_url;
3434
exports.image_upload_tag = uploader.image_upload_tag;
3535
exports.unsigned_image_upload_tag = uploader.unsigned_image_upload_tag;
36+
exports.create_slideshow = uploader.create_slideshow;

test/integration/api/provisioning/account_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ runOnlyForInternalPRs('account API - Provisioning', function () {
88
let CLOUD_API;
99
let CLOUD_NAME;
1010
let CLOUD_ID;
11-
let USER_NAME_1 = `SDK TEST ${Date.now()}`;
12-
let USER_NAME_2 = `SDK TEST 2 ${Date.now()}`;
13-
let USER_EMAIL_1 = `sdk-test+${Date.now()}@cloudinary.com`;
14-
let USER_EMAIL_2 = `sdk-test2+${Date.now()}@cloudinary.com`;
11+
let USER_NAME_1 = `NODE TEST ${Date.now()}`;
12+
let USER_NAME_2 = `NODE TEST 2 ${Date.now()}`;
13+
let USER_EMAIL_1 = `node-test+${Date.now()}@cloudinary.com`;
14+
let USER_EMAIL_2 = `node-test2+${Date.now()}@cloudinary.com`;
1515
let USER_ROLE = 'billing';
1616
let USER_ID_1;
1717
let USER_ID_2;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const Q = require('q');
2+
const cloudinary = require("../../../../cloudinary");
3+
const describe = require('../../../testUtils/suite');
4+
const TEST_ID = Date.now();
5+
6+
const createTestConfig = require('../../../testUtils/createTestConfig');
7+
8+
const testConstants = require('../../../testUtils/testConstants');
9+
const UPLOADER_V2 = cloudinary.v2.uploader;
10+
11+
const {
12+
TIMEOUT,
13+
TAGS
14+
} = testConstants;
15+
16+
const {
17+
TEST_TAG
18+
} = TAGS;
19+
20+
require('jsdom-global')();
21+
22+
describe("create slideshow tests", function () {
23+
this.timeout(TIMEOUT.LONG);
24+
after(function () {
25+
var config = cloudinary.config(true);
26+
if (!(config.api_key && config.api_secret)) {
27+
expect().fail("Missing key and secret. Please set CLOUDINARY_URL.");
28+
}
29+
return Q.allSettled([
30+
!cloudinary.config().keep_test_products ? cloudinary.v2.api.delete_resources_by_tag(TEST_TAG) : void 0,
31+
!cloudinary.config().keep_test_products ? cloudinary.v2.api.delete_resources_by_tag(TEST_TAG,
32+
{
33+
resource_type: "video"
34+
}) : void 0
35+
]);
36+
});
37+
beforeEach(function () {
38+
cloudinary.config(true);
39+
cloudinary.config(createTestConfig());
40+
});
41+
42+
43+
it("should successfully create slideshow", async function () {
44+
// this.timeout(TIMEOUT.LONG);
45+
const slideshowManifest
46+
= 'w_352;h_240;du_5;fps_30;vars_(slides_((media_s64:aHR0cHM6Ly9y' +
47+
'ZXMuY2xvdWRpbmFyeS5jb20vZGVtby9pbWFnZS91cGxvYWQvY291cGxl);(media_s64:aH' +
48+
'R0cHM6Ly9yZXMuY2xvdWRpbmFyeS5jb20vZGVtby9pbWFnZS91cGxvYWQvc2FtcGxl)))';
49+
50+
const slideshowManifestJson = {
51+
"w": 848,
52+
"h": 480,
53+
"du": 6,
54+
"fps": 30,
55+
"vars": {
56+
"sdur": 500,
57+
"tdur": 500,
58+
"slides": [
59+
{
60+
"media": "i:protests9"
61+
}, {
62+
"media": "i:protests8"
63+
},
64+
{
65+
"media": "i:protests7"
66+
},
67+
{
68+
"media": "i:protests6"
69+
},
70+
{
71+
"media": "i:protests2"
72+
},
73+
{
74+
"media": "i:protests1"
75+
}
76+
]
77+
}
78+
}
79+
80+
81+
const res = await UPLOADER_V2.create_slideshow({
82+
manifest_transformation: {
83+
custom_function: {
84+
function_type: 'render',
85+
source: slideshowManifest
86+
}
87+
},
88+
transformation: {
89+
width: 100,
90+
height: 100,
91+
crop: 'scale'
92+
},
93+
// manifest_json: slideshowManifestJson,
94+
tags: [TEST_TAG],
95+
overwrite: true,
96+
public_id: TEST_ID,
97+
notification_url: 'https://example.com'
98+
});
99+
100+
expect(res.status).to.be('processing');
101+
expect(res.public_id).to.be(TEST_ID.toString()); // TestID is int, Server returns a string and not an int.
102+
expect(res.batch_id.length).to.be.above(5); // some long string
103+
})
104+
})

types/cloudinary_ts_spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,3 +1048,14 @@ cloudinary.v2.api.create_folder('foo',{
10481048
cloudinary.v2.api.delete_folder('foo',{
10491049
agent: new Http.Agent()
10501050
});
1051+
1052+
// $ExpectType Promise<any>
1053+
cloudinary.v2.uploader.create_slideshow({
1054+
manifest_json: {
1055+
foo: 'bar' // This is a typescript Record
1056+
}, // In practice only one of the two are allowed
1057+
manifest_transformation: {
1058+
width: 100
1059+
},
1060+
height:100
1061+
});

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,8 @@ declare module 'cloudinary' {
10441044

10451045
function upload_url(options?: ConfigOptions): Promise<any>;
10461046

1047+
function create_slideshow(options?: ConfigOptions & { manifest_transformation?: TransformationOptions, manifest_json?: Record<string, any>}, callback?: UploadResponseCallback): Promise<any>;
1048+
10471049
/****************************** Structured Metadata API V2 Methods *************************************/
10481050

10491051
function update_metadata(metadata: string | object, public_ids: string[], options?:UploadApiOptions, callback?: ResponseCallback): Promise<MetadataFieldApiResponse>;

0 commit comments

Comments
 (0)