diff --git a/frontend-next/src/components/app/datatypes.js b/frontend-next/src/components/app/datatypes.js
index 602fb96..de09d4c 100644
--- a/frontend-next/src/components/app/datatypes.js
+++ b/frontend-next/src/components/app/datatypes.js
@@ -37,29 +37,42 @@ let dateOptions = {
minute: "2-digit",
};
+/**
+ * Photo URL Test
+ * @param {String} url - URL to Test
+ * @returns {Boolean} - Image Loaded (True) or Not (False)
+ */
+function imageProcessing(url) {
+ var img = new Image();
+ img.src = url;
+ return img.complete;
+}
+
+
/**
* Rich Message Formatting
* @param {String} message - Message to Format
* @returns {String} - Formatted Message (IN HTML)
*/
function RMF(message) {
- var IMG_END = [".jpg", ".jpeg", ".png", ".gif", ".webp"]
var URLREGEX = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
var URLmatch = message.match(URLREGEX);
var newMessage = URLmatch ? [] : message
if (URLmatch) {
for (var i = 0; i < URLmatch.length; i++) {
- if (IMG_END.includes(URLmatch[i].slice(-4)) || IMG_END.includes(URLmatch[i].slice(-5))) {
- // Its a photo
- newMessage.push((
))
- } else {
+ if (imageProcessing("https://"+URLmatch[i])) {
newMessage.push((
- {URLmatch.length == 1 && message.split(URLmatch[i])[0]}
- {URLmatch[i]}
+ {(URLmatch.length == 1) && message.split(URLmatch[i])[0].replace("https://","")}
+
{(i == URLmatch.length || URLmatch.length == 1) && message.split(URLmatch[i])[1]}
))
+ } else {
+ newMessage.push((
+ {URLmatch.length == 1 && message.split(URLmatch[i])[0]}
+ {URLmatch[i]}
+ {(i == URLmatch.length || URLmatch.length == 1) && message.split(URLmatch[i])[1]}
+ ))
}
-
}
}
return newMessage