-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into link-webhook
- Loading branch information
Showing
26 changed files
with
307 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { getDomainViaEdge } from "@/lib/planetscale/get-domain-via-edge"; | ||
import { Background, Footer, Nav, NavMobile } from "@dub/ui"; | ||
import { constructMetadata } from "@dub/utils"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export const metadata = constructMetadata({ | ||
title: "Link Not Found – Dub.co", | ||
description: | ||
"This link does not exist on Dub.co. Please check the URL and try again.", | ||
noIndex: true, | ||
}); | ||
|
||
export default async function NotFoundLinkPage({ | ||
params, | ||
}: { | ||
params: { domain: string }; | ||
}) { | ||
const domain = await getDomainViaEdge(params.domain); | ||
|
||
if (domain?.notFoundUrl) { | ||
redirect(domain.notFoundUrl); | ||
} | ||
|
||
return ( | ||
<main className="flex min-h-screen flex-col justify-between"> | ||
<NavMobile /> | ||
<Nav /> | ||
<div className="z-10 mx-2 my-10 flex max-w-md flex-col items-center space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16"> | ||
<div className="font-display mx-auto flex h-20 w-20 items-center justify-center rounded-full border border-gray-300 bg-white/80 text-lg font-bold text-gray-400"> | ||
404 | ||
</div> | ||
<h1 className="font-display text-5xl font-bold">Link Not Found</h1> | ||
<p className="text-lg text-gray-600"> | ||
This link does not exist. Please check the URL and try again. | ||
</p> | ||
<a | ||
href="https://dub.co/home" | ||
className="rounded-full bg-gray-800 px-10 py-2 font-medium text-white transition-colors hover:bg-black" | ||
> | ||
Create Your Free Branded Link | ||
</a> | ||
</div> | ||
<Footer /> | ||
<Background /> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { punyEncode } from "@dub/utils"; | ||
import { conn } from "./connection"; | ||
|
||
export const checkIfKeyExists = async (domain: string, key: string) => { | ||
const { rows } = | ||
(await conn.execute( | ||
"SELECT 1 FROM Link WHERE domain = ? AND `key` = ? LIMIT 1", | ||
[domain, punyEncode(decodeURIComponent(key))], // we need to make sure that the key is always URI-decoded + punycode-encoded (cause that's how we store it in MySQL) | ||
)) || {}; | ||
|
||
return rows && Array.isArray(rows) && rows.length > 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { conn } from "./connection"; | ||
|
||
export const checkIfUserExists = async (userId: string) => { | ||
const { rows } = | ||
(await conn.execute("SELECT 1 FROM User WHERE id = ? LIMIT 1", [userId])) || | ||
{}; | ||
|
||
return rows && Array.isArray(rows) && rows.length > 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { connect } from "@planetscale/database"; | ||
|
||
export const conn = connect({ | ||
url: process.env.PLANETSCALE_DATABASE_URL || process.env.DATABASE_URL, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { conn } from "./connection"; | ||
import { EdgeDomainProps } from "./types"; | ||
|
||
export const getDomainViaEdge = async (domain: string) => { | ||
const { rows } = | ||
(await conn.execute("SELECT * FROM Domain WHERE slug = ?", [domain])) || {}; | ||
|
||
return rows && Array.isArray(rows) && rows.length > 0 | ||
? (rows[0] as EdgeDomainProps) | ||
: null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Link } from "@prisma/client"; | ||
import { conn } from "./connection"; | ||
|
||
// Get link by workspaceId and identifier | ||
export const getLinkByIdentifier = async ( | ||
workspaceId: string, | ||
identifier: string, | ||
) => { | ||
const { rows } = | ||
(await conn.execute( | ||
"SELECT * FROM Link WHERE projectId = ? AND identifier = ?", | ||
[workspaceId, identifier], | ||
)) || {}; | ||
|
||
return rows && Array.isArray(rows) && rows.length > 0 | ||
? (rows[0] as Link) | ||
: null; | ||
}; |
Oops, something went wrong.