Skip to content

Commit 48c23ab

Browse files
committed
Add utilities to detect and replace broken links V2
1 parent c3a64e3 commit 48c23ab

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/features/utils/LinkDetection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static CompletableFuture<Boolean> isLinkBroken(String url) {
8080
})
8181
.exceptionally(ignored -> true)
8282
.thenCompose(result -> {
83-
if (!result) {
83+
if (!Boolean.TRUE.equals(result)) {
8484
return CompletableFuture.completedFuture(false);
8585
}
8686
HttpRequest getRequest = HttpRequest.newBuilder(URI.create(url)).GET().build();
@@ -99,7 +99,9 @@ public static CompletableFuture<String> replaceDeadLinks(String text, String rep
9999

100100
List<CompletableFuture<String>> deadLinkFutures = links.stream()
101101
.distinct()
102-
.map(link -> isLinkBroken(link).thenApply(isBroken -> isBroken ? link : null))
102+
.map(link -> isLinkBroken(link)
103+
.thenApply(isBroken -> Boolean.TRUE.equals(isBroken) ? link : null))
104+
103105
.toList();
104106

105107
return CompletableFuture.allOf(deadLinkFutures.toArray(new CompletableFuture[0]))

0 commit comments

Comments
 (0)