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.

limit to 25

Steven Teyd88c17a447ac
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index bf5f167159..4ab0a41dee 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -290,6 +290,22 @@ export async function processLink({
status: 422,
};
}
+ // we can do it here because we only pass session when creating a link (and not editing it)
+ if (session) {
+ const count = await prisma.link.count({
+ where: {
+ domain,
+ userId: session?.user.id,
+ },
+ });
+ if (count > 25) {
+ return {
+ link: payload,
+ error: `You can only create 25 ${domain} short links.`,
+ status: 403,
+ };
+ }
+ }
} else {
return {
link: payload,
diff --git a/apps/web/scripts/dub-domain-users.ts b/apps/web/scripts/dub-domain-users.ts
new file mode 100644
index 0000000000..c5afac5efa
--- /dev/null
+++ b/apps/web/scripts/dub-domain-users.ts
@@ -0,0 +1,23 @@
+import "dotenv-flow/config";
+import prisma from "@/lib/prisma";
+
+async function main() {
+ const users = await prisma.link.groupBy({
+ by: ["userId"],
+ where: {
+ domain: "dub.sh",
+ },
+ _count: {
+ userId: true,
+ },
+ orderBy: {
+ _count: {
+ userId: "desc",
+ },
+ },
+ take: 100,
+ });
+ console.table(users);
+}
+
+main();
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index 53914e005f..61db0d582d 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -538,11 +538,15 @@ function AddEditLinkModal({
</div>
)}
</div>
- {keyError && (
+ {keyError ? (
<p className="mt-2 text-sm text-red-600" id="key-error">
{keyError}
</p>
- )}
+ ) : domain === "chatg.pt" ? (
+ <p className="mt-2 text-sm text-gray-500">
+ You can only create up to 25 links with this domain.
+ </p>
+ ) : null}
</div>
</div>