add proxy, idk if its a good idea

This commit is contained in:
smolgrrr 2023-10-31 11:33:47 +11:00
parent 4631431874
commit 449f6b4bf5

View File

@ -2,19 +2,23 @@ import { getLinkPreview } from 'link-preview-js';
import { useState, useEffect } from 'react';
//Need to move this all server side
const LinkModal = ({ url }: { url: string }) => {
const [linkPreview, setLinkPreview] = useState<LinkPreview | null>(null);
useEffect(() => {
const proxyUrl = 'https://api.allorigins.win/raw?url=';
getLinkPreview(url)
.then((preview) => setLinkPreview(preview as LinkPreview))
.catch((error) => console.error(error));
.catch(error => {
console.error("Error fetching original URL, trying with proxy:", error);
return getLinkPreview(proxyUrl + url);
})
.then((preview) => setLinkPreview(preview as LinkPreview))
.catch((error) => console.error("Error fetching URL with proxy:", error));
}, [url]);
if (!linkPreview) {
return <a className="hover:underline" href={url}>{url}</a>; // or some loading state
return <a className='hover:underline' href={url}>{url}</a>; // or some loading state
}
return (