Skip to content

Commit 5566e59

Browse files
authored
Add support to use fetch format
1 parent 8688da1 commit 5566e59

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class Configuration {
4040
public Map<String, Object> properties = new HashMap<String, Object>();
4141
public Boolean secureCdnSubdomain;
4242
public boolean useRootPath;
43+
public boolean useFetchFormat;
4344
public int timeout;
4445
public boolean loadStrategies = true;
4546
public boolean clientHints = false;
@@ -68,6 +69,7 @@ private Configuration(
6869
int proxyPort,
6970
Boolean secureCdnSubdomain,
7071
boolean useRootPath,
72+
boolean useFetchFormat,
7173
int timeout,
7274
boolean loadStrategies,
7375
boolean forceVersion,
@@ -90,6 +92,7 @@ private Configuration(
9092
this.proxyPort = proxyPort;
9193
this.secureCdnSubdomain = secureCdnSubdomain;
9294
this.useRootPath = useRootPath;
95+
this.useFetchFormat = useFetchFormat;
9396
this.timeout = timeout;
9497
this.loadStrategies = loadStrategies;
9598
this.forceVersion = forceVersion;
@@ -121,6 +124,7 @@ public void update(Map config) {
121124
this.proxyPort = ObjectUtils.asInteger(config.get("proxy_port"), 0);
122125
this.secureCdnSubdomain = ObjectUtils.asBoolean(config.get("secure_cdn_subdomain"), null);
123126
this.useRootPath = ObjectUtils.asBoolean(config.get("use_root_path"), false);
127+
this.useFetchFormat = ObjectUtils.asBoolean(config.get("use_fetch_format"), false);
124128
this.loadStrategies = ObjectUtils.asBoolean(config.get("load_strategies"), true);
125129
this.timeout = ObjectUtils.asInteger(config.get("timeout"), 0);
126130
this.clientHints = ObjectUtils.asBoolean(config.get("client_hints"), false);
@@ -158,6 +162,7 @@ public Map<String, Object> asMap() {
158162
map.put("proxy_port", proxyPort);
159163
map.put("secure_cdn_subdomain", secureCdnSubdomain);
160164
map.put("use_root_path", useRootPath);
165+
map.put("use_fetch_format", useFetchFormat);
161166
map.put("load_strategies", loadStrategies);
162167
map.put("timeout", timeout);
163168
map.put("client_hints", clientHints);
@@ -190,6 +195,7 @@ public Configuration(Configuration other) {
190195
this.proxyPort = other.proxyPort;
191196
this.secureCdnSubdomain = other.secureCdnSubdomain;
192197
this.useRootPath = other.useRootPath;
198+
this.useFetchFormat = other.useFetchFormat;
193199
this.timeout = other.timeout;
194200
this.clientHints = other.clientHints;
195201
if (other.authToken != null) {
@@ -306,6 +312,7 @@ public static class Builder {
306312
private int proxyPort;
307313
private Boolean secureCdnSubdomain;
308314
private boolean useRootPath;
315+
private boolean useFetchFormat;
309316
private boolean loadStrategies = true;
310317
private int timeout;
311318
private boolean clientHints = false;
@@ -347,6 +354,7 @@ public Configuration build() {
347354
proxyPort,
348355
secureCdnSubdomain,
349356
useRootPath,
357+
useFetchFormat,
350358
timeout,
351359
loadStrategies,
352360
forceVersion,
@@ -453,6 +461,11 @@ public Builder setUseRootPath(boolean useRootPath) {
453461
return this;
454462
}
455463

464+
public Builder setUseFetchFormat(boolean useFetchFormat) {
465+
this.useFetchFormat = useFetchFormat;
466+
return this;
467+
}
468+
456469
public Builder setLoadStrategies(boolean loadStrategies) {
457470
this.loadStrategies = loadStrategies;
458471
return this;
@@ -514,6 +527,7 @@ public Builder from(Configuration other) {
514527
this.proxyPort = other.proxyPort;
515528
this.secureCdnSubdomain = other.secureCdnSubdomain;
516529
this.useRootPath = other.useRootPath;
530+
this.useFetchFormat = other.useFetchFormat;
517531
this.loadStrategies = other.loadStrategies;
518532
this.timeout = other.timeout;
519533
this.clientHints = other.clientHints;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Url {
3535
String source = null;
3636
private String urlSuffix;
3737
private Boolean useRootPath;
38+
private Boolean useFetchFormat;
3839
Map<String, Transformation> sourceTransformation = null;
3940
String[] sourceTypes = null;
4041
String fallbackContent = null;
@@ -76,6 +77,7 @@ public Url clone() {
7677
cloned.sourceTypes = this.sourceTypes;
7778
cloned.urlSuffix = this.urlSuffix;
7879
cloned.useRootPath = this.useRootPath;
80+
cloned.useFetchFormat = this.useFetchFormat;
7981
cloned.longUrlSignature = this.longUrlSignature;
8082
cloned.authToken = this.authToken;
8183
return cloned;
@@ -172,6 +174,11 @@ public Url useRootPath(boolean useRootPath) {
172174
return this;
173175
}
174176

177+
public Url useFetchFormat(boolean useFetchFormat) {
178+
this.useFetchFormat = useFetchFormat;
179+
return this;
180+
}
181+
175182
public Url cname(String cname) {
176183
this.config.cname = cname;
177184
return this;
@@ -366,7 +373,7 @@ public String generate(String source) {
366373
}
367374
}
368375

369-
if (type != null && type.equals("fetch") && !StringUtils.isEmpty(format)) {
376+
if ((type != null && type.equals("fetch") || (useFetchFormat != null && useFetchFormat)) && !StringUtils.isEmpty(format)) {
370377
transformation().fetchFormat(format);
371378
this.format = null;
372379
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,13 @@ public void testFetchFormat() {
492492
assertEquals("http://res.cloudinary.com/test123/image/fetch/f_jpg/http://cloudinary.com/images/old_logo.png", result);
493493
}
494494

495+
@Test
496+
public void testUseFetchFormat() {
497+
// should support use fetch format, adds the format but not an extension
498+
String result = cloudinary.url().format("jpg").useFetchFormat(true).generate("old_logo");
499+
assertEquals("http://res.cloudinary.com/test123/image/upload/f_jpg/old_logo", result);
500+
}
501+
495502
@Test
496503
public void testEffect() {
497504
// should support effect

0 commit comments

Comments
 (0)