import { useEffect, useState } from "react"; import { useRaw } from "../../store/raw"; import { useLocation } from "react-router"; import { DynamicIcon } from "lucide-react/dynamic"; import "./fview.scss"; function FileView() { const raw = useRaw(); const location = useLocation(); const [load, setLoad] = useState(false); useEffect(() => { if (!load) { raw.update(location.pathname.substring(1, location.pathname.length)); setLoad(true); return; } }, [raw, location, load]); return (
{decodeURIComponent(location.pathname)}
{ ev.preventDefault(); navigator.clipboard.writeText(`${document.location.origin}/api/raw${location.pathname}`) .then(() => alert("url copied to clipboard")) .catch(err => console.error("Failed to copy text: ", err)); }}> { ev.preventDefault(); fetch(`/api/download${location.pathname}`) .then(response => response.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.style.display = "none"; a.href = url; a.download = location.pathname.split("/").pop() || "download"; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); }) .catch(error => console.error("Download failed:", error)); }}>
{raw.data}
); } export default FileView;