mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 01:11:25 +00:00
add proxy, idk if its a good idea
This commit is contained in:
parent
4631431874
commit
449f6b4bf5
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user