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.

a few fixes

Kiran Kd6acb4572208
diff --git a/apps/web/lib/api/case-sensitive-short-links.ts b/apps/web/lib/api/case-sensitive-short-links.ts
index 0d7aae5ae1..bd66ce1dff 100644
--- a/apps/web/lib/api/case-sensitive-short-links.ts
+++ b/apps/web/lib/api/case-sensitive-short-links.ts
@@ -1,7 +1,11 @@
-import { Link } from "@prisma/client";
import { LinkProps } from "../types";
-export const CASE_SENSITIVE_DOMAINS = ["buff.ly", "dub.sh", "example.net"];
+export const CASE_SENSITIVE_DOMAINS = [
+ "buff.ly",
+ "dub.sh",
+ "example.net",
+ "acme.pub",
+];
const SECRET_KEY = "your-secret-key-here";
@@ -71,7 +75,7 @@ export const decodeShortLinkIfCaseSensitive = (shortLink: string) => {
};
// Decode key + shortLink if it's case sensitive
-export const decodeIfCaseSensitive = (link: Link) => {
+export const decodeIfCaseSensitive = (link: any) => {
if (isCaseSensitiveDomain(link.domain)) {
const originalKey = decodeKey(link.key);
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 622eed6765..8fa642f246 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -48,9 +48,7 @@ export default async function LinkMiddleware(
// links on Dub are case insensitive by default
let key = punyEncode(originalKey);
- const caseSensitive = isCaseSensitiveDomain(domain);
-
- if (!caseSensitive) {
+ if (!isCaseSensitiveDomain(domain)) {
key = key.toLowerCase();
}
diff --git a/apps/web/lib/planetscale/get-link-via-edge.ts b/apps/web/lib/planetscale/get-link-via-edge.ts
index 9d500c00c5..5ebcd844f9 100644
--- a/apps/web/lib/planetscale/get-link-via-edge.ts
+++ b/apps/web/lib/planetscale/get-link-via-edge.ts
@@ -1,10 +1,16 @@
import { punyEncode } from "@dub/utils";
-import { decodeKeyIfCaseSensitive } from "../api/case-sensitive-short-links";
+import {
+ decodeIfCaseSensitive,
+ decodeKeyIfCaseSensitive,
+} from "../api/case-sensitive-short-links";
import { conn } from "./connection";
import { EdgeLinkProps } from "./types";
export const getLinkViaEdge = async (domain: string, key: string) => {
- key = decodeKeyIfCaseSensitive({ domain, key });
+ key = decodeKeyIfCaseSensitive({
+ domain,
+ key,
+ });
const { rows } =
(await conn.execute(
@@ -12,7 +18,10 @@ export const getLinkViaEdge = async (domain: string, key: string) => {
[domain, punyEncode(decodeURIComponent(key))], // we need to make sure that the key is always URI-decoded + punycode-encoded (cause that's how we store it in MySQL)
)) || {};
- return rows && Array.isArray(rows) && rows.length > 0
- ? (rows[0] as EdgeLinkProps)
- : null;
+ const link =
+ rows && Array.isArray(rows) && rows.length > 0
+ ? (rows[0] as EdgeLinkProps)
+ : null;
+
+ return link ? decodeIfCaseSensitive(link) : null;
};