@@ -339,7 +339,6 @@ public String generate() {
339
339
}
340
340
341
341
public String generate (String source ) {
342
-
343
342
boolean useRootPath = this .config .useRootPath ;
344
343
if (this .useRootPath != null ) {
345
344
useRootPath = this .useRootPath ;
@@ -405,8 +404,7 @@ public String generate(String source) {
405
404
String resourceType = this .resourceType ;
406
405
if (resourceType == null ) resourceType = "image" ;
407
406
String finalResourceType = finalizeResourceType (resourceType , type , urlSuffix , useRootPath , config .shorten );
408
- String prefix = unsignedDownloadUrlPrefix (source , config .cloudName , config .privateCdn , config .cdnSubdomain , config .secureCdnSubdomain , config .cname , config .secure , config .secureDistribution );
409
-
407
+ String prefix = unsignedDownloadUrlPrefix (source , config );
410
408
String join = StringUtils .join (new String []{prefix , finalResourceType , signature , transformationStr , version , source }, "/" );
411
409
String url = StringUtils .mergeSlashesInUrl (join );
412
410
@@ -507,49 +505,52 @@ public String finalizeResourceType(String resourceType, String type, String urlS
507
505
return result ;
508
506
}
509
507
510
- public String unsignedDownloadUrlPrefix (String source , String cloudName , boolean privateCdn , boolean cdnSubdomain , Boolean secureCdnSubdomain , String cname , boolean secure , String secureDistribution ) {
511
- if (this . config .cloudName .startsWith ("/" )) {
512
- return "/res" + this . config .cloudName ;
508
+ public static String unsignedDownloadUrlPrefix (String source , Configuration config ) {
509
+ if (config .cloudName .startsWith ("/" )) {
510
+ return "/res" + config .cloudName ;
513
511
}
514
- boolean sharedDomain = !this . config .privateCdn ;
512
+ boolean sharedDomain = !config .privateCdn ;
515
513
516
514
String prefix ;
515
+ String cloudName ;
516
+ String secureDistribution = config .secureDistribution ;
517
+ Boolean secureCdnSubdomain = null ;
517
518
518
- if (this . config .secure ) {
519
- if (StringUtils .isEmpty (this . config .secureDistribution ) || this . config .secureDistribution .equals (Cloudinary .OLD_AKAMAI_SHARED_CDN )) {
520
- secureDistribution = this . config .privateCdn ? this . config .cloudName + "-res.cloudinary.com" : Cloudinary .SHARED_CDN ;
519
+ if (config .secure ) {
520
+ if (StringUtils .isEmpty (config .secureDistribution ) || config .secureDistribution .equals (Cloudinary .OLD_AKAMAI_SHARED_CDN )) {
521
+ secureDistribution = config .privateCdn ? config .cloudName + "-res.cloudinary.com" : Cloudinary .SHARED_CDN ;
521
522
}
522
523
if (!sharedDomain ) {
523
524
sharedDomain = secureDistribution .equals (Cloudinary .SHARED_CDN );
524
525
}
525
526
526
527
if (secureCdnSubdomain == null && sharedDomain ) {
527
- secureCdnSubdomain = this . config .cdnSubdomain ;
528
+ secureCdnSubdomain = config .cdnSubdomain ;
528
529
}
529
530
530
531
if (secureCdnSubdomain != null && secureCdnSubdomain == true ) {
531
- secureDistribution = this . config .secureDistribution .replace ("res.cloudinary.com" , "res-" + shard (source ) + ".cloudinary.com" );
532
+ secureDistribution = config .secureDistribution .replace ("res.cloudinary.com" , "res-" + shard (source ) + ".cloudinary.com" );
532
533
}
533
534
534
535
prefix = "https://" + secureDistribution ;
535
- } else if (StringUtils .isNotBlank (this . config .cname )) {
536
- String subdomain = this . config .cdnSubdomain ? "a" + shard (source ) + "." : "" ;
537
- prefix = "http://" + subdomain + this . config .cname ;
536
+ } else if (StringUtils .isNotBlank (config .cname )) {
537
+ String subdomain = config .cdnSubdomain ? "a" + shard (source ) + "." : "" ;
538
+ prefix = "http://" + subdomain + config .cname ;
538
539
} else {
539
540
String protocol = "http://" ;
540
- cloudName = this . config .privateCdn ? this . config .cloudName + "-" : "" ;
541
+ cloudName = config .privateCdn ? config .cloudName + "-" : "" ;
541
542
String res = "res" ;
542
- String subdomain = this . config .cdnSubdomain ? "-" + shard (source ) : "" ;
543
+ String subdomain = config .cdnSubdomain ? "-" + shard (source ) : "" ;
543
544
String domain = ".cloudinary.com" ;
544
545
prefix = StringUtils .join (new String []{protocol , cloudName , res , subdomain , domain }, "" );
545
546
}
546
547
if (sharedDomain ) {
547
- prefix += "/" + this . config .cloudName ;
548
+ prefix += "/" + config .cloudName ;
548
549
}
549
550
return prefix ;
550
551
}
551
552
552
- private String shard (String input ) {
553
+ private static String shard (String input ) {
553
554
CRC32 crc32 = new CRC32 ();
554
555
crc32 .update (Util .getUTF8Bytes (input ));
555
556
return String .valueOf ((crc32 .getValue () % 5 + 5 ) % 5 + 1 );
0 commit comments