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.

update click tracking

Steven Tey2109e25ccddd
diff --git a/apps/web/app/admin.dub.co/actions.ts b/apps/web/app/admin.dub.co/actions.ts
index d25b05eb41..32ea945829 100644
--- a/apps/web/app/admin.dub.co/actions.ts
+++ b/apps/web/app/admin.dub.co/actions.ts
@@ -10,7 +10,7 @@ import {
SHORT_DOMAIN,
getDomainWithoutWWW,
} from "@dub/utils";
-import { LEGAL_PROJECT_ID } from "@dub/utils/dist/constants";
+import { DUB_DOMAINS, LEGAL_PROJECT_ID } from "@dub/utils/dist/constants";
import { get } from "@vercel/edge-config";
import { randomBytes } from "crypto";
@@ -248,7 +248,9 @@ export async function banUser(data: FormData) {
prisma.link.updateMany({
where: {
userId: user.id,
- domain: SHORT_DOMAIN,
+ domain: {
+ in: DUB_DOMAINS.map((domain) => domain.slug),
+ },
},
data: {
userId: LEGAL_USER_ID,
diff --git a/apps/web/app/api/projects/route.ts b/apps/web/app/api/projects/route.ts
index 1ed7bd831a..5a055739c6 100644
--- a/apps/web/app/api/projects/route.ts
+++ b/apps/web/app/api/projects/route.ts
@@ -60,6 +60,24 @@ export const POST = withSession(async ({ req, session }) => {
}
}
+ const freeProjects = await prisma.project.count({
+ where: {
+ users: {
+ some: {
+ userId: session.user.id,
+ role: "owner",
+ },
+ },
+ },
+ });
+
+ if (freeProjects >= 1) {
+ return new Response(
+ "You can only create one free project on Dub.co. Additional projects require a paid plan.",
+ { status: 403 },
+ );
+ }
+
const [slugExist, domainExist] = await Promise.all([
prisma.project.findUnique({
where: {
diff --git a/apps/web/app/api/stats/[endpoint]/route.ts b/apps/web/app/api/stats/[endpoint]/route.ts
index 4d3229a46b..0429511742 100644
--- a/apps/web/app/api/stats/[endpoint]/route.ts
+++ b/apps/web/app/api/stats/[endpoint]/route.ts
@@ -9,24 +9,16 @@ export const GET = withAuth(
const { endpoint } = params;
const { domain, key, interval } = searchParams;
- // TODO: remove this after #545 merges
- if (isDubDomain(domain) && !key && project.id !== DUB_PROJECT_ID) {
- return new Response("Domain does not belong to project.", {
- status: 403,
- });
- }
-
- const constructedDomain =
- domain || project?.domains?.map((d) => d.slug).join(",");
-
- if (!constructedDomain) {
- return new Response("Missing link domain.", { status: 400 });
- }
+ let filteredDomain = "";
- // if there's no key and it's not a project, return 400
- // this is because projects can show stats for all links
- if (!key && !project) {
- return new Response("Missing link key.", { status: 400 });
+ // TODO: remove this logic after #545 merges
+ if (
+ domain &&
+ (!isDubDomain(domain) || key || project.id === DUB_PROJECT_ID)
+ ) {
+ filteredDomain = domain;
+ } else if (project.domains.length > 0) {
+ filteredDomain = project.domains.map((d) => d.slug).join(",");
}
// return 403 if project is on the free plan and interval is 90d or all
@@ -38,7 +30,7 @@ export const GET = withAuth(
}
const response = await getStats({
- domain: constructedDomain,
+ domain: filteredDomain,
key,
endpoint,
interval,
diff --git a/apps/web/lib/tinybird.ts b/apps/web/lib/tinybird.ts
index ae40e11583..1e4f65fa03 100644
--- a/apps/web/lib/tinybird.ts
+++ b/apps/web/lib/tinybird.ts
@@ -87,8 +87,8 @@ export async function recordClick({
[domain, key],
),
conn.execute(
- "UPDATE Project p JOIN Domain d ON p.id = d.projectId SET p.usage = p.usage + 1 WHERE d.slug = ?",
- [domain],
+ "UPDATE Project p JOIN Link l ON p.id = l.projectId SET p.usage = p.usage + 1 WHERE domain = ? AND `key` = ?",
+ [domain, key],
),
]
: conn.execute(
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 82abb4304a..805c029208 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -385,7 +385,7 @@ function AddEditLinkModal({
setUrlError(error);
}
} else {
- toast.error(res.statusText);
+ toast.error(await res.text());
}
}
setSaving(false);
diff --git a/apps/web/ui/modals/add-project-modal.tsx b/apps/web/ui/modals/add-project-modal.tsx
index 155e2e9e6b..a6cd22ccec 100644
--- a/apps/web/ui/modals/add-project-modal.tsx
+++ b/apps/web/ui/modals/add-project-modal.tsx
@@ -150,7 +150,7 @@ function AddProjectModalHelper({
toast.error(domainErrorResponse);
}
} else {
- toast.error(res.statusText);
+ toast.error(await res.text());
}
setSaving(false);
});
diff --git a/apps/web/ui/modals/archive-link-modal.tsx b/apps/web/ui/modals/archive-link-modal.tsx
index 5ae918f1b5..9281212f42 100644
--- a/apps/web/ui/modals/archive-link-modal.tsx
+++ b/apps/web/ui/modals/archive-link-modal.tsx
@@ -68,7 +68,7 @@ function ArchiveLinkModal({
setArchiving(false);
if (!res.ok) {
- toast.error(res.statusText);
+ toast.error(await res.text());
return;
}
diff --git a/apps/web/ui/projects/pro-banner.tsx b/apps/web/ui/projects/pro-banner.tsx
index 191ab02ab4..fafa88a27e 100644
--- a/apps/web/ui/projects/pro-banner.tsx
+++ b/apps/web/ui/projects/pro-banner.tsx
@@ -16,9 +16,8 @@ export default function ProBanner({
<div className="fixed bottom-5 z-10 mx-5 flex flex-col space-y-3 rounded-lg border border-gray-200 bg-white p-5 shadow-lg sm:right-5 sm:mx-auto sm:max-w-sm">
<h3 className="text-lg font-semibold">Upgrade to Pro</h3>
<p className="text-sm text-gray-500">
- It looks like you're currently on our free plan. Consider upgrading to
- Pro to enjoy higher limits, extra features, and support our open-source
- company.
+ It looks like you're currently on our Free plan. Please consider
+ upgrading to Pro to enjoy higher limits and extra features.
</p>
<div className="flex space-x-5">
<button
diff --git a/apps/web/ui/stats/toggle.tsx b/apps/web/ui/stats/toggle.tsx
index b3e22b77a5..2bdedd57cc 100644
--- a/apps/web/ui/stats/toggle.tsx
+++ b/apps/web/ui/stats/toggle.tsx
@@ -46,7 +46,7 @@ export default function Toggle() {
const scrolled = useScroll(80);
const { name, plan, logo } = useProject();
- const { projectDomains, primaryDomain } = useDomains();
+ const { allActiveDomains, primaryDomain } = useDomains();
const isPublicStatsPage = basePath.startsWith("/stats");
@@ -70,13 +70,13 @@ export default function Toggle() {
<h2 className="text-lg font-semibold text-gray-800">
{primaryDomain}
</h2>
- {projectDomains && projectDomains.length > 0 && (
+ {allActiveDomains && allActiveDomains.length > 1 && (
<Tooltip
- content={<DomainsFilterTooltip domains={projectDomains} />}
+ content={<DomainsFilterTooltip domains={allActiveDomains} />}
side="bottom"
>
<div className="cursor-pointer">
- <Badge variant="gray">+{projectDomains.length - 1}</Badge>
+ <Badge variant="gray">+{allActiveDomains.length - 1}</Badge>
</div>
</Tooltip>
)}