import { useState } from "react"; import Link from "next/link"; import { MetaScrapingProps } from "@/app/(protected)/dashboard/scrape/scrapes"; import { Skeleton } from "../ui/skeleton"; import { Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipTrigger, } from "../ui/tooltip"; import BlurImage from "./blur-image"; import { Icons } from "./icons"; export function LinkPreviewer({ apiKey, url, formatUrl, }: { apiKey: string; url: string; formatUrl: string; }) { const [screenshotInfo, setScreenshotInfo] = useState({ tmp_url: "", }); const handleScrapingScreenshot = async () => { if (url) { const res = await fetch( `/api/v1/scraping/screenshot?url=${url}&key=${apiKey}&width=1200&height=750&viewportWidth=1200&viewportHeight=750`, ); if (!res.ok || res.status !== 200) { } else { const blob = await res.blob(); const imageUrl = URL.createObjectURL(blob); setScreenshotInfo({ tmp_url: imageUrl, }); } } }; const handleOpenChange = (open: boolean) => { if (open) { handleScrapingScreenshot(); } }; return ( {formatUrl} {screenshotInfo.tmp_url ? ( ) : ( )} ); } export function LinkInfoPreviewer({ apiKey, url, formatUrl, }: { apiKey: string; url: string; formatUrl: string; }) { const placeholdImage = "/_static/illustrations/rocket-crashed.svg"; const [metaInfo, setMetaInfo] = useState({ title: "", description: "", image: "", icon: "", url: "", lang: "", author: "", timestamp: "", payload: "", }); const handleScrapingInfo = async () => { if (url) { const res = await fetch(`/api/v1/scraping/meta?url=${url}&key=${apiKey}`); if (!res.ok || res.status !== 200) { setMetaInfo({ title: url, description: "", image: placeholdImage, icon: "", url: "", lang: "", author: "", timestamp: "", payload: "", }); } else { const data = await res.json(); setMetaInfo({ ...data, title: data.title || url }); } } }; const handleOpenChange = (open: boolean) => { if (open) { handleScrapingInfo(); } }; return ( {formatUrl} {metaInfo.title ? ( <> {metaInfo.title} {metaInfo.description && ( {metaInfo.description} )} > ) : ( )} ); }
{metaInfo.title}
{metaInfo.description}