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.

Replace domain/key with single link column

Tim Wilson1a77a1f824b0
diff --git a/apps/web/app/api/cron/import/csv/route.ts b/apps/web/app/api/cron/import/csv/route.ts
index 258d6f7798..66a488736b 100644
--- a/apps/web/app/api/cron/import/csv/route.ts
+++ b/apps/web/app/api/cron/import/csv/route.ts
@@ -27,15 +27,15 @@ export async function POST(req: Request) {
if (!id || !url) throw new Error("Missing ID or URL for the import file");
const mapper = (row: Record<string, string>) => {
+ const linkUrl = getPrettyUrl(row[mapping.link]);
+
return {
...Object.fromEntries(
Object.entries(mapping).map(([key, value]) => [key, row[value]]),
),
- domain: getPrettyUrl(row[mapping.domain]).split("/")[0],
+ domain: linkUrl.split("/")[0],
// domain.com/path/to/page => path/to/page
- key:
- getPrettyUrl(row[mapping.key]).split("/").slice(1).join("/") ??
- "_root",
+ key: linkUrl.split("/").slice(1).join("/") || "_root",
createdAt: mapping.createdAt
? parseDateTime(row[mapping.createdAt])
: undefined,
diff --git a/apps/web/lib/ai/generate-csv-mapping.ts b/apps/web/lib/ai/generate-csv-mapping.ts
index 8b391922b0..ef74bb59b6 100644
--- a/apps/web/lib/ai/generate-csv-mapping.ts
+++ b/apps/web/lib/ai/generate-csv-mapping.ts
@@ -18,26 +18,18 @@ export async function generateCsvMapping(
domain: z
.string()
.optional()
- .describe(
- "The domain of the shortlink. Can be mapped to a full URL if there is not a separate domain column",
- ),
- key: z
- .string()
- .optional()
- .describe(
- "The key/slug of the shortlink (a shortlink is: https://[domain]/[key]). Can be mapped to a full URL if there is not a separate key column",
- ),
+ .describe("The shortlink (link), including the domain and path."),
+ url: z.string().optional().describe("The full URL of the shortlink"),
createdAt: z
.string()
.optional()
- .describe("The date and time the shortlink was created"),
+ .describe("The date and time the shortlink was created (createdAt)"),
tags: z
.string()
.optional()
.describe(
"A comma-separated list of tags for shortlink organization (NOT to be mapped to a description).",
),
- url: z.string().optional().describe("The full URL of the shortlink"),
title: z.string().optional().describe("The title of the shortlink"),
description: z
.string()
diff --git a/apps/web/lib/zod/schemas/import-csv.ts b/apps/web/lib/zod/schemas/import-csv.ts
index 6d8b613141..9df959920a 100644
--- a/apps/web/lib/zod/schemas/import-csv.ts
+++ b/apps/web/lib/zod/schemas/import-csv.ts
@@ -1,9 +1,8 @@
import { z } from "zod";
export const linkMappingSchema = z.object({
- domain: z.string(),
+ link: z.string(),
url: z.string(),
- key: z.string(),
createdAt: z.string().optional(),
tags: z.string().optional(),
title: z.string().optional(),
diff --git a/apps/web/ui/modals/import-csv-modal/field-mapping.tsx b/apps/web/ui/modals/import-csv-modal/field-mapping.tsx
index 29e71d751b..8587474ddd 100644
--- a/apps/web/ui/modals/import-csv-modal/field-mapping.tsx
+++ b/apps/web/ui/modals/import-csv-modal/field-mapping.tsx
@@ -9,7 +9,7 @@ import {
TableIcon,
Xmark,
} from "@dub/ui/src/icons";
-import { cn, formatDate, truncate } from "@dub/utils";
+import { cn, formatDate, getPrettyUrl, truncate } from "@dub/utils";
import { readStreamableValue } from "ai/rsc";
import { ChevronDown } from "lucide-react";
import { useEffect, useMemo, useState } from "react";
@@ -82,19 +82,8 @@ function FieldRow({
let values = firstRows?.map((row) => row[value]).filter(Boolean);
switch (field) {
- case "domain":
- // Split by "/" and take the first part (excluding protocol)
- values = values.map((e) => e.replace(/^https?:\/\//, "").split("/")[0]);
- break;
- case "key":
- // Split by "/" and take the last part
- values = values.map(
- (e) =>
- e
- .replace(/^https?:\/\//, "")
- .split("/")
- .at(-1) as string,
- );
+ case "link":
+ values = values.map(getPrettyUrl);
break;
case "tags":
// Split by commas
@@ -104,6 +93,7 @@ function FieldRow({
.map((e) => e.trim())
.join(" & "),
);
+ break;
case "createdAt":
// Convert to date
values = values.map((e) =>
@@ -112,7 +102,7 @@ function FieldRow({
break;
}
- values = values.map((e) => truncate(e, 16) as string);
+ values = values.map((e) => truncate(e, 24) as string);
return values;
}, [firstRows, value]);
@@ -123,11 +113,6 @@ function FieldRow({
<span className="whitespace-nowrap text-sm font-medium text-gray-950">
{label} {required && <span className="text-red-700">*</span>}
</span>
- {["domain", "key"].includes(field) && (
- <InfoTooltip
- content={`If your file doesn't have an independent ${field} column, you can map this to the full URL instead.`}
- />
- )}
{field === "tags" && (
<InfoTooltip content="Tags may be comma-separated as long as they're escaped properly in the CSV file." />
)}
diff --git a/apps/web/ui/modals/import-csv-modal/index.tsx b/apps/web/ui/modals/import-csv-modal/index.tsx
index e5975247e8..333e3292de 100644
--- a/apps/web/ui/modals/import-csv-modal/index.tsx
+++ b/apps/web/ui/modals/import-csv-modal/index.tsx
@@ -33,16 +33,12 @@ import { FieldMapping } from "./field-mapping";
import { SelectFile } from "./select-file";
export const mappableFields = {
- domain: {
- label: "Domain",
- required: true,
- },
- key: {
- label: "Key",
+ link: {
+ label: "Short Link",
required: true,
},
url: {
- label: "URL",
+ label: "Destination URL",
required: true,
},
createdAt: {