Skip to content

Commit 63cb44f

Browse files
nadavofirtocker
authored andcommitted
extend support of url_suffix for different resource types
1 parent 04dcd41 commit 63cb44f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

lib/utils.js

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.coffee

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,20 @@ finalize_resource_type = (resource_type, type, url_suffix, use_root_path, shorte
544544
if resource_type == 'image' && type == 'upload'
545545
resource_type = "images"
546546
type = null
547+
else if resource_type == 'image' && type == 'private'
548+
resource_type = 'private_images'
549+
type = null
550+
else if resource_type == 'image' && type == 'authenticated'
551+
resource_type = 'authenticated_images'
552+
type = null
547553
else if resource_type == 'raw' && type == 'upload'
548554
resource_type = 'files'
549555
type = null
556+
else if resource_type == 'video' && type == 'upload'
557+
resource_type = 'videos'
558+
type = null
550559
else
551-
throw new Error("URL Suffix only supported for image/upload and raw/upload")
560+
throw new Error("URL Suffix only supported for image/upload, image/private, image/authenticated, video/upload and raw/upload")
552561
if use_root_path
553562
if (resource_type == 'image' && type == 'upload') || (resource_type == 'images' && !type?)
554563
resource_type = null

test/utils_spec.coffee

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe "utils", ->
8484
expect(()-> utils.url("test", {url_suffix:"hello"})).to.be.throwError(/URL Suffix only supported in private CDN/)
8585

8686
it "should disallow url_suffix in non upload types" , ->
87-
expect(()-> utils.url("test", {url_suffix:"hello", private_cdn:true, type:'facebook'})).to.be.throwError(/URL Suffix only supported for image\/upload and raw\/upload/)
87+
expect(()-> utils.url("test", {url_suffix:"hello", private_cdn:true, type:'facebook'})).to.be.throwError(/URL Suffix only supported for image\/upload, image\/private, image\/authenticated, video\/upload and raw\/upload/)
8888

8989
it "should disallow url_suffix with / or ." , ->
9090
expect(()-> utils.url("test", {url_suffix:"hello/world", private_cdn:true})).to.be.throwError(/url_suffix should not include . or \//)
@@ -111,6 +111,12 @@ describe "utils", ->
111111
it "should support url_suffix for raw uploads" , ->
112112
test_cloudinary_url("test", {url_suffix:"hello", private_cdn:true, resource_type:'raw'}, "http://#{cloud_name}-res.cloudinary.com/files/test/hello", {})
113113

114+
it "should support url_suffix for raw uploads" , ->
115+
test_cloudinary_url("test", {url_suffix:"hello", private_cdn:true, resource_type:'video'}, "http://#{cloud_name}-res.cloudinary.com/videos/test/hello", {})
116+
117+
it "should support url_suffix for raw uploads" , ->
118+
test_cloudinary_url("test", {url_suffix:"hello", private_cdn:true, type:'authenticated'}, "http://#{cloud_name}-res.cloudinary.com/authenticated_images/test/hello", {})
119+
114120
it "should support use_root_path in shared distribution" , ->
115121
test_cloudinary_url("test", {use_root_path:true, private_cdn:false}, "http://res.cloudinary.com/#{cloud_name}/test", {})
116122
test_cloudinary_url("test", {use_root_path:true, private_cdn:false, angle:0}, "http://res.cloudinary.com/#{cloud_name}/a_0/test", {})

0 commit comments

Comments
 (0)