Skip to content

Commit fbda280

Browse files
committed
updated cloudinary file
1 parent fb36cd7 commit fbda280

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

__TESTS__/unit/asset/CloudinaryFile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Tests for CloudinaryFile', () => {
2727
.setPublicID('sample')
2828
.setSuffix('foo')
2929
.setAssetType('image')
30-
.setStorageType('private')
30+
.setDeliveryType('private')
3131
.setVersion('12345');
3232

3333
expect(cloudinaryFile.toURL()).toContain('private_images/v12345/sample/foo');

__TESTS__/unit/config/cloudinaryConfig.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describe('Tests for CloudinaryConfiguration', () => {
185185

186186
it('should support url_suffix for private uploads', () => {
187187
const img = createNewImage('sample');
188-
img.setStorageType('private');
188+
img.setDeliveryType('private');
189189
img.setSuffix('SOME_SUFFIX');
190190

191191
expect(img.toURL()).toBe("https://res.cloudinary.com/demo/private_images/sample/SOME_SUFFIX");
@@ -214,7 +214,7 @@ describe('Tests for CloudinaryConfiguration', () => {
214214
const img = createNewImage('sample', {}, {
215215
useRootPath: true,
216216
privateCdn: true
217-
}).setStorageType('private');
217+
}).setDeliveryType('private');
218218
img.toURL();
219219
}).toThrow();
220220

__TESTS__/unit/url/encoding.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ describe('Tests for Encoding the URL', () => {
6464

6565
it('Fetch: should not encode ("$:/") signs', () => {
6666
const img = createNewImage('https://res.cloudinary.com/demo/image/upload/sample?a=b');
67-
img.setStorageType('fetch');
67+
img.setDeliveryType('fetch');
6868

6969
expect(img.toURL())
7070
.toBe('https://res.cloudinary.com/demo/image/fetch/https://res.cloudinary.com/demo/image/upload/sample%3Fa%3Db');
7171
});
7272

7373
it('Should correctly encode youtube URLs', () => {
7474
const img = createNewImage('https://www.youtube.com/watch?v=d9NF2edxy-M');
75-
img.setStorageType('youtube');
75+
img.setDeliveryType('youtube');
7676

7777
expect(img.toURL())
7878
.toBe('https://res.cloudinary.com/demo/image/youtube/https://www.youtube.com/watch%3Fv%3Dd9NF2edxy-M');

__TESTS__/unit/url/url.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ describe('Tests for URL configuration', () => {
4040
// Suffix only works with predefined SEO_TYPES
4141
Object.keys(SEO_TYPES).forEach((resourceType) => {
4242
const [assetType, storageType] = resourceType.split('/');
43-
image.setStorageType(assetType)
44-
.setStorageType(storageType);
43+
image.setDeliveryType(assetType)
44+
.setDeliveryType(storageType);
4545

4646
expect(image.toURL.bind(image)).not.toThrow();
4747
});
4848

4949
// Any other storage type should throw
50-
image.setStorageType('fff');
50+
image.setDeliveryType('fff');
5151
expect(image.toURL.bind(image)).toThrow();
5252
});
5353

src/assets/CloudinaryFile.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,32 @@ export const SEO_TYPES: Record<string, string> = {
2424
"video/upload": "videos"
2525
};
2626

27+
/**
28+
* Supported delivery type options.
29+
*/
30+
type DELIVERY_TYPE =
31+
'key'|
32+
'upload'|
33+
'private_delivery'|
34+
'public_delivery'|
35+
'authenticated'|
36+
'fetch'|
37+
'sprite'|
38+
'text'|
39+
'multi'|
40+
'facebook'|
41+
'twitter'|
42+
'twitter_name'|
43+
'gravatar'|
44+
'youtube'|
45+
'hulu'|
46+
'vimeo'|
47+
'animoto'|
48+
'worldstarhiphop'|
49+
'dailymotion';
2750

2851
/**
29-
* @desc Cloudinary file without a transformation
52+
* @descriptionCloudinary file without a transformation
3053
* @summary SDK
3154
* @memberOf SDK
3255
*/
@@ -55,7 +78,7 @@ class CloudinaryFile {
5578
}
5679

5780
/**
58-
* @desc Sets the public ID of the asset.
81+
* @description Sets the public ID of the asset.
5982
* @param {string} publicID The public ID of the asset.
6083
* @return {this}
6184
*/
@@ -66,18 +89,17 @@ class CloudinaryFile {
6689
}
6790

6891
/**
69-
* @desc Sets the storage type of the asset.
70-
* @param {string} newType The type of the asset. Supported values are key, image,
71-
* video, raw, auto, all.
92+
* @description Sets the delivery type of the asset.
93+
* @param {DELIVERY_TYPE | string} newType The type of the asset.
7294
* @return {this}
7395
*/
74-
setStorageType(newType: string): this {
96+
setDeliveryType(newType: DELIVERY_TYPE|string): this {
7597
this.storageType = newType;
7698
return this;
7799
}
78100

79101
/**
80-
* @desc Sets the URL SEO suffix of the asset.
102+
* @description Sets the URL SEO suffix of the asset.
81103
* @param {string} newSuffix The SEO suffix.
82104
* @return {this}
83105
*/
@@ -87,7 +109,7 @@ class CloudinaryFile {
87109
}
88110

89111
/**
90-
* @desc Sets the signature of the asset.
112+
* @description Sets the signature of the asset.
91113
* @param {string} signature The signature.
92114
* @return {this}
93115
*/
@@ -97,7 +119,7 @@ class CloudinaryFile {
97119
}
98120

99121
/**
100-
* @desc Sets the version of the asset.
122+
* @description Sets the version of the asset.
101123
* @param {string} newVersion The version of the asset.
102124
* @return {this}
103125
*/
@@ -109,12 +131,11 @@ class CloudinaryFile {
109131
}
110132

111133
/**
112-
* @desc Sets the asset type.
113-
* @param {string} newType The type of the asset. Supported values are key, image,
114-
* video, raw, auto, all.
134+
* @description Sets the asset type.
135+
* @param {string} newType The type of the asset.
115136
* @return {this}
116137
*/
117-
setAssetType(newType: string): this {
138+
setAssetType(newType: 'key'|'image'|'video'|'raw'|'auto'|'all'|string): this {
118139
if (newType) {
119140
this.assetType = newType;
120141
}
@@ -125,6 +146,10 @@ class CloudinaryFile {
125146
return this;
126147
}
127148

149+
/**
150+
* @description Serializes to URL string
151+
* @param overwriteOptions
152+
*/
128153
toURL(overwriteOptions: {trackedAnalytics?: Partial<ITrackedPropertiesThroughAnalytics>} = {}): string {
129154
return this.createCloudinaryURL(null, overwriteOptions.trackedAnalytics);
130155
}

0 commit comments

Comments
 (0)