The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added archive link feature + small tweaks to UI
Steven Teyb85d995e0bf2
diff --git a/components/app/link-card.tsx b/components/app/link-card.tsxindex 1d1866c659..b084b4ea92 100644--- a/components/app/link-card.tsx+++ b/components/app/link-card.tsx@@ -1,9 +1,10 @@import Link from "next/link";import { useRouter } from "next/router";+import { useState } from "react";import useSWR from "swr";import BlurImage from "@/components/shared/blur-image";import CopyButton from "@/components/shared/copy-button";-import { Chart, LoadingDots, QR } from "@/components/shared/icons";+import { Chart, LoadingDots, QR, ThreeDots } from "@/components/shared/icons";import Tooltip, { TooltipContent } from "@/components/shared/tooltip";import useProject from "@/lib/swr/use-project";import useUsage from "@/lib/swr/use-usage";@@ -15,7 +16,9 @@ import {nFormatter,timeAgo,} from "@/lib/utils";+import Popover from "../shared/popover";import { useAddEditLinkModal } from "./modals/add-edit-link-modal";+import { useArchiveLinkModal } from "./modals/archive-link-modal";import { useDeleteLinkModal } from "./modals/delete-link-modal";import { useLinkQRModal } from "./modals/link-qr-modal";@@ -27,8 +30,9 @@ export default function LinkCard({ props }: { props: LinkProps }) {const router = useRouter();const { slug } = router.query as { slug: string };- const { project, isOwner } = useProject();+ const { project } = useProject();const { domain } = project || {};+ const { isOwner } = useProject();const { exceededUsage } = useUsage();const { data: clicks, isValidating } = useSWR<number>(@@ -41,28 +45,31 @@ export default function LinkCard({ props }: { props: LinkProps }) {},);+ const { setShowLinkQRModal, LinkQRModal } = useLinkQRModal({+ props,+ });const { setShowAddEditLinkModal, AddEditLinkModal } = useAddEditLinkModal({props,});-- const { setShowDeleteLinkModal, DeleteLinkModal } = useDeleteLinkModal({+ const { setShowArchiveLinkModal, ArchiveLinkModal } = useArchiveLinkModal({props,});-- const { setShowLinkQRModal, LinkQRModal } = useLinkQRModal({+ const { setShowDeleteLinkModal, DeleteLinkModal } = useDeleteLinkModal({props,});+ const [openPopover, setOpenPopover] = useState(false);return (- <>+ <div className="bg-white p-4 rounded-lg shadow hover:shadow-md transition-all">+ <LinkQRModal /><AddEditLinkModal />+ <ArchiveLinkModal /><DeleteLinkModal />- <LinkQRModal />- <li className="relative flex flex-col sm:flex-row justify-between items-start sm:items-center bg-white p-4 rounded-lg shadow hover:shadow-md transition-all">+ <li className="relative flex justify-between items-center">{expiresAt && new Date() > new Date(expiresAt) ? (<div className="absolute top-0 left-0 rounded-t-lg w-full h-1.5 bg-amber-500" />) : null}- <div className="relative flex items-center space-x-4 mb-3 sm:mb-0">+ <div className="relative flex items-center space-x-4"><BlurImagesrc={`https://www.google.com/s2/favicons?sz=64&domain_url=${apexDomain}`}alt={apexDomain}@@ -107,44 +114,76 @@ export default function LinkCard({ props }: { props: LinkProps }) {</h3></div></div>- <div className="flex items-center space-x-3 w-full sm:w-auto">- <p className="text-sm hidden sm:block text-gray-500 whitespace-nowrap">++ <div className="flex items-center">+ <p className="text-sm hidden sm:block text-gray-500 whitespace-nowrap mr-3">Added {timeAgo(createdAt)}</p>- {slug && exceededUsage ? (- <Tooltip- content={- <TooltipContent- title={- isOwner- ? "You have exceeded your usage limit. We're still collecting data on your existing links, but you need to upgrade to edit them."- : "The owner of this project has exceeded their usage limit. We're still collecting data on all existing links, but they need to upgrade their plan to edit them."- }- cta={isOwner && "Upgrade"}- ctaLink={isOwner && "/settings"}- />- }- >- <div className="grow text-gray-300 cursor-not-allowed font-medium text-sm px-5 py-1.5 sm:py-2 border rounded-md border-gray-200 transition-all duration-75">- Edit+ <p className="text-sm sm:hidden text-gray-500 whitespace-nowrap mr-3">+ {timeAgo(createdAt, true)}+ </p>+ <Popover+ content={+ <div className="w-full sm:w-40 p-2 grid gap-1">+ {slug && exceededUsage ? (+ <Tooltip+ content={+ <TooltipContent+ title={+ isOwner+ ? "You have exceeded your usage limit. We're still collecting data on your existing links, but you need to upgrade to edit them."+ : "The owner of this project has exceeded their usage limit. We're still collecting data on all existing links, but they need to upgrade their plan to edit them."+ }+ cta={isOwner && "Upgrade"}+ ctaLink={isOwner && "/settings"}+ />+ }+ >+ <div className="w-full text-gray-300 cursor-not-allowed font-medium text-sm p-2 text-left transition-all duration-75">+ Edit+ </div>+ </Tooltip>+ ) : (+ <button+ onClick={() => {+ setOpenPopover(false);+ setShowAddEditLinkModal(true);+ }}+ className="w-full font-medium text-sm text-gray-500 p-2 text-left rounded-md hover:bg-gray-100 transition-all duration-75"+ >+ Edit+ </button>+ )}+ <button+ onClick={() => {+ setOpenPopover(false);+ setShowArchiveLinkModal(true);+ }}+ className="w-full font-medium text-sm text-gray-500 p-2 text-left rounded-md hover:bg-gray-100 transition-all duration-75"+ >+ Archive+ </button>+ <button+ onClick={() => {+ setOpenPopover(false);+ setShowDeleteLinkModal(true);+ }}+ className="w-full font-medium text-sm text-red-600 hover:bg-red-600 hover:text-white p-2 text-left rounded-md transition-all duration-75"+ >+ Delete+ </button></div>- </Tooltip>- ) : (- <button- onClick={() => setShowAddEditLinkModal(true)}- className="grow sm:grow-0 font-medium text-sm text-gray-500 px-5 py-1.5 sm:py-2 border rounded-md border-gray-200 hover:border-black active:scale-95 transition-all duration-75"- >- Edit- </button>- )}- <button- onClick={() => setShowDeleteLinkModal(true)}- className="grow sm:grow-0 font-medium text-sm text-white bg-red-600 hover:bg-white hover:text-red-600 border-red-600 px-5 py-1.5 sm:py-2 border rounded-md active:scale-95 transition-all duration-75"+ }+ align="end"+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}>- Delete- </button>+ <button className="rounded-md px-1 py-2 hover:bg-gray-100 active:bg-gray-200 transition-all duration-75">+ <ThreeDots className="w-5 h-5 text-gray-500" />+ </button>+ </Popover></div></li>- </>+ </div>);}diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsxindex 6348c7b41b..e3ba224620 100644--- a/components/app/modals/add-edit-link-modal/index.tsx+++ b/components/app/modals/add-edit-link-modal/index.tsx@@ -14,6 +14,7 @@ import {AlertCircleFill,LoadingCircle,LoadingDots,+ Random,} from "@/components/shared/icons";import Modal from "@/components/shared/modal";import Tooltip, { TooltipContent } from "@/components/shared/tooltip";@@ -191,10 +192,12 @@ function AddEditLinkModal({disabled={generatingSlug}type="button">- {generatingSlug && <LoadingCircle />}- <p>- {generatingSlug ? "Generating" : "Generate random slug"}- </p>+ {generatingSlug ? (+ <LoadingCircle />+ ) : (+ <Random className="w-3 h-3" />+ )}+ <p>{generatingSlug ? "Generating" : "Randomize"}</p></button></div><div className="relative flex mt-1 rounded-md shadow-sm">diff --git a/components/app/modals/archive-link-modal.tsx b/components/app/modals/archive-link-modal.tsxnew file mode 100644index 0000000000..0c973037a5--- /dev/null+++ b/components/app/modals/archive-link-modal.tsx@@ -0,0 +1,127 @@+import { useRouter } from "next/router";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";+import { mutate } from "swr";+import BlurImage from "@/components/shared/blur-image";+import LoadingDots from "@/components/shared/icons/loading-dots";+import Modal from "@/components/shared/modal";+import useProject from "@/lib/swr/use-project";+import { LinkProps } from "@/lib/types";+import { getApexDomain, linkConstructor } from "@/lib/utils";++function ArchiveLinkModal({+ showArchiveLinkModal,+ setShowArchiveLinkModal,+ props,+}: {+ showArchiveLinkModal: boolean;+ setShowArchiveLinkModal: Dispatch<SetStateAction<boolean>>;+ props: LinkProps;+}) {+ const router = useRouter();+ const { slug } = router.query;+ const [deleting, setDeleting] = useState(false);+ const { project: { domain } = {} } = useProject();+ const apexDomain = getApexDomain(props.url);++ const shortlink = useMemo(() => {+ return linkConstructor({+ key: props.key,+ domain,+ pretty: true,+ });+ }, [props, domain]);++ return (+ <Modal+ showModal={showArchiveLinkModal}+ setShowModal={setShowArchiveLinkModal}+ >+ <div className="inline-block w-full sm:max-w-md overflow-hidden align-middle transition-all transform bg-white sm:border sm:border-gray-200 shadow-xl sm:rounded-2xl">+ <div className="flex flex-col justify-center items-center space-y-3 sm:px-16 px-4 pt-8 py-4 border-b border-gray-200">+ <BlurImage+ src={`https://www.google.com/s2/favicons?sz=64&domain_url=${apexDomain}`}+ alt={apexDomain}+ className="w-10 h-10 rounded-full"+ width={20}+ height={20}+ />+ <h3 className="font-medium text-lg">Archive {shortlink}</h3>+ <p className="text-sm text-gray-500 text-center">+ Archived links will still work - they just won't show up on your+ main dashboard.+ </p>+ </div>++ <div className="flex flex-col space-y-6 text-left bg-gray-50 sm:px-16 px-4 py-8">+ <button+ onClick={async (e) => {+ e.preventDefault();+ setDeleting(true);+ fetch(+ domain+ ? `/api/projects/${slug}/domains/${domain}/links/${props.key}/archive`+ : `/api/links/${props.key}/archive`,+ {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ },+ ).then(async (res) => {+ setDeleting(false);+ if (res.status === 200) {+ mutate(+ domain+ ? `/api/projects/${slug}/domains/${domain}/links`+ : `/api/links`,+ );+ setShowArchiveLinkModal(false);+ }+ });+ }}+ disabled={deleting}+ className={`${+ deleting+ ? "cursor-not-allowed bg-gray-100 border-gray-200 text-gray-400"+ : "bg-black hover:bg-white hover:text-black border-black text-white"+ } flex justify-center items-center w-full text-sm h-10 rounded-md border transition-all focus:outline-none`}+ >+ {deleting ? (+ <LoadingDots color="#808080" />+ ) : (+ <p>Confirm archive</p>+ )}+ </button>+ </div>+ </div>+ </Modal>+ );+}++export function useArchiveLinkModal({ props }: { props?: LinkProps }) {+ const [showArchiveLinkModal, setShowArchiveLinkModal] = useState(false);++ const ArchiveLinkModalCallback = useCallback(() => {+ return props ? (+ <ArchiveLinkModal+ showArchiveLinkModal={showArchiveLinkModal}+ setShowArchiveLinkModal={setShowArchiveLinkModal}+ props={props}+ />+ ) : null;+ }, [showArchiveLinkModal, setShowArchiveLinkModal]);++ return useMemo(+ () => ({+ setShowArchiveLinkModal,+ ArchiveLinkModal: ArchiveLinkModalCallback,+ }),+ [setShowArchiveLinkModal, ArchiveLinkModalCallback],+ );+}diff --git a/components/app/modals/delete-link-modal.tsx b/components/app/modals/delete-link-modal.tsxindex 4b83153475..412e6b2275 100644--- a/components/app/modals/delete-link-modal.tsx+++ b/components/app/modals/delete-link-modal.tsx@@ -52,7 +52,7 @@ function DeleteLinkModal({height={20}/><h3 className="font-medium text-lg">Delete {shortlink}</h3>- <p className="text-sm text-gray-500">+ <p className="text-sm text-gray-500 text-center">Warning: Deleting this link will remove all of its stats. Thisaction cannot be undone.</p>diff --git a/components/app/modals/delete-project-modal.tsx b/components/app/modals/delete-project-modal.tsxindex 64138a5e71..81f29e4153 100644--- a/components/app/modals/delete-project-modal.tsx+++ b/components/app/modals/delete-project-modal.tsx@@ -40,7 +40,7 @@ function DeleteProjectModal({height={20}/><h3 className="font-medium text-lg">Delete Project</h3>- <p className="text-sm text-gray-500">+ <p className="text-sm text-gray-500 text-center">Warning: This will permanently delete your project, custom domain,and all associated links + their stats.</p>diff --git a/components/app/modals/edit-domain-modal.tsx b/components/app/modals/edit-domain-modal.tsxindex 1ddf741f3d..4de1fd0f41 100644--- a/components/app/modals/edit-domain-modal.tsx+++ b/components/app/modals/edit-domain-modal.tsx@@ -59,7 +59,7 @@ function EditDomainModal({height={20}/><h3 className="font-medium text-lg">Change Domain</h3>- <p className="text-sm text-gray-500">+ <p className="text-sm text-gray-500 text-center">Warning: Changing your project's domain will break all existingshort links.</p>diff --git a/components/layout/app/nav-tabs.tsx b/components/layout/app/nav-tabs.tsxindex 51e1eb4c63..26deda170b 100644--- a/components/layout/app/nav-tabs.tsx+++ b/components/layout/app/nav-tabs.tsx@@ -43,7 +43,7 @@ export default function NavTabs() {: "border-transparent text-gray-600 hover:text-black"}`}>- <div className="rounded-md px-3 py-2 hover:bg-gray-100 active:bg-gray-200 transition-all">+ <div className="rounded-md px-3 py-2 hover:bg-gray-100 active:bg-gray-200 transition-all duration-75"><p className="text-sm">{name}</p></div></a>diff --git a/components/layout/app/project-select.tsx b/components/layout/app/project-select.tsxindex 970f63d96e..e11e4953a1 100644--- a/components/layout/app/project-select.tsx+++ b/components/layout/app/project-select.tsx@@ -1,5 +1,5 @@import { useRouter } from "next/router";-import { useMemo } from "react";+import { useMemo, useState } from "react";import { useSession } from "next-auth/react";import useSWR from "swr";import { useAddProjectModal } from "@/components/app/modals/add-project-modal";@@ -31,6 +31,7 @@ export default function ProjectSelect() {});}, [router, projects, session]);+ const [openPopover, setOpenPopover] = useState(false);if (!projects || !router.isReady)return (@@ -50,6 +51,8 @@ export default function ProjectSelect() {setShowAddProjectModal={setShowAddProjectModal}/>}+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}><div className="relative cursor-pointer w-60 rounded-lg bg-white hover:bg-gray-100 active:bg-gray-200 py-1.5 pl-3 pr-10 text-left focus:outline-none text-sm transition-all duration-75"><div className="flex justify-start items-center space-x-3">@@ -101,7 +104,7 @@ function ProjectList({{projects.map(({ name, slug, domain, logo }) => (<buttonkey={slug}- className={`relative flex items-center space-x-2 p-2 rounded-md w-full hover:bg-gray-100 ${+ className={`relative flex items-center space-x-2 p-2 rounded-md w-full hover:bg-gray-100 active:bg-gray-200 ${selected.slug === slug ? "font-medium" : ""} transition-all duration-75`}onClick={() => router.push(`/${slug}`)}diff --git a/components/layout/app/user-dropdown.tsx b/components/layout/app/user-dropdown.tsxindex 36fb138877..244b4d8e1d 100644--- a/components/layout/app/user-dropdown.tsx+++ b/components/layout/app/user-dropdown.tsx@@ -1,16 +1,18 @@-import { Fragment } from "react";+import { useState } from "react";import { signOut, useSession } from "next-auth/react";import Popover from "@/components/shared/popover";export default function UserDropdown() {const { data: session } = useSession();+ const [openPopover, setOpenPopover] = useState(false);+return (<div className="relative inline-block text-left"><Popovercontent={<div className="p-1 w-full sm:w-56 rounded-md bg-white"><button- className="relative p-2 rounded-md w-full hover:bg-gray-100 transition-all duration-75"+ className="relative p-2 rounded-md w-full hover:bg-gray-100 transition-all duration-75 text-sm text-left"onClick={() => signOut()}>Logout@@ -18,6 +20,8 @@ export default function UserDropdown() {</div>}align="end"+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}><div className="rounded-full overflow-hidden border border-gray-300 w-10 h-10 flex justify-center items-center active:scale-95 focus:outline-none transition-all duration-75">{session && (diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsxindex b93674aea2..1081c00c7c 100644--- a/components/shared/icons/index.tsx+++ b/components/shared/icons/index.tsx@@ -30,3 +30,5 @@ export { default as Lock } from "./lock";export { default as QR } from "./qr";export { default as Download } from "./download";export { default as Calendar } from "./calendar";+export { default as ThreeDots } from "./three-dots";+export { default as Random } from "./random";diff --git a/components/shared/icons/random.tsx b/components/shared/icons/random.tsxnew file mode 100644index 0000000000..b7b83fedf4--- /dev/null+++ b/components/shared/icons/random.tsx@@ -0,0 +1,18 @@+export default function Random({ className }: { className?: string }) {+ return (+ <svg+ className={className}+ viewBox="0 0 24 24"+ width="24"+ height="24"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ fill="none"+ shapeRendering="geometricPrecision"+ >+ <path d="M21.67 3.955l-2.825-2.202.665-.753 4.478 3.497-4.474 3.503-.665-.753 2.942-2.292h-4.162c-3.547.043-5.202 3.405-6.913 7.023 1.711 3.617 3.366 6.979 6.913 7.022h4.099l-2.883-2.247.665-.753 4.478 3.497-4.474 3.503-.665-.753 2.884-2.247h-4.11c-3.896-.048-5.784-3.369-7.461-6.858-1.687 3.51-3.592 6.842-7.539 6.858h-2.623v-1h2.621c3.6-.014 5.268-3.387 6.988-7.022-1.72-3.636-3.388-7.009-6.988-7.023h-2.621v-1h2.623c3.947.016 5.852 3.348 7.539 6.858 1.677-3.489 3.565-6.81 7.461-6.858h4.047z" />+ </svg>+ );+}diff --git a/components/shared/icons/three-dots.tsx b/components/shared/icons/three-dots.tsxnew file mode 100644index 0000000000..d885852e55--- /dev/null+++ b/components/shared/icons/three-dots.tsx@@ -0,0 +1,20 @@+export default function ThreeDots({ className }: { className: string }) {+ return (+ <svg+ fill="none"+ shapeRendering="geometricPrecision"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ viewBox="0 0 24 24"+ width="14"+ height="14"+ className={className}+ >+ <circle cx="12" cy="12" r="1"></circle>+ <circle cx="12" cy="5" r="1"></circle>+ <circle cx="12" cy="19" r="1"></circle>+ </svg>+ );+}diff --git a/components/shared/popover.tsx b/components/shared/popover.tsxindex 06ec1974cc..5f3ab585c7 100644--- a/components/shared/popover.tsx+++ b/components/shared/popover.tsx@@ -8,12 +8,15 @@ export default function Popover({children,content,align = "center",+ openPopover,+ setOpenPopover,}: {children: ReactNode;content: ReactNode | string;align?: "center" | "start" | "end";+ openPopover;+ setOpenPopover;}) {- const [openPopover, setOpenPopover] = useState(false);const router = useRouter();const mobileTooltipRef = useRef(null);@@ -74,13 +77,7 @@ export default function Popover({<div className="rounded-full h-1 w-6 bg-gray-300 group-active:-rotate-12 transition-all" /></div><div className="flex items-center justify-center w-full overflow-hidden align-middle bg-white shadow-xl min-h-[150px]">- {typeof content === "string" ? (- <span className="block text-sm text-center text-gray-700 max-w-xs">- {content}- </span>- ) : (- content- )}+ {content}</div></motion.div><motion.div@@ -106,20 +103,11 @@ export default function Popover({</PopoverPrimitive.Trigger><PopoverPrimitive.ContentsideOffset={4}- side="top"align={align}className="hidden sm:block animate-slide-up-fade items-center rounded-md overflow-hidden z-20 bg-white border border-gray-200 drop-shadow-lg"><PopoverPrimitive.Arrow className="fill-current text-white" />- {typeof content === "string" ? (- <div className="p-5">- <span className="block text-sm text-center text-gray-700 max-w-xs">- {content}- </span>- </div>- ) : (- content- )}+ {content}<PopoverPrimitive.Arrow className="fill-current text-white" /></PopoverPrimitive.Content></PopoverPrimitive.Root>diff --git a/lib/api/links.ts b/lib/api/links.tsindex 3d8bbee688..044da12db4 100644--- a/lib/api/links.ts+++ b/lib/api/links.ts@@ -233,3 +233,17 @@ export async function deleteLink(domain: string, key: string) {redis.del(`${domain}:clicks:${key}`),]);}++export async function archiveLink(domain: string, key: string) {+ return await prisma.link.update({+ where: {+ domain_key: {+ domain,+ key,+ },+ },+ data: {+ archived: true,+ },+ });+}diff --git a/lib/utils.ts b/lib/utils.tsindex f68bc5c704..0e042615aa 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -108,9 +108,11 @@ export const getDescriptionFromUrl = async (url: string) => {return description;};-export const timeAgo = (timestamp: Date): string => {+export const timeAgo = (timestamp: Date, timeOnly?: boolean): string => {if (!timestamp) return "never";- return `${ms(Date.now() - new Date(timestamp).getTime())} ago`;+ return `${ms(Date.now() - new Date(timestamp).getTime())}${+ timeOnly ? "" : " ago"+ }`;};export const getDateTimeLocal = (timestamp?: Date): string => {diff --git a/pages/api/links/[key]/archive.ts b/pages/api/links/[key]/archive.tsnew file mode 100644index 0000000000..191a349c28--- /dev/null+++ b/pages/api/links/[key]/archive.ts@@ -0,0 +1,37 @@+import { NextApiRequest, NextApiResponse } from "next";+import { archiveLink } from "@/lib/api/links";+import { withUserAuth } from "@/lib/auth";+import prisma from "@/lib/prisma";++const domain = "dub.sh";++export default withUserAuth(+ async (req: NextApiRequest, res: NextApiResponse, userId: string) => {+ const { key } = req.query as { key: string };++ const isOwner = await prisma.link+ .findUnique({+ where: {+ domain_key: {+ domain,+ key,+ },+ },+ })+ .then((link) => link?.userId === userId);++ if (!isOwner) {+ return res.status(403).json({ error: "Not authorized" });+ }++ if (req.method === "PUT") {+ const response = await archiveLink(domain, key);+ return res.status(200).json(response);+ } else {+ res.setHeader("Allow", ["PUT"]);+ return res+ .status(405)+ .json({ error: `Method ${req.method} Not Allowed` });+ }+ },+);diff --git a/pages/api/links/[key]/index.ts b/pages/api/links/[key]/index.tsindex 33daf363e0..04416fa215 100644--- a/pages/api/links/[key]/index.ts+++ b/pages/api/links/[key]/index.ts@@ -48,7 +48,7 @@ export default withUserAuth(const response = await deleteLink(domain, oldKey);return res.status(200).json(response);} else {- res.setHeader("Allow", ["GET", "POST", "DELETE"]);+ res.setHeader("Allow", ["PUT", "DELETE"]);return res.status(405).json({ error: `Method ${req.method} Not Allowed` });diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/archive.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/archive.tsnew file mode 100644index 0000000000..9077c26070--- /dev/null+++ b/pages/api/projects/[slug]/domains/[domain]/links/[key]/archive.ts@@ -0,0 +1,25 @@+import { NextApiRequest, NextApiResponse } from "next";+import { archiveLink } from "@/lib/api/links";+import { withProjectAuth } from "@/lib/auth";++export default withProjectAuth(+ async (req: NextApiRequest, res: NextApiResponse, _, session) => {+ const { domain, key } = req.query as {+ domain: string;+ key: string;+ };++ if (req.method === "PUT") {+ const response = await archiveLink(domain, key);+ return res.status(200).json(response);+ } else {+ res.setHeader("Allow", ["PUT"]);+ return res+ .status(405)+ .json({ error: `Method ${req.method} Not Allowed` });+ }+ },+ {+ needVerifiedDomain: true,+ },+);diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.tsindex 5ccdb14f2a..4b4e9719b9 100644--- a/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.ts+++ b/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.ts@@ -39,7 +39,7 @@ export default withProjectAuth(const response = await deleteLink(domain, oldKey);return res.status(200).json(response);} else {- res.setHeader("Allow", ["POST", "DELETE"]);+ res.setHeader("Allow", ["PUT", "DELETE"]);return res.status(405).json({ error: `Method ${req.method} Not Allowed` });