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.

missed a few spots

Kiran K52d0f99fea35
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.ts
index 2a67b661cc..5bd943626b 100644
--- a/apps/web/app/api/customers/[id]/activity/route.ts
+++ b/apps/web/app/api/customers/[id]/activity/route.ts
@@ -1,4 +1,5 @@
import { getEvents } from "@/lib/analytics/get-events";
+import { decodeLinkIfCaseSensitive } from "@/lib/api/case-sensitive-short-links";
import { getCustomerOrThrow } from "@/lib/api/customers/get-customer-or-throw";
import { transformCustomer } from "@/lib/api/customers/transform-customer";
import { withWorkspace } from "@/lib/auth";
@@ -32,7 +33,7 @@ export const GET = withWorkspace(async ({ workspace, params, session }) => {
);
}
- const [leadEvents, saleEvents, link] = await Promise.all([
+ let [leadEvents, saleEvents, link] = await Promise.all([
getEvents({
customerId: customer.id,
event: "leads",
@@ -104,6 +105,8 @@ export const GET = withWorkspace(async ({ workspace, params, session }) => {
(a, b) => b.timestamp.getTime() - a.timestamp.getTime(),
);
+ link = decodeLinkIfCaseSensitive(link);
+
// Add click event to activities
activity.push({
timestamp: customer.clickedAt!,
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index 318bdb99aa..781b0f8b61 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -1,7 +1,7 @@
import { tb } from "@/lib/tinybird";
import { prisma } from "@dub/prisma";
import { Link } from "@dub/prisma/client";
-import { decodeKeyIfCaseSensitive } from "../api/case-sensitive-short-links";
+import { decodeLinkIfCaseSensitive } from "../api/case-sensitive-short-links";
import { transformLink } from "../api/links";
import { generateRandomName } from "../names";
import z from "../zod";
@@ -107,15 +107,12 @@ export const getEvents = async (params: EventsFilters) => {
const events = response.data
.map((evt) => {
- const link = linksMap[evt.link_id];
+ let link = linksMap[evt.link_id];
if (!link) {
return null;
}
- link.key = decodeKeyIfCaseSensitive({
- domain: link.domain,
- key: link.key,
- });
+ link = decodeLinkIfCaseSensitive(link);
const eventData = {
...evt,
diff --git a/apps/web/lib/api/case-sensitive-short-links.ts b/apps/web/lib/api/case-sensitive-short-links.ts
index 29fc405402..2df1509fa9 100644
--- a/apps/web/lib/api/case-sensitive-short-links.ts
+++ b/apps/web/lib/api/case-sensitive-short-links.ts
@@ -57,7 +57,10 @@ export const decodeLinkIfCaseSensitive = (link: any) => {
if (isCaseSensitiveDomain(link.domain)) {
const originalKey = decodeKey(link.key);
- link.shortLink = link.shortLink.replace(link.key, originalKey);
+ if (link.shortLink) {
+ link.shortLink = link.shortLink.replace(link.key, originalKey);
+ }
+
link.key = originalKey;
}
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 8fa642f246..3fe5e589e7 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -81,6 +81,10 @@ export default async function LinkMiddleware(
let linkData = await getLinkViaEdge(domain, key);
if (!linkData) {
+ // TODO
+ // if the link doesn’t exist in redis (which is case sensitive), we need to read both the old version + new hashed version from MySQL.
+ // If the hashed version exists, we should use that one since we know that it’s 100% accurate.
+
if (domain === "buff.ly" || domain === "dev.buff.ly") {
linkData = await importBitlyLink({ domain, key: originalKey });
}