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 ability to set expired URL on project & link level

Steven Teyd8ee2c8baa53
diff --git a/apps/web/app/expired/page.tsx b/apps/web/app/expired/[workspaceId]/page.tsx
similarity index 79%
rename from apps/web/app/expired/page.tsx
rename to apps/web/app/expired/[workspaceId]/page.tsx
index 12c39e862a..05780a90f8 100644
--- a/apps/web/app/expired/page.tsx
+++ b/apps/web/app/expired/[workspaceId]/page.tsx
@@ -1,6 +1,8 @@
+import { getWorkspaceViaEdge } from "@/lib/planetscale";
import { Background, Footer, Nav } from "@dub/ui";
import { constructMetadata } from "@dub/utils";
import { TimerOff } from "lucide-react";
+import { redirect } from "next/navigation";
export const runtime = "edge";
@@ -11,7 +13,17 @@ export const metadata = constructMetadata({
noIndex: true,
});
-export default async function ExpiredPage() {
+export default async function ExpiredPage({
+ params,
+}: {
+ params: { workspaceId: string };
+}) {
+ const workspace = await getWorkspaceViaEdge(params.workspaceId);
+
+ if (workspace?.slug === "acme") {
+ redirect("https://dub.co");
+ }
+
return (
<main className="flex min-h-screen flex-col justify-between">
<Nav />
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index fb555e25d6..037732e66c 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -84,6 +84,7 @@ export default async function LinkMiddleware(
ios,
android,
geo,
+ expiredUrl,
} = link;
// only show inspect modal if the link is not password protected
@@ -120,7 +121,14 @@ export default async function LinkMiddleware(
// if the link has expired
if (expiresAt && new Date(expiresAt) < new Date()) {
- return NextResponse.rewrite(new URL("/expired", req.url), DUB_HEADERS);
+ if (expiredUrl) {
+ return NextResponse.redirect(expiredUrl, DUB_HEADERS);
+ } else {
+ return NextResponse.rewrite(
+ new URL(`/expired/${link.projectId}`, req.url),
+ DUB_HEADERS,
+ );
+ }
}
const searchParams = req.nextUrl.searchParams;
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index c365455eff..f1eb32b6c2 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -33,6 +33,7 @@ export interface RedisLinkProps {
rewrite?: boolean;
iframeable?: boolean;
expiresAt?: Date;
+ expiredUrl?: string;
ios?: string;
android?: string;
geo?: object;
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 9399205326..3cd3efa5fa 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -93,11 +93,14 @@ model Project {
billingCycleStart Int // day of the month when the billing cycle starts
usage Int @default(0)
usageLimit Int @default(1000)
+ aiUsage Int @default(0)
+ aiLimit Int @default(10)
linksUsage Int @default(0)
linksLimit Int @default(25)
domainsLimit Int @default(3)
tagsLimit Int @default(5)
usersLimit Int @default(1)
+ expiredUrl String? @db.LongText // URL to redirect to for expired links
monitoringId String? @unique // cron job ID for monitoring
users ProjectUsers[]
@@ -194,13 +197,14 @@ model Domain {
}
model Link {
- id String @id @default(cuid())
- domain String // domain of the link (e.g. dub.sh) – also stored on Redis
- key String // key of the link (e.g. /github) – also stored on Redis
- url String @db.LongText // target url (e.g. https://github.com/dubinc/dub) – also stored on Redis
- archived Boolean @default(false) // whether the link is archived or not
- expiresAt DateTime? // when the link expires – stored on Redis via ttl
- password String? // password to access the link
+ id String @id @default(cuid())
+ domain String // domain of the link (e.g. dub.sh) – also stored on Redis
+ key String // key of the link (e.g. /github) – also stored on Redis
+ url String @db.LongText // target url (e.g. https://github.com/dubinc/dub) – also stored on Redis
+ archived Boolean @default(false) // whether the link is archived or not
+ expiresAt DateTime? // when the link expires – stored on Redis via ttl
+ expiredUrl String? @db.LongText // URL to redirect the user to when the link is expired
+ password String? // password to access the link
proxy Boolean @default(false) // Proxy to use custom OG tags (stored on redis) – if false, will use OG tags from target url
title String? // OG title for the link (e.g. Dub.co - Open-Source Link Management Infrastructure)