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.

fix timing complexities

Steven Teyb064be28d39f
diff --git a/apps/web/app/api/callback/expire/route.ts b/apps/web/app/api/callback/expire/route.ts
index d599832550..302c80c297 100644
--- a/apps/web/app/api/callback/expire/route.ts
+++ b/apps/web/app/api/callback/expire/route.ts
@@ -19,8 +19,6 @@ export async function POST(req: Request) {
return new Response("Missing link ID", { status: 200 });
}
- console.log({ linkId });
-
const link = await prisma.link.findUnique({
where: {
id: linkId,
@@ -36,8 +34,11 @@ export async function POST(req: Request) {
return new Response("Link not found", { status: 200 });
}
- if (!link.expiresAt || link.expiresAt < new Date()) {
- return new Response("Link already expired", { status: 200 });
+ if (!link.expiresAt || link.expiresAt > new Date()) {
+ return new Response(
+ "Link is not expired or does not have an expiration date",
+ { status: 200 },
+ );
}
const { domain, key } = link;
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 9348bd9453..a8f6ed1039 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -509,7 +509,7 @@ export async function addLink(link: LinkProps) {
if (expiresAt && new Date(expiresAt) > new Date()) {
await qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/callback/expire`,
- delay: new Date(expiresAt).getTime() - new Date().getTime(),
+ delay: (new Date(expiresAt).getTime() - new Date().getTime()) / 1000,
body: {
linkId: response.id,
},
@@ -663,7 +663,8 @@ export async function editLink({
? [
qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/callback/expire`,
- delay: new Date(expiresAt).getTime() - new Date().getTime(),
+ delay:
+ (new Date(expiresAt).getTime() - new Date().getTime()) / 1000,
body: {
linkId: id,
},