Skip to content

Commit b5f2775

Browse files
authored
Merge pull request #12 from kadampabookings/prod
Work up to prod 17/01
2 parents fe77d11 + 8f4120a commit b5f2775

File tree

34 files changed

+444
-159
lines changed

34 files changed

+444
-159
lines changed

webfx-stack-authn-logout-client/src/main/webfx/i18n/[email protected]

Lines changed: 0 additions & 1 deletion
This file was deleted.

webfx-stack-cloud-image-client/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@
2323

2424
<dependency>
2525
<groupId>dev.webfx</groupId>
26-
<artifactId>webfx-platform-conf</artifactId>
26+
<artifactId>webfx-platform-blob</artifactId>
2727
<version>0.1.0-SNAPSHOT</version>
2828
</dependency>
2929

3030
<dependency>
3131
<groupId>dev.webfx</groupId>
32-
<artifactId>webfx-platform-console</artifactId>
32+
<artifactId>webfx-platform-conf</artifactId>
3333
<version>0.1.0-SNAPSHOT</version>
3434
</dependency>
3535

3636
<dependency>
3737
<groupId>dev.webfx</groupId>
38-
<artifactId>webfx-platform-fetch</artifactId>
38+
<artifactId>webfx-platform-console</artifactId>
3939
<version>0.1.0-SNAPSHOT</version>
4040
</dependency>
4141

4242
<dependency>
4343
<groupId>dev.webfx</groupId>
44-
<artifactId>webfx-platform-file</artifactId>
44+
<artifactId>webfx-platform-fetch</artifactId>
4545
<version>0.1.0-SNAPSHOT</version>
4646
</dependency>
4747

webfx-stack-cloud-image-client/src/main/java/dev/webfx/stack/cloud/image/impl/client/ClientImageService.java

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package dev.webfx.stack.cloud.image.impl.client;
22

33
import dev.webfx.platform.async.Future;
4+
import dev.webfx.platform.async.Promise;
5+
import dev.webfx.platform.blob.Blob;
46
import dev.webfx.platform.conf.ConfigLoader;
57
import dev.webfx.platform.console.Console;
68
import dev.webfx.platform.fetch.CorsMode;
79
import dev.webfx.platform.fetch.Fetch;
810
import dev.webfx.platform.fetch.FetchOptions;
911
import dev.webfx.platform.fetch.FormData;
10-
import dev.webfx.platform.file.File;
1112
import dev.webfx.platform.util.http.HttpMethod;
1213
import dev.webfx.platform.util.http.HttpResponseStatus;
1314
import dev.webfx.stack.cloud.image.CloudImageService;
@@ -23,8 +24,11 @@ public class ClientImageService implements CloudImageService {
2324
private String uploadUrl;
2425
private String deleteUrl;
2526
private String urlPattern;
27+
private final Future<Void> urlPatternFuture;
2628

2729
public ClientImageService() {
30+
Promise<Void> urlPatternPromise = Promise.promise();
31+
urlPatternFuture = urlPatternPromise.future();
2832
ConfigLoader.onConfigLoaded(CONFIG_PATH, config -> {
2933
existsUrl = config.getString("existsUrl");
3034
uploadUrl = config.getString("uploadUrl");
@@ -33,45 +37,52 @@ public ClientImageService() {
3337
Fetch.fetchText(urlPatternUrl, new FetchOptions()
3438
.setMethod(HttpMethod.GET)
3539
.setMode(CorsMode.NO_CORS)
36-
)
37-
.onFailure(Console::log)
38-
.onSuccess(text -> urlPattern = text);
40+
)
41+
.onFailure(Console::log)
42+
.onSuccess(text -> urlPattern = text)
43+
.onComplete(ar -> urlPatternPromise.complete());
3944
});
4045
}
4146

47+
// Helper method to ensure that we return the future only when urlPattern is loaded (because the client may need to
48+
// call CloudImageService.url() method - which requires urlPattern to be loaded - after returning the future).
49+
private <T> Future<T> whenUrlPatternLoaded(Future<T> future) {
50+
return urlPatternFuture.compose(v -> future);
51+
}
52+
4253
public Future<Boolean> exists(String id) {
43-
return Fetch.fetch(existsUrl, new FetchOptions()
44-
.setMethod(HttpMethod.POST)
45-
.setMode(CorsMode.NO_CORS)
46-
.setBody(new FormData().append("id", id))
54+
return whenUrlPatternLoaded(Fetch.fetch(existsUrl, new FetchOptions()
55+
.setMethod(HttpMethod.POST)
56+
.setMode(CorsMode.NO_CORS)
57+
.setBody(new FormData().append("id", id))
4758
).compose(response -> {
4859
if (response.ok())
4960
return Future.succeededFuture(response.status() == HttpResponseStatus.OK_200); // OK_200 = exists, NO_CONTENT_204 = doesn't exist
5061
return Future.failedFuture("Failed to call " + existsUrl + ", status = " + response.statusText());
51-
});
62+
}));
5263
}
5364

54-
public Future<Void> upload(File file, String id, boolean overwrite) {
55-
return Fetch.fetch(uploadUrl, new FetchOptions()
56-
.setMethod(HttpMethod.POST)
57-
.setMode(CorsMode.NO_CORS)
58-
.setBody(new FormData()
59-
.append("id", id)
60-
.append("overwrite", overwrite)
61-
.append("file", file, id)
62-
)
63-
).map(response -> null);
65+
public Future<Void> upload(Blob blob, String id, boolean overwrite) {
66+
return whenUrlPatternLoaded(Fetch.fetch(uploadUrl, new FetchOptions()
67+
.setMethod(HttpMethod.POST)
68+
.setMode(CorsMode.NO_CORS)
69+
.setBody(new FormData()
70+
.append("id", id)
71+
.append("overwrite", overwrite)
72+
.append("file", blob, id)
73+
)
74+
).map(response -> null));
6475
}
6576

6677
public Future<Void> delete(String id, boolean invalidate) {
67-
return Fetch.fetch(deleteUrl, new FetchOptions()
68-
.setMethod(HttpMethod.POST)
69-
.setMode(CorsMode.NO_CORS)
70-
.setBody(new FormData()
71-
.append("id", id)
72-
.append("invalidate", invalidate)
73-
)
74-
).map(response -> null);
78+
return whenUrlPatternLoaded(Fetch.fetch(deleteUrl, new FetchOptions()
79+
.setMethod(HttpMethod.POST)
80+
.setMode(CorsMode.NO_CORS)
81+
.setBody(new FormData()
82+
.append("id", id)
83+
.append("invalidate", invalidate)
84+
)
85+
).map(response -> null));
7586
}
7687

7788
@Override

webfx-stack-cloud-image-client/src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
// Direct dependencies modules
66
requires webfx.platform.async;
7+
requires webfx.platform.blob;
78
requires webfx.platform.conf;
89
requires webfx.platform.console;
910
requires webfx.platform.fetch;
10-
requires webfx.platform.file;
1111
requires webfx.platform.util.http;
1212
requires webfx.stack.cloud.image;
1313

webfx-stack-cloud-image-cloudinary/pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,24 @@
1515

1616
<dependencies>
1717

18+
<dependency>
19+
<groupId>dev.webfx</groupId>
20+
<artifactId>webfx-platform-ast</artifactId>
21+
<version>0.1.0-SNAPSHOT</version>
22+
</dependency>
23+
1824
<dependency>
1925
<groupId>dev.webfx</groupId>
2026
<artifactId>webfx-platform-async</artifactId>
2127
<version>0.1.0-SNAPSHOT</version>
2228
</dependency>
2329

30+
<dependency>
31+
<groupId>dev.webfx</groupId>
32+
<artifactId>webfx-platform-blob</artifactId>
33+
<version>0.1.0-SNAPSHOT</version>
34+
</dependency>
35+
2436
<dependency>
2537
<groupId>dev.webfx</groupId>
2638
<artifactId>webfx-platform-conf</artifactId>
@@ -29,13 +41,13 @@
2941

3042
<dependency>
3143
<groupId>dev.webfx</groupId>
32-
<artifactId>webfx-platform-fetch</artifactId>
44+
<artifactId>webfx-platform-console</artifactId>
3345
<version>0.1.0-SNAPSHOT</version>
3446
</dependency>
3547

3648
<dependency>
3749
<groupId>dev.webfx</groupId>
38-
<artifactId>webfx-platform-file</artifactId>
50+
<artifactId>webfx-platform-fetch</artifactId>
3951
<version>0.1.0-SNAPSHOT</version>
4052
</dependency>
4153

webfx-stack-cloud-image-cloudinary/src/main/java/dev/webfx/stack/cloud/image/impl/cloudinary/Cloudinary.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package dev.webfx.stack.cloud.image.impl.cloudinary;
22

3+
import dev.webfx.platform.ast.AST;
4+
import dev.webfx.platform.ast.ReadOnlyAstObject;
35
import dev.webfx.platform.async.Future;
6+
import dev.webfx.platform.blob.Blob;
47
import dev.webfx.platform.conf.ConfigLoader;
8+
import dev.webfx.platform.console.Console;
59
import dev.webfx.platform.fetch.*;
6-
import dev.webfx.platform.file.File;
7-
import dev.webfx.platform.util.http.HttpHeaders;
8-
import dev.webfx.platform.util.http.HttpMethod;
910
import dev.webfx.platform.util.Strings;
1011
import dev.webfx.platform.util.collection.Collections;
12+
import dev.webfx.platform.util.http.HttpHeaders;
13+
import dev.webfx.platform.util.http.HttpMethod;
1114
import dev.webfx.stack.cloud.image.impl.fetchbased.FetchBasedCloudImageService;
1215
import dev.webfx.stack.hash.sha1.Sha1;
1316

14-
import java.util.*;
17+
import java.util.ArrayList;
18+
import java.util.Collection;
19+
import java.util.List;
20+
import java.util.Map;
1521

1622
/**
1723
* @author Bruno Salmon
1824
*/
1925
public class Cloudinary extends FetchBasedCloudImageService {
2026

27+
private static final boolean LOG_JSON_REPLY = true;
2128
private static final String CONFIG_PATH = "webfx.stack.cloud.image.cloudinary";
2229

2330
private String cloudName;
@@ -43,17 +50,18 @@ public Future<Boolean> exists(String id) {
4350
.map(Response::ok);
4451
}
4552

46-
public Future<Void> upload(File file, String id, boolean overwrite) {
53+
public Future<Void> upload(Blob blob, String id, boolean overwrite) {
4754
return fetchJsonObject(
4855
"https://api.cloudinary.com/v1_1/" + cloudName + "/image/upload",
4956
HttpMethod.POST,
5057
new FetchOptions().setBody(
5158
signFormData(new FormData()
5259
.append("public_id", id)
5360
.append("overwrite", overwrite)
54-
).append("file", file, id)
61+
.append("invalidate", true) // Otherwise the new image might not be displayed immediately after upload
62+
).append("file", blob, id)
5563
)
56-
).map(json -> null);
64+
).map(json -> logJsonReply("upload", json));
5765
}
5866

5967
public Future<Void> delete(String id, boolean invalidate) {
@@ -66,7 +74,14 @@ public Future<Void> delete(String id, boolean invalidate) {
6674
.append("invalidate", invalidate)
6775
)
6876
)
69-
).map(json -> null);
77+
).map(json -> logJsonReply("delete", json));
78+
}
79+
80+
private static Void logJsonReply(String operation, ReadOnlyAstObject jsonReply) {
81+
if (LOG_JSON_REPLY) {
82+
Console.log("[CLOUDINARY] - " + operation + " - json reply = " + AST.formatObject(jsonReply, "json"));
83+
}
84+
return null;
7085
}
7186

7287
@Override

webfx-stack-cloud-image-cloudinary/src/main/java/module-info.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
module webfx.stack.cloud.image.cloudinary {
44

55
// Direct dependencies modules
6+
requires webfx.platform.ast;
67
requires webfx.platform.async;
8+
requires webfx.platform.blob;
79
requires webfx.platform.conf;
10+
requires webfx.platform.console;
811
requires webfx.platform.fetch;
9-
requires webfx.platform.file;
1012
requires webfx.platform.util;
1113
requires webfx.platform.util.http;
1214
requires webfx.stack.cloud.image;

webfx-stack-cloud-image/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929

3030
<dependency>
3131
<groupId>dev.webfx</groupId>
32-
<artifactId>webfx-platform-fetch</artifactId>
32+
<artifactId>webfx-platform-blob</artifactId>
3333
<version>0.1.0-SNAPSHOT</version>
3434
</dependency>
3535

3636
<dependency>
3737
<groupId>dev.webfx</groupId>
38-
<artifactId>webfx-platform-fetch-ast-json</artifactId>
38+
<artifactId>webfx-platform-fetch</artifactId>
3939
<version>0.1.0-SNAPSHOT</version>
4040
</dependency>
4141

4242
<dependency>
4343
<groupId>dev.webfx</groupId>
44-
<artifactId>webfx-platform-file</artifactId>
44+
<artifactId>webfx-platform-fetch-ast-json</artifactId>
4545
<version>0.1.0-SNAPSHOT</version>
4646
</dependency>
4747

webfx-stack-cloud-image/src/main/java/dev/webfx/stack/cloud/image/CloudImageService.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package dev.webfx.stack.cloud.image;
22

3-
import dev.webfx.platform.ast.ReadOnlyAstObject;
43
import dev.webfx.platform.async.Future;
5-
import dev.webfx.platform.file.File;
4+
import dev.webfx.platform.blob.Blob;
65

76
/**
87
* @author Bruno Salmon
@@ -11,12 +10,15 @@ public interface CloudImageService {
1110

1211
Future<Boolean> exists(String id);
1312

14-
Future<Void> upload(File file, String id, boolean overwrite);
13+
Future<Void> upload(Blob blob, String id, boolean overwrite);
1514

1615
Future<Void> delete(String id, boolean invalidate);
1716

1817
default String url(String source, int width, int height) {
19-
String url = urlPattern().replace(":source", source);
18+
String urlPattern = urlPattern();
19+
if (urlPattern == null)
20+
throw new IllegalStateException("[CloudImageService] urlPattern is null");
21+
String url = urlPattern.replace(":source", source);
2022
if (width > 0)
2123
url = url.replace(":width", "" + width);
2224
else
@@ -25,6 +27,9 @@ default String url(String source, int width, int height) {
2527
url = url.replace(":height", "" + height);
2628
else
2729
url = url.replace("/h_:height", ""); // temporary
30+
31+
//We add a random parameter to prevent the cache to display an old image
32+
url = url + "?t=" + System.currentTimeMillis();
2833
return url;
2934
}
3035

0 commit comments

Comments
 (0)