mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-18 22:44:26 +01:00
fix: handle URL parsing error in imageUrl
This commit is contained in:
@@ -3,6 +3,7 @@ import parseTextNote, { resolveTagReference, type ParsedTextNoteNode } from '@/c
|
|||||||
import type { Event as NostrEvent } from 'nostr-tools';
|
import type { Event as NostrEvent } from 'nostr-tools';
|
||||||
import PlainTextDisplay from '@/components/textNote/PlainTextDisplay';
|
import PlainTextDisplay from '@/components/textNote/PlainTextDisplay';
|
||||||
import MentionedUserDisplay from '@/components/textNote/MentionedUserDisplay';
|
import MentionedUserDisplay from '@/components/textNote/MentionedUserDisplay';
|
||||||
|
// eslint-disable-next-line import/no-cycle
|
||||||
import MentionedEventDisplay from '@/components/textNote/MentionedEventDisplay';
|
import MentionedEventDisplay from '@/components/textNote/MentionedEventDisplay';
|
||||||
import ImageDisplay from '@/components/textNote/ImageDisplay';
|
import ImageDisplay from '@/components/textNote/ImageDisplay';
|
||||||
import SafeLink from '@/components/utils/SafeLink';
|
import SafeLink from '@/components/utils/SafeLink';
|
||||||
@@ -59,7 +60,7 @@ const TextNoteContentDisplay = (props: TextNoteContentDisplayProps) => {
|
|||||||
return <span class="text-blue-500 underline">{item.content}</span>;
|
return <span class="text-blue-500 underline">{item.content}</span>;
|
||||||
}
|
}
|
||||||
if (item.type === 'URL') {
|
if (item.type === 'URL') {
|
||||||
if (isImageUrl(new URL(item.content))) {
|
if (isImageUrl(item.content)) {
|
||||||
return (
|
return (
|
||||||
<ImageDisplay
|
<ImageDisplay
|
||||||
url={item.content}
|
url={item.content}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Switch, Match, type Component } from 'solid-js';
|
import { Switch, Match, type Component } from 'solid-js';
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-cycle
|
||||||
import TextNoteDisplay, { type TextNoteDisplayProps } from '@/components/textNote/TextNoteDisplay';
|
import TextNoteDisplay, { type TextNoteDisplayProps } from '@/components/textNote/TextNoteDisplay';
|
||||||
|
|
||||||
import useConfig from '@/nostr/useConfig';
|
import useConfig from '@/nostr/useConfig';
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
export const isImageUrl = (url: URL): boolean => {
|
export const isImageUrl = (urlString: string): boolean => {
|
||||||
return /\.(jpeg|jpg|png|gif|webp)$/i.test(url.pathname);
|
try {
|
||||||
|
const url = new URL(urlString);
|
||||||
|
return /\.(jpeg|jpg|png|gif|webp)$/i.test(url.pathname);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fixUrl = (urlString: string): string => {
|
export const fixUrl = (urlString: string): string => {
|
||||||
|
|||||||
Reference in New Issue
Block a user