The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added reserved links
Steven Teyfe29972d639b
diff --git a/lib/constants.ts b/lib/constants.tsindex 575eb142fa..4725e4246c 100644--- a/lib/constants.ts+++ b/lib/constants.ts@@ -13,7 +13,13 @@ export const FRAMER_MOTION_LIST_ITEM_VARIANTS = {show: { scale: 1, opacity: 1, transition: { type: "spring" } },};-export const RESERVED_KEYS = ["pricing", "about", "stats", "placeholder"];+export const RESERVED_KEYS = [+ "pricing",+ "about",+ "stats",+ "placeholder",+ "blog",+];export const COUNTRIES: { [key: string]: string } = {AF: "Afghanistan",diff --git a/lib/upstash.ts b/lib/upstash.tsindex 06a3d8c43c..242a128d24 100644--- a/lib/upstash.ts+++ b/lib/upstash.ts@@ -1,6 +1,6 @@import { Redis } from "@upstash/redis";import { NextRequest, userAgent } from "next/server";-import { LOCALHOST_GEO_DATA } from "@/lib/constants";+import { LOCALHOST_GEO_DATA, RESERVED_KEYS } from "@/lib/constants";import { LinkProps } from "@/lib/types";import { customAlphabet } from "nanoid";import { getTitleFromUrl } from "@/lib/utils";@@ -66,6 +66,9 @@ export async function getRandomKey(hostname: string): Promise<string> {}export async function checkIfKeyExists(hostname: string, key: string) {+ if (hostname === "dub.sh" && RESERVED_KEYS.includes(key)) {+ return 1; // reserved keys for dub.sh+ }return await redis.hexists(`${hostname}:links`, key);}@@ -139,6 +142,9 @@ export async function addLink(title?: string, // if title is provided, it will be useduserId?: string // only applicable for dub.sh links) {+ if (hostname === "dub.sh" && key && RESERVED_KEYS.includes(key)) {+ return null; // reserved keys for dub.sh+ }const response = key? await setKey(hostname, key, url, title): await setRandomKey(hostname, url, title);@@ -175,6 +181,9 @@ export async function editLink(});} else {// if key is different+ if (hostname === "dub.sh" && RESERVED_KEYS.includes(newKey)) {+ return null; // reserved keys for dub.sh+ }const keyExists = await checkIfKeyExists(hostname, newKey);if (keyExists === 1) {return null; // key already existsdiff --git a/pages/api/links/[key].ts b/pages/api/links/[key].tsindex 9436198909..4365b99ebc 100644--- a/pages/api/links/[key].ts+++ b/pages/api/links/[key].ts@@ -1,6 +1,7 @@import { NextApiRequest, NextApiResponse } from "next";import { redis, editLink } from "@/lib/upstash";import { getSession } from "@/lib/auth";+import { RESERVED_KEYS } from "@/lib/constants";export default async function handler(req: NextApiRequest,diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex a034369e5b..0fffe98f3d 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -1,6 +1,7 @@import { NextApiRequest, NextApiResponse } from "next";import { getLinksForProject, addLink } from "@/lib/upstash";import { getSession } from "@/lib/auth";+import { RESERVED_KEYS } from "@/lib/constants";// This is a special route for creating custom dub.sh links.