aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/util')
-rw-r--r--src/main/java/com/juick/util/WebUtils.java13
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;
+ }
}