From 294dd3a6b08c9739273a778a1ca79adaaefca6b6 Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Fri, 19 Apr 2024 02:32:18 -0400 Subject: [PATCH] Image Fix Async --- frontend-next/src/components/app/datatypes.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend-next/src/components/app/datatypes.js b/frontend-next/src/components/app/datatypes.js index de09d4c..bda0465 100644 --- a/frontend-next/src/components/app/datatypes.js +++ b/frontend-next/src/components/app/datatypes.js @@ -43,9 +43,18 @@ let dateOptions = { * @returns {Boolean} - Image Loaded (True) or Not (False) */ function imageProcessing(url) { - var img = new Image(); - img.src = url; - return img.complete; + var x = async () => { + var img = new Image(); + img.src = url; + img.onload = function() { + return true; + } + img.onerror = function() { + return false; + } + } + var res = x() + return res } @@ -62,7 +71,7 @@ function RMF(message) { for (var i = 0; i < URLmatch.length; i++) { if (imageProcessing("https://"+URLmatch[i])) { newMessage.push(( - {(URLmatch.length == 1) && message.split(URLmatch[i])[0].replace("https://","")} + {(URLmatch.length == 1) && message.split(URLmatch[i])[0].replace("https://","").replace("http://","")} {(i == URLmatch.length || URLmatch.length == 1) && message.split(URLmatch[i])[1]} ))