From 257489d85c9654ff9b34d29e3107283e1a543fca Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Mon, 19 Dec 2022 12:34:47 -0300 Subject: [PATCH] refactor the location --- app/containers/message/Urls.tsx | 8 ++------ app/lib/methods/helpers/image.ts | 2 ++ app/lib/methods/helpers/index.ts | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 app/lib/methods/helpers/image.ts diff --git a/app/containers/message/Urls.tsx b/app/containers/message/Urls.tsx index 3503d0b7d..6ca09b6c0 100644 --- a/app/containers/message/Urls.tsx +++ b/app/containers/message/Urls.tsx @@ -14,6 +14,7 @@ import EventEmitter from '../../lib/methods/helpers/events'; import I18n from '../../i18n'; import MessageContext from './Context'; import { IUrl } from '../../definitions'; +import { isImage, isValidURL } from '../../lib/methods/helpers'; const styles = StyleSheet.create({ button: { @@ -94,11 +95,6 @@ const UrlContent = React.memo( } ); -const isImage = (url: string) => { - const regExpUrlImage = new RegExp(/\.(jpg|jpeg|png|webp|avif|gif|svg)$/); - return regExpUrlImage.test(url); -}; - const Url = React.memo( ({ url, index, theme }: { url: IUrl; index: number; theme: TSupportedThemes }) => { if (!url || url?.ignoreParse) { @@ -117,7 +113,7 @@ const Url = React.memo( if (url.image) { imageUrl = url.image; } else { - imageUrl = isImage(url.url) ? url.url : ''; + imageUrl = isImage(url.url) && isValidURL(url.url) ? url.url : ''; } return ( diff --git a/app/lib/methods/helpers/image.ts b/app/lib/methods/helpers/image.ts new file mode 100644 index 000000000..60120670e --- /dev/null +++ b/app/lib/methods/helpers/image.ts @@ -0,0 +1,2 @@ +const regExpUrlImage = new RegExp(/\.(jpg|jpeg|png|webp|avif|gif|svg)$/); +export const isImage = (url: string) => regExpUrlImage.test(url); diff --git a/app/lib/methods/helpers/index.ts b/app/lib/methods/helpers/index.ts index 0c9414e9c..4098203a0 100644 --- a/app/lib/methods/helpers/index.ts +++ b/app/lib/methods/helpers/index.ts @@ -14,3 +14,4 @@ export * from './server'; export * from './url'; export * from './isValidEmail'; export * from './random'; +export * from './image';