The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
limit expiresAt to 30 days in the future
Steven Teyafc9056645fa
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex a8f6ed1039..57ce409e4b 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -278,6 +278,14 @@ export async function processLink({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) {diff --git a/apps/web/scripts/sync-expired-links.ts b/apps/web/scripts/sync-expired-links.tsnew file mode 100644index 0000000000..5570a45eb5--- /dev/null+++ b/apps/web/scripts/sync-expired-links.ts@@ -0,0 +1,59 @@+import "dotenv-flow/config";+import prisma from "@/lib/prisma";+import { redis } from "./utils";+import { qstash } from "@/lib/cron";++const anchor = 2250;++async function main() {+ const expiredLinks = await prisma.link.findMany({+ where: {+ expiresAt: {+ gt: new Date("2023-12-20T02:10:00.000Z"),+ },+ },+ select: {+ id: true,+ domain: true,+ key: true,+ expiresAt: true,+ },+ orderBy: {+ expiresAt: "asc",+ },+ skip: anchor,+ });++ const pipeline = redis.pipeline();+ // redisLinks.forEach((link, idx) => {+ // const { domain, key } = expiredLinks[idx];+ // console.log({ domain, key });+ // pipeline.set(`${domain}:${key}`, {+ // ...link,+ // expired: true,+ // });+ // });++ // await Promise.all(+ // expiredLinks.map((link) => {+ // const { domain, key } = link;+ // pipeline.persist(`${domain}:${key}`);+ // qstash.publishJSON({+ // url: "https://app.dub.co/api/callback/expire",+ // delay:+ // (new Date(link.expiresAt!).getTime() - new Date().getTime()) / 1000,+ // body: {+ // linkId: link.id,+ // },+ // });+ // }),+ // );++ // await pipeline.exec();++ console.log(`Synced ${expiredLinks.length} links`);+ // table log the last 10 links+ console.table(expiredLinks.slice(-10));+}++main();