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 check-if-key-exists.ts

Steven Tey70399f8a05ac
diff --git a/apps/web/lib/planetscale/check-if-key-exists.ts b/apps/web/lib/planetscale/check-if-key-exists.ts
index 85a1b0370c..66330397ab 100644
--- a/apps/web/lib/planetscale/check-if-key-exists.ts
+++ b/apps/web/lib/planetscale/check-if-key-exists.ts
@@ -1,11 +1,23 @@
import { punyEncode } from "@dub/utils";
+import {
+ encodeKey,
+ isCaseSensitiveDomain,
+} from "../api/links/case-sensitivity";
import { conn } from "./connection";
export const checkIfKeyExists = async (domain: string, key: string) => {
+ const isCaseSensitive = isCaseSensitiveDomain(domain);
+ const keyToQuery = isCaseSensitive
+ ? // for case sensitive domains, we need to encode the key
+ encodeKey(key)
+ : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded
+ // (cause that's how we store it in MySQL)
+ punyEncode(decodeURIComponent(key));
+
const { rows } =
(await conn.execute(
"SELECT 1 FROM Link WHERE domain = ? AND `key` = ? LIMIT 1",
- [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)
+ [domain, keyToQuery],
)) || {};
return rows && Array.isArray(rows) && rows.length > 0;