The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
stashed some changes
Steven Teyd6d21d78447a
diff --git a/lib/upstash.ts b/lib/upstash.tsindex 80c1243b62..23e0a74513 100644--- a/lib/upstash.ts+++ b/lib/upstash.ts@@ -1,7 +1,7 @@import { Redis } from "@upstash/redis";import { NextRequest, userAgent } from "next/server";import { LOCALHOST_GEO_DATA, RESERVED_KEYS } from "@/lib/constants";-import { LinkProps } from "@/lib/types";+import { LinkProps, ProjectProps } from "@/lib/types";import { customAlphabet } from "nanoid";import { getDescriptionFromUrl, getTitleFromUrl } from "@/lib/utils";@@ -246,8 +246,8 @@ export async function deleteLink(domain: string, key: string, userId?: string) {return await pipeline.exec();}-export async function getUsage(hostname: string, billingCycleStart?: Date) {- const cachedUsage = await redis.get(`usage:${hostname}`);+export async function getUsage(userId: string, projects: ProjectProps[]) {+ const cachedUsage = await redis.get(`usage:${userId}`);if (cachedUsage) {return cachedUsage;}diff --git a/pages/api/projects/usage.ts b/pages/api/projects/usage.tsindex cd0db4a428..12d5895246 100644--- a/pages/api/projects/usage.ts+++ b/pages/api/projects/usage.ts@@ -13,7 +13,16 @@ export default async function handler(// GET /api/projects/usage – get a user's usage over all their projectsif (req.method === "GET") {- const usage = await getUsage();+ const projects = await prisma.project.findMany({+ where: {+ users: {+ some: {+ userId: session.user.id,+ },+ },+ },+ });+ const usage = projects ? await getUsage(session.user.id, projects) : 0;return res.status(200).json(usage);} else {res.setHeader("Allow", ["GET"]);