page.tsx85 lines, 3.1 KB
| 1 | import { Button } from "@/components/ui/button"; |
| 2 | import { getUrlByShortCode } from "@/server/actions/urls/get-url"; |
| 3 | import { AlertTriangle, ExternalLink } from "lucide-react"; |
| 4 | import { Metadata } from "next"; |
| 5 | import Link from "next/link"; |
| 6 | import { redirect } from "next/navigation"; |
| 7 | |
| 8 | export const metadata: Metadata = { |
| 9 | title: "Redirecting...", |
| 10 | description: "You are being redirected to the original URL", |
| 11 | }; |
| 12 | |
| 13 | type Params = Promise<{ shortCode: string }>; |
| 14 | |
| 15 | export default async function RedirectPage(props: { params: Params }) { |
| 16 | const { shortCode } = await props.params; |
| 17 | |
| 18 | const response = await getUrlByShortCode(shortCode); |
| 19 | |
| 20 | if (response.success && response.data) { |
| 21 | if (response.data.flagged) { |
| 22 | return ( |
| 23 | <div className="flex h-[calc(100vh-64px)] items-center justify-center px-4"> |
| 24 | <div className="w-full max-w-md mx-auto text-center"> |
| 25 | <div className="flex justify-center mb-6"> |
| 26 | <div className="size-16 rounded-full bg-yellow-100 dark:bg-yellow-900/30 flex items-center justify-center"> |
| 27 | <AlertTriangle className="size-8 text-yellow-600 dark:text-yellow-400" /> |
| 28 | </div> |
| 29 | </div> |
| 30 | <h1 className="text-2xl font-bold text-yellow-600 dark:text-yellow-400 mb-4"> |
| 31 | Caution: Flagged URL |
| 32 | </h1> |
| 33 | <p className="text-muted-foreground mb-2"> |
| 34 | This link has been flagged by our safety system and is pending |
| 35 | review by an administrator. |
| 36 | </p> |
| 37 | {response.data.flagReason && ( |
| 38 | <p className="text-sm text-yellow-600 dark:text-yellow-400 mb-6 bg-yellow-50 dark:bg-yellow-900/20 p-3 rounded-md"> |
| 39 | Reason: {response.data.flagReason} |
| 40 | </p> |
| 41 | )} |
| 42 | <div className="flex flex-col sm:flex-row gap-3 justify-center mt-6"> |
| 43 | <Button asChild variant={"outline"}> |
| 44 | <Link href={"/"}>Return to Homepage</Link> |
| 45 | </Button> |
| 46 | <Button asChild> |
| 47 | <a |
| 48 | href={response.data.originalUrl} |
| 49 | target="_blank" |
| 50 | rel="noopener noreferrer" |
| 51 | > |
| 52 | Proceed Anyway <ExternalLink className="size-4" /> |
| 53 | </a> |
| 54 | </Button> |
| 55 | </div> |
| 56 | </div> |
| 57 | </div> |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | redirect(response.data.originalUrl); |
| 62 | } |
| 63 | |
| 64 | return ( |
| 65 | <div className="flex h-[calc(100vh-64px)] items-center justify-center px-4"> |
| 66 | <div className="w-full max-w-md mx-auto text-center"> |
| 67 | <div className="flex justify-center mb-6"> |
| 68 | <div className="size-16 rounded-full bg-destructive/10 flex items-center justify-center"> |
| 69 | <AlertTriangle className="size-8 text-destructive" /> |
| 70 | </div> |
| 71 | </div> |
| 72 | <h1 className="text-2xl font-bold text-destructive mb-4"> |
| 73 | URL Not Found |
| 74 | </h1> |
| 75 | <p className="text-muted-foreground mb-6"> |
| 76 | The short link you're trying to access doesn't exist or has |
| 77 | been removed. |
| 78 | </p> |
| 79 | <Button asChild> |
| 80 | <Link href={"/"}>Return to Homepage</Link> |
| 81 | </Button> |
| 82 | </div> |
| 83 | </div> |
| 84 | ); |
| 85 | } |