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.

remove expiration date limit

Steven Teyb5b7da7678ab
diff --git a/apps/docs/api-reference/endpoint/bulk-create-links.mdx b/apps/docs/api-reference/endpoint/bulk-create-links.mdx
index 977a0bca10..c0ddaf0252 100644
--- a/apps/docs/api-reference/endpoint/bulk-create-links.mdx
+++ b/apps/docs/api-reference/endpoint/bulk-create-links.mdx
@@ -11,8 +11,7 @@ description: Bulk create up to 100 links for the authenticated project.
<Warning>
Bulk link creation does not support the following features: [Link
cloaking](https://dub.co/help/article/how-to-create-link#link-cloaking),
- [Custom social media cards](https://dub.co/help/article/how-to-create-link#custom-social-media-cards),
- [Expiration date](https://dub.co/help/article/how-to-create-link#expiration-date)
+ [Custom social media cards](https://dub.co/help/article/how-to-create-link#custom-social-media-cards)
</Warning>
<RequestExample>
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 1e168719bc..92526752a5 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -7,7 +7,6 @@ import {
import prisma from "@/lib/prisma";
import { redis } from "@/lib/upstash";
import {
- APP_DOMAIN_WITH_NGROK,
DEFAULT_REDIRECTS,
DUB_DOMAINS,
DUB_PROJECT_ID,
@@ -25,7 +24,6 @@ import cloudinary from "cloudinary";
import { isIframeable } from "../middleware/utils";
import { LinkProps, ProjectProps, SimpleLinkProps } from "../types";
import { Session } from "../auth";
-import { qstash } from "../cron";
export async function getLinksForProject({
projectId,
@@ -262,8 +260,8 @@ export async function processLink({
}
// expire date checks
- if (payload.expiresAt) {
- const date = new Date(payload.expiresAt);
+ if (expiresAt) {
+ const date = new Date(expiresAt);
if (isNaN(date.getTime())) {
return {
link: payload,
@@ -272,21 +270,13 @@ export async function processLink({
};
}
// check if expiresAt is in the future
- if (new Date(payload.expiresAt) < new Date()) {
+ if (new Date(expiresAt) < new Date()) {
return {
link: payload,
error: "Expiry date must be in the future.",
status: 422,
};
}
- // check if expiresAt is more than 30 days in the future
- if (new Date(payload.expiresAt) > new Date(Date.now() + 2592000000)) {
- return {
- link: payload,
- error: "Expiry date cannot be more than 30 days in the future.",
- status: 422,
- };
- }
}
if (project) {
@@ -400,13 +390,6 @@ export async function processLink({
status: 422,
};
}
- if (expiresAt) {
- return {
- link: payload,
- error: "You cannot set expiry dates with bulk link creation.",
- status: 422,
- };
- }
const exists = await checkIfKeyExists(domain, key);
if (exists) {
return {
@@ -486,7 +469,7 @@ export async function addLink(link: LinkProps) {
rewrite: true,
iframeable: await isIframeable({ url, requestDomain: domain }),
}),
- expired: expiresAt && new Date(expiresAt) < new Date(),
+ ...(expiresAt && { expiresAt }),
...(ios && { ios }),
...(android && { android }),
...(geo && { geo }),
@@ -513,30 +496,20 @@ export async function addLink(link: LinkProps) {
},
});
}
-
- // if link expires, schedule a job to expire it
- 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()) / 1000,
- body: {
- linkId: response.id,
- },
- });
- }
return response;
}
export async function bulkCreateLinks(links: LinkProps[]) {
if (links.length === 0) return [];
const pipeline = redis.pipeline();
- links.forEach(({ domain, key, url, password }) => {
+ links.forEach(({ domain, key, url, password, expiresAt }) => {
const hasPassword = password && password.length > 0 ? true : false;
pipeline.set(
`${domain}:${key}`,
{
url: encodeURIComponent(url),
password: hasPassword,
+ ...(expiresAt && { expiresAt }),
},
{
nx: true,
@@ -663,23 +636,11 @@ export async function editLink({
rewrite: true,
iframeable: await isIframeable({ url, requestDomain: domain }),
}),
- expired: expiresAt && new Date(expiresAt) < new Date(),
+ ...(expiresAt && { expiresAt }),
...(ios && { ios }),
...(android && { android }),
...(geo && { geo }),
}),
- ...(expiresAt && new Date(expiresAt) > new Date()
- ? [
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/callback/expire`,
- delay:
- (new Date(expiresAt).getTime() - new Date().getTime()) / 1000,
- body: {
- linkId: id,
- },
- }),
- ]
- : []),
// if key is changed: rename resource in Cloudinary, delete the old key in Redis and change the clicks key name
...(changedDomain || changedKey
? [
diff --git a/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsx b/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsx
index a74ba4636c..894f0dbc2e 100644
--- a/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/expiration-section.tsx
@@ -56,9 +56,6 @@ export default function ExpirationSection({
id="expiresAt"
name="expiresAt"
min={getDateTimeLocal()}
- max={getDateTimeLocal(
- new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
- )}
value={expiresAt ? getDateTimeLocal(expiresAt) : ""}
step="60" // need to add step to prevent weird date bug (https://stackoverflow.com/q/19284193/10639526)
onChange={(e) => {