@ -1,6 +1,7 @@
|
|||||||
import useImgProxy from "Hooks/useImgProxy";
|
import useImgProxy from "Hooks/useImgProxy";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
|
import { getUrlHostname } from "Util";
|
||||||
|
|
||||||
interface ProxyImgProps extends React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement> {
|
interface ProxyImgProps extends React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement> {
|
||||||
size?: number;
|
size?: number;
|
||||||
@ -34,7 +35,7 @@ export const ProxyImg = (props: ProxyImgProps) => {
|
|||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Failed to proxy image from {host}, click here to load directly"
|
defaultMessage="Failed to proxy image from {host}, click here to load directly"
|
||||||
values={{
|
values={{
|
||||||
host: new URL(src ?? "").hostname,
|
host: getUrlHostname(src),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -166,7 +166,7 @@ export default function Text({ content, tags, creator, disableMedia, depth }: Te
|
|||||||
if (t) {
|
if (t) {
|
||||||
return <ProxyImg src={t[2]} size={15} className="custom-emoji" />;
|
return <ProxyImg src={t[2]} size={15} className="custom-emoji" />;
|
||||||
} else {
|
} else {
|
||||||
return i;
|
return `:${i}:`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -497,6 +497,14 @@ export function getRelayName(url: string) {
|
|||||||
return parsedUrl.host + parsedUrl.search;
|
return parsedUrl.host + parsedUrl.search;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUrlHostname(url?: string) {
|
||||||
|
try {
|
||||||
|
return new URL(url ?? "").hostname;
|
||||||
|
} catch {
|
||||||
|
return url?.match(/(\S+\.\S+)/i)?.[1] ?? url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface NostrLink {
|
export interface NostrLink {
|
||||||
type: NostrPrefix;
|
type: NostrPrefix;
|
||||||
id: string;
|
id: string;
|
||||||
|
Reference in New Issue
Block a user