Skip to content

Commit 2fca8d7

Browse files
nitzanjtocker
authored andcommitted
Change url suffix and root path limitations
* Allow rootPath/urlSuffix without a private cdn. * Allow rootPath/urlSuffix for videos. * Allow rootPath/urlSuffix for authenticated images.
1 parent 00c99ed commit 2fca8d7

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

cloudinary-core/src/main/java/com/cloudinary/Url.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,6 @@ public String generate(String source) {
328328
throw new IllegalArgumentException("Must supply cloud_name in tag or in configuration");
329329
}
330330

331-
if (!this.config.privateCdn) {
332-
if (StringUtils.isNotBlank(urlSuffix)) {
333-
throw new IllegalArgumentException("URL Suffix only supported in private CDN");
334-
}
335-
if (useRootPath) {
336-
throw new IllegalArgumentException("Root path only supported in private CDN");
337-
}
338-
}
339-
340331
if (source == null) {
341332
if (publicId == null) {
342333
if (this.source == null) {
@@ -457,11 +448,17 @@ public String finalizeResourceType(String resourceType, String type, String urlS
457448
} else if (resourceType.equals("image") && type.equals("private")) {
458449
resourceType = "private_images";
459450
type = null;
451+
} else if (resourceType.equals("image") && type.equals("authenticated")){
452+
resourceType = "authenticated_images";
453+
type = null;
460454
} else if (resourceType.equals("raw") && type.equals("upload")) {
461455
resourceType = "files";
462456
type = null;
457+
} else if (resourceType.equals("video") && type.equals("upload")){
458+
resourceType = "videos";
459+
type = null;
463460
} else {
464-
throw new IllegalArgumentException("URL Suffix only supported for image/upload, image/private and raw/upload");
461+
throw new IllegalArgumentException("URL Suffix only supported for image/upload, image/private, raw/upload, image/authenticated and video/upload");
465462
}
466463
}
467464
if (useRootPath) {

cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ public void testCnameSubdomain() {
163163
assertEquals("http://a2.hello.com/test123/image/upload/test", result);
164164
}
165165

166-
@Test(expected = IllegalArgumentException.class)
167-
public void testDisallowUrlSuffixInSharedDistribution() {
168-
cloudinary.url().suffix("hello").generate("test");
169-
}
170-
171166
@Test(expected = IllegalArgumentException.class)
172167
public void testDisallowUrlSuffixInNonUploadTypes() {
173168
cloudinary.url().suffix("hello").privateCdn(true).type("facebook").generate("test");
@@ -228,15 +223,23 @@ public void testSupportUrlSuffixForRawUploads() {
228223
assertEquals("http://test123-res.cloudinary.com/files/test/hello", actual);
229224
}
230225

226+
@Test
227+
public void testSupportUrlSuffixForVideoUploads() {
228+
String actual = cloudinary.url().suffix("hello").privateCdn(true).resourceType("video").generate("test");
229+
assertEquals("http://test123-res.cloudinary.com/videos/test/hello", actual);
230+
}
231+
232+
@Test
233+
public void testSupportUrlSuffixForAuthenticatedImages() {
234+
String actual = cloudinary.url().suffix("hello").privateCdn(true).resourceType("image").type("authenticated").generate("test");
235+
assertEquals("http://test123-res.cloudinary.com/authenticated_images/test/hello", actual);
236+
}
237+
231238
@Test
232239
public void testSupportUrlSuffixForPrivateImages(){
233240
String actual = cloudinary.url().suffix("hello").privateCdn(true).resourceType("image").type("private").generate("test");
234241
assertEquals("http://test123-res.cloudinary.com/private_images/test/hello", actual);
235242
}
236-
@Test(expected = IllegalArgumentException.class)
237-
public void testDisllowUseRootPathInSharedDistribution() {
238-
cloudinary.url().useRootPath(true).generate("test");
239-
}
240243

241244
@Test
242245
public void testSupportUseRootPathForPrivateCdn() {

0 commit comments

Comments
 (0)