The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
backwards compatibility
Steven Tey065ceeda5f9e
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex 58eb1d0e9b..3d1438486d 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -2,6 +2,7 @@ import { DubApiError, ErrorCodes } from "@/lib/api/errors";import { deleteLink, editLink, processLink } from "@/lib/api/links";import { withAuth } from "@/lib/auth";import { qstash } from "@/lib/cron";+import prisma from "@/lib/prisma";import { LinkWithTagIdsProps } from "@/lib/types";import { updateLinkBodySchema } from "@/lib/zod/schemas/links";import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";@@ -9,10 +10,38 @@ import { NextResponse } from "next/server";// GET /api/links/[linkId] – get a linkexport const GET = withAuth(async ({ headers, link }) => {- // link is guaranteed to exist because if not we will return 404- return NextResponse.json(link!, {- headers,+ if (!link) {+ throw new DubApiError({+ code: "not_found",+ message: "Link not found.",+ });+ }++ const tags = await prisma.tag.findMany({+ where: {+ linksNew: {+ some: {+ linkId: link.id,+ },+ },+ },+ select: {+ id: true,+ name: true,+ color: true,+ },});+ // link is guaranteed to exist because if not we will return 404+ return NextResponse.json(+ {+ ...link,+ tagId: tags?.[0]?.id ?? null, // backwards compatibility+ tags,+ },+ {+ headers,+ },+ );});// PUT /api/links/[linkId] – update a linkdiff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 182e4477ab..0592c05067 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -849,9 +849,6 @@ export async function deleteLink(link: LinkProps) {id: link.id,},}),- cloudinary.v2.uploader.destroy(`${link.domain}/${link.key}`, {- invalidate: true,- }),redis.hdel(link.domain, link.key.toLowerCase()),recordLink({ link, deleted: true }),link.projectId &&@@ -865,6 +862,11 @@ export async function deleteLink(link: LinkProps) {},},}),+ link.proxy &&+ link.image &&+ cloudinary.v2.uploader.destroy(`${link.domain}/${link.key}`, {+ invalidate: true,+ }),]);}