@@ -12,7 +12,7 @@ import ICloudinaryConfigurations from "../interfaces/Config/ICloudinaryConfigura
12
12
* @param {Object } config
13
13
* @param {Object } descriptor
14
14
* @param {Transformation } transformation
15
- * @return {string } CloudianryURL
15
+ * @return {string } CloudinaryURL
16
16
*/
17
17
function createCloudinaryURL ( config : ICloudinaryConfigurations , descriptor ?: IDescriptor , transformation ?: Transformation ) : string {
18
18
const prefix = getUrlPrefix ( config . cloud . cloudName , config . url ) ;
@@ -38,19 +38,49 @@ function createCloudinaryURL(config: ICloudinaryConfigurations, descriptor?: IDe
38
38
39
39
/**
40
40
* Create the URL prefix for Cloudinary resources.
41
+ * Available use cases
42
+ * http://res.cloudinary.com/{cloudName}
43
+ * https://res.cloudinary.com/{cloudName}
44
+ * https://{cloudName}-res.cloudinary.com/
45
+ * http://{domain}/${cloudName}
46
+ * https://{domain}/${cloudName}
47
+ * https://{domain}
41
48
* @private
49
+ *
42
50
* @param {string } cloudName
43
51
* @param {IURLConfig } urlConfig
44
52
*/
45
- function getUrlPrefix ( cloudName : string , urlConfig :IURLConfig ) {
46
- // defaults
47
- const protocol = urlConfig . secure ? "https://" : "http://" ;
48
- const cdnPart = "" ;
49
- const subdomain = "res" ;
50
- const host = ".cloudinary.com" ;
51
- const path = `/${ cloudName } ` ;
52
-
53
- return [ protocol , cdnPart , subdomain , host , path ] . join ( "" ) ;
53
+ function getUrlPrefix ( cloudName : string , urlConfig : IURLConfig ) {
54
+ const secure = urlConfig . secure ;
55
+ const privateCDN = urlConfig . privateCdn ;
56
+ const cname = urlConfig . cname ;
57
+ const secureDistribution = urlConfig . secureDistribution ;
58
+
59
+ if ( ! secure && ! cname ) {
60
+ return `http://res.cloudinary.com/${ cloudName } ` ;
61
+ }
62
+
63
+ if ( secure && ! secureDistribution && privateCDN ) {
64
+ return `https://${ cloudName } -res.cloudinary.com` ;
65
+ }
66
+
67
+ if ( secure && ! secureDistribution ) {
68
+ return `https://res.cloudinary.com/${ cloudName } ` ;
69
+ }
70
+
71
+ if ( secure && secureDistribution && privateCDN ) {
72
+ return `https://${ secureDistribution } ` ;
73
+ }
74
+
75
+ if ( secure && secureDistribution ) {
76
+ return `https://${ secureDistribution } /${ cloudName } ` ;
77
+ }
78
+
79
+ if ( ! secure && cname ) {
80
+ return `http://${ cname } /${ cloudName } ` ;
81
+ } else {
82
+ return 'ERROR' ;
83
+ }
54
84
}
55
85
56
86
/**
@@ -59,7 +89,7 @@ function getUrlPrefix(cloudName: string, urlConfig:IURLConfig) {
59
89
*/
60
90
function handleAssetType ( descriptor : IDescriptor ) {
61
91
//default to image
62
- if ( ! descriptor || ! descriptor . assetType ) {
92
+ if ( ! descriptor || ! descriptor . assetType ) {
63
93
return 'image' ;
64
94
}
65
95
@@ -72,7 +102,7 @@ function handleAssetType(descriptor: IDescriptor) {
72
102
*/
73
103
function handleStorageType ( descriptor : IDescriptor ) {
74
104
//default to upload
75
- if ( ! descriptor || ! descriptor . storageType ) {
105
+ if ( ! descriptor || ! descriptor . storageType ) {
76
106
return 'upload' ;
77
107
}
78
108
@@ -83,7 +113,7 @@ function handleStorageType(descriptor: IDescriptor) {
83
113
* @private
84
114
* @param descriptor
85
115
*/
86
- function getUrlVersion ( urlConfig :IURLConfig , descriptor : IDescriptor ) {
116
+ function getUrlVersion ( urlConfig : IURLConfig , descriptor : IDescriptor ) {
87
117
const shouldForceVersion = urlConfig . forceVersion !== false ;
88
118
89
119
if ( descriptor . version ) {
0 commit comments