Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add the workspaceId,tags, qrCode to link info response

Kiran K5191e6421279
diff --git a/apps/web/app/api/links/info/route.ts b/apps/web/app/api/links/info/route.ts
index 38d49be062..ec257f347d 100644
--- a/apps/web/app/api/links/info/route.ts
+++ b/apps/web/app/api/links/info/route.ts
@@ -5,11 +5,15 @@ import { getLinkInfoQuerySchema } from "@/lib/zod/schemas/links";
import { linkConstructor } from "@dub/utils";
import { NextResponse } from "next/server";
+// TODO:
+// Move the link transform logic to a shared function.
+// It has been duplicated in multiple places.
+
// GET /api/links/info – get the info for a link
export const GET = withAuth(async ({ headers, searchParams }) => {
const { domain, key } = getLinkInfoQuerySchema.parse(searchParams);
- const response = await prisma.link.findUnique({
+ const link = await prisma.link.findUnique({
where: {
domain_key: {
domain,
@@ -21,20 +25,41 @@ export const GET = withAuth(async ({ headers, searchParams }) => {
},
});
- if (!response) {
+ 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,
+ },
+ });
+
+ const shortLink = linkConstructor({
+ domain: link.domain,
+ key: link.key,
+ });
+
return NextResponse.json(
{
- ...response,
- shortLink: linkConstructor({
- domain: response.domain,
- key: response.key,
- }),
+ ...link,
+ workspaceId: `ws_${link.projectId}`,
+ tagId: tags?.[0]?.id ?? null, // backwards compatibility
+ tags,
+ qrCode: `https://api.dub.co/qr?url=${shortLink}`,
+ shortLink,
},
{
headers,