mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
fix: broken out page
This commit is contained in:
parent
aa20e931ee
commit
3d2de94acf
1 changed files with 20 additions and 15 deletions
|
|
@ -1,33 +1,38 @@
|
|||
import { Icon } from "@iconify/react";
|
||||
import { Link, useNavigate, useSearchParams } from "react-router";
|
||||
import { Link, Navigate, useSearchParams } from "react-router";
|
||||
|
||||
export default function LinkOutPage() {
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const url = searchParams.get("url");
|
||||
|
||||
if (!url) {
|
||||
navigate("/");
|
||||
return null;
|
||||
}
|
||||
if (!url) return <Navigate to={"/"} replace />;
|
||||
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(url);
|
||||
} catch {
|
||||
navigate("/"); // redirect if URL is invalid
|
||||
return null;
|
||||
return <Navigate to={"/"} replace />; // redirect if URL is invalid
|
||||
}
|
||||
|
||||
if (!["http:", "https:"].includes(parsed.protocol)) {
|
||||
navigate("/");
|
||||
return null;
|
||||
}
|
||||
if (!["http:", "https:"].includes(parsed.protocol)) return <Navigate to={"/"} replace />;
|
||||
|
||||
const isSafe = Array.from(SAFE_LINKS).some((domain) => parsed.hostname === domain || parsed.hostname.endsWith(`.${domain}`));
|
||||
if (isSafe) {
|
||||
navigate(url);
|
||||
return null;
|
||||
window.location.replace(url);
|
||||
return (
|
||||
<div className="grow flex items-center justify-center">
|
||||
<div className="bg-amber-50 border-2 border-amber-500 rounded-2xl shadow-lg py-8 px-6 max-w-md w-full text-center flex flex-col items-center">
|
||||
<h2 className="text-3xl font-black flex items-center gap-4 mb-1">
|
||||
<Icon icon="svg-spinners:180-ring-with-bg" className="text-3xl" />
|
||||
Redirecting...
|
||||
</h2>
|
||||
|
||||
<div className="bg-zinc-100 border border-zinc-300 rounded-md p-2 wrap-break-word w-full mt-4">
|
||||
<code className="font-mono text-sm">{url}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -39,7 +44,7 @@ export default function LinkOutPage() {
|
|||
</h2>
|
||||
<p>You're attempting to leave TomodachiShare island! The destination website is potentially dangerous.</p>
|
||||
|
||||
<div className="bg-zinc-100 border border-zinc-300 rounded-md p-2 break-all w-full mt-4">
|
||||
<div className="bg-zinc-100 border border-zinc-300 rounded-md p-2 wrap-break-word w-full mt-4">
|
||||
<code className="font-mono text-sm">{url}</code>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue