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.

Merge branch 'main' into well-known

Steven Tey09ff09c52fa3
diff --cc apps/web/app/api/domains/[domain]/route.ts
index 57e842e08d,064294a7dc..837f8f3a1a
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@@ -15,7 -14,8 +14,9 @@@ import
DomainSchema,
updateDomainBodySchema,
} from "@/lib/zod/schemas/domains";
- import { Prisma } from "@prisma/client";
+ import { prisma } from "@dub/prisma";
++import { Prisma } from "@dub/prisma/client";
+ import { combineWords, nanoid, R2_URL } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
@@@ -39,9 -39,10 +40,11 @@@ export const GET = withWorkspace
export const PATCH = withWorkspace(
async ({ req, workspace, params }) => {
const {
++ id: domainId,
slug: domain,
registeredDomain,
- id: domainId,
+ logo: oldLogo,
+ deepLink: existingDeepLink,
} = await getDomainOrThrow({
workspace,
domain: params.domain,
@@@ -53,16 -54,25 +56,26 @@@
placeholder,
expiredUrl,
notFoundUrl,
- archived,
+ logo,
+ archived,
+ deepLink,
} = updateDomainBodySchema.parse(await parseRequestBody(req));
- if (workspace.plan === "free" && expiredUrl) {
- throw new DubApiError({
- code: "forbidden",
- message:
- "You can only use Default Expiration URLs on a Pro plan and above. Upgrade to Pro to use these features.",
- });
+ if (workspace.plan === "free") {
+ if (logo || expiredUrl || notFoundUrl) {
+ const proFeaturesString = combineWords(
+ [
+ logo && "custom QR code logos",
+ expiredUrl && "default expiration URLs",
+ notFoundUrl && "not found URLs",
+ ].filter(Boolean) as string[],
+ );
+
+ throw new DubApiError({
+ code: "forbidden",
+ message: `You can only set ${proFeaturesString} on a Pro plan and above. Upgrade to Pro to use these features.`,
+ });
+ }
}
const domainUpdated =
@@@ -90,19 -113,12 +116,18 @@@
slug: domain,
},
data: {
+ ...(domainUpdated && { slug: newDomain }),
archived,
- ...(domainUpdated && !registeredDomain && { slug: newDomain }),
- ...(placeholder && { placeholder }),
- ...(workspace.plan != "free" && {
- expiredUrl,
- notFoundUrl,
- }),
+ placeholder,
+ expiredUrl,
+ notFoundUrl,
+ logo: deleteLogo ? null : logoUploaded?.url || oldLogo,
+ ...(deepLink && {
+ deepLink: {
+ ...(existingDeepLink as Prisma.JsonObject),
+ ...deepLink,
+ },
+ }),
},
include: {
registeredDomain: true,
diff --cc apps/web/app/api/domains/route.ts
index f9d7a3d68e,18df9f0575..bcfa27f839
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@@ -77,7 -78,7 +78,7 @@@ export const GET = withWorkspace
export const POST = withWorkspace(
async ({ req, workspace, session }) => {
const body = await parseRequestBody(req);
- const { slug, placeholder, expiredUrl, notFoundUrl, deepLink } =
- const { slug, logo, expiredUrl, notFoundUrl, placeholder } =
++ const { slug, logo, expiredUrl, notFoundUrl, placeholder, deepLink } =
createDomainBodySchema.parse(body);
const totalDomains = await prisma.domain.count({
@@@ -130,12 -147,10 +147,10 @@@
projectId: workspace.id,
primary: totalDomains === 0,
...(placeholder && { placeholder }),
- ...(workspace.plan !== "free" && {
- expiredUrl,
- notFoundUrl,
- }),
+ expiredUrl,
+ notFoundUrl,
+ ...(logoUploaded && { logo: logoUploaded.url }),
- },
+ ...(deepLink && { deepLink }),
- },
}),
createLink({
diff --cc apps/web/lib/zod/schemas/domains.ts
index 07acb06fc8,d48ff542a3..7f8732ef55
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@@ -126,7 -123,12 +130,13 @@@ export const createDomainBodySchema = z
"Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened.",
)
.openapi({ example: "https://dub.co/help/article/what-is-dub" }),
+ logo: z
+ .string()
+ .trim()
+ .nullish()
+ .transform((v) => v || null)
+ .describe("The logo of the domain."),
+ deepLink: deepLink.nullish().describe("Deep link configuration."),
});
export const updateDomainBodySchema = createDomainBodySchema.partial();
diff --cc packages/prisma/schema/domain.prisma
index f624ac48be,ce428b8fa2..dc325914d6
--- a/packages/prisma/schema/domain.prisma
+++ b/packages/prisma/schema/domain.prisma
@@@ -8,7 -8,7 +8,8 @@@ model Domain
primary Boolean @default(false)
archived Boolean @default(false)
lastChecked DateTime @default(now())
+ logo String?
+ deepLink Json?
links Link[]
project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
projectId String?