From 8c37a7f9cd181fecefede8eaa12e3f3a2ef03317 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Wed, 8 May 2024 11:58:05 -0500 Subject: [PATCH] fix bug with images --- src/helpers/url.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/helpers/url.ts b/src/helpers/url.ts index 2bd020c00..a360cf1d7 100644 --- a/src/helpers/url.ts +++ b/src/helpers/url.ts @@ -1,5 +1,3 @@ -import { isValidRelayURL, validateRelayURL } from "./relay"; - export const convertToUrl = (url: string | URL) => (url instanceof URL ? url : new URL(url)); export const IMAGE_EXT = [".svg", ".gif", ".png", ".jpg", ".jpeg", ".webp", ".avif"]; @@ -23,10 +21,10 @@ export function isAudioURL(url: string | URL) { } export function getMediaHashFromURL(url: string | URL) { - const u = new URL(url); + const u = url instanceof URL ? url : new URL(url); const matches = Array.from(u.pathname.matchAll(/[0-9a-f]{64}/gi)); - return matches[matches.length - 1][0] as string | undefined; + if (matches.length > 0) return matches[matches.length - 1][0] as string | undefined; } export function replaceDomain(url: string | URL, replacementUrl: string | URL) {