diff options
author | Vitaly Takmazov | 2024-02-23 12:10:14 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2024-02-23 12:20:20 +0300 |
commit | ba742fbe56b13e263aeeec14d9e2515c490bc316 (patch) | |
tree | 41cc02410f68b54442d6a20bd833aef215b7eed8 /src/main/java/com/juick/util | |
parent | 731efedb49a46eff0a6f53470769f4d7fbaf8676 (diff) |
Telegram: display Juick links
Diffstat (limited to 'src/main/java/com/juick/util')
-rw-r--r-- | src/main/java/com/juick/util/WebUtils.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/com/juick/util/WebUtils.java b/src/main/java/com/juick/util/WebUtils.java index a8e690ed..b9f8ca1a 100644 --- a/src/main/java/com/juick/util/WebUtils.java +++ b/src/main/java/com/juick/util/WebUtils.java @@ -17,6 +17,9 @@ package com.juick.util; +import org.apache.commons.lang3.math.NumberUtils; +import org.springframework.web.util.UriComponents; + import java.util.regex.Pattern; /** @@ -63,4 +66,14 @@ public class WebUtils { .replaceAll("\\'", "\\\\'") .replaceAll("=", "\\\\\\\\="); } + + public static int getMessageNumberFromUrl(String ourDomain, UriComponents url) { + return getMessageNumberFromUrl(ourDomain, url, false); + } + public static int getMessageNumberFromUrl(String ourDomain, UriComponents url, boolean legacyOnly) { + if (url.getPath() == null || url.getHost() == null) return -1; + var messageNumberPathSegment = legacyOnly ? url.getPath().substring(1) + : url.getPath().substring(url.getPath().lastIndexOf("/") + 1); + return url.getHost().equals(ourDomain) ? NumberUtils.toInt(messageNumberPathSegment, -1) : -1; + } } |