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 { Icon } from "@iconify/react";
|
||||||
import { Link, useNavigate, useSearchParams } from "react-router";
|
import { Link, Navigate, useSearchParams } from "react-router";
|
||||||
|
|
||||||
export default function LinkOutPage() {
|
export default function LinkOutPage() {
|
||||||
const navigate = useNavigate();
|
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const url = searchParams.get("url");
|
const url = searchParams.get("url");
|
||||||
|
|
||||||
if (!url) {
|
if (!url) return <Navigate to={"/"} replace />;
|
||||||
navigate("/");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let parsed: URL;
|
let parsed: URL;
|
||||||
try {
|
try {
|
||||||
parsed = new URL(url);
|
parsed = new URL(url);
|
||||||
} catch {
|
} catch {
|
||||||
navigate("/"); // redirect if URL is invalid
|
return <Navigate to={"/"} replace />; // redirect if URL is invalid
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!["http:", "https:"].includes(parsed.protocol)) {
|
if (!["http:", "https:"].includes(parsed.protocol)) return <Navigate to={"/"} replace />;
|
||||||
navigate("/");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSafe = Array.from(SAFE_LINKS).some((domain) => parsed.hostname === domain || parsed.hostname.endsWith(`.${domain}`));
|
const isSafe = Array.from(SAFE_LINKS).some((domain) => parsed.hostname === domain || parsed.hostname.endsWith(`.${domain}`));
|
||||||
if (isSafe) {
|
if (isSafe) {
|
||||||
navigate(url);
|
window.location.replace(url);
|
||||||
return null;
|
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 (
|
return (
|
||||||
|
|
@ -39,7 +44,7 @@ export default function LinkOutPage() {
|
||||||
</h2>
|
</h2>
|
||||||
<p>You're attempting to leave TomodachiShare island! The destination website is potentially dangerous.</p>
|
<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>
|
<code className="font-mono text-sm">{url}</code>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue