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.

save script

Steven Tey21e3e356c3d6
diff --git a/apps/web/scripts/bulk-create-links.ts b/apps/web/scripts/bulk-create-links.ts
new file mode 100644
index 0000000000..a02910d04c
--- /dev/null
+++ b/apps/web/scripts/bulk-create-links.ts
@@ -0,0 +1,34 @@
+import { chunk } from "@dub/utils";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+import { bulkCreateLinks } from "../lib/api/links/bulk-create-links";
+
+const links: any[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("xxx.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: { data: any }) => {
+ const shortLink = result.data["Short link"];
+ links.push({
+ domain: shortLink.split("/")[0],
+ key: shortLink.split("/")[1],
+ url: result.data["Destination URL"],
+ projectId: "xxx",
+ userId: "xxx",
+ });
+ },
+ complete: async () => {
+ const chunks = chunk(links, 500);
+ for (const chunk of chunks) {
+ await bulkCreateLinks({ links: chunk });
+ console.log(`Created ${chunk.length} of ${links.length} links`);
+ await new Promise((resolve) => setTimeout(resolve, 500));
+ }
+ },
+ });
+}
+
+main();
diff --git a/packages/utils/src/functions/normalize-string.ts b/packages/utils/src/functions/normalize-string.ts
index ddbf788cbf..83cb1e8f3e 100644
--- a/packages/utils/src/functions/normalize-string.ts
+++ b/packages/utils/src/functions/normalize-string.ts
@@ -21,11 +21,11 @@ export const normalizeString = (key: string) => {
// Optional: Add logging in development
if (process.env.NODE_ENV === "development" && original !== normalized) {
- console.log(`Normalized key: "${original}" -> "${normalized}"`);
- console.log(
- "Original char codes:",
- Array.from(original).map((c) => c.charCodeAt(0)),
- );
+ // console.log(`Normalized key: "${original}" -> "${normalized}"`);
+ // console.log(
+ // "Original char codes:",
+ // Array.from(original).map((c) => c.charCodeAt(0)),
+ // );
}
return normalized;