The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
use shortLink for other importers too
Steven Tey88080d4f0040
diff --git a/apps/web/app/api/cron/import/bitly/route.ts b/apps/web/app/api/cron/import/bitly/route.tsindex c8ade51b0c..d2d27f485e 100644--- a/apps/web/app/api/cron/import/bitly/route.ts+++ b/apps/web/app/api/cron/import/bitly/route.ts@@ -16,7 +16,7 @@ export async function POST(req: Request) {await verifyQstashSignature({ req, rawBody });const body = JSON.parse(rawBody);- const { workspaceId, bitlyGroup, importTags, folderId } = body;+ const { workspaceId, bitlyGroup, importTags } = body;try {const bitlyApiKey = await redis.get(`import:bitly:${workspaceId}`);diff --git a/apps/web/app/api/cron/import/bitly/utils.ts b/apps/web/app/api/cron/import/bitly/utils.tsindex 8245c846b5..1b0a3fdaab 100644--- a/apps/web/app/api/cron/import/bitly/utils.ts+++ b/apps/web/app/api/cron/import/bitly/utils.ts@@ -22,7 +22,7 @@ export const importLinksFromBitly = async ({userId: string;bitlyGroup: string;domains: string[];- folderId: string;+ folderId?: string;tagsToId?: Record<string, string>;bitlyApiKey: string;searchAfter?: string | null;diff --git a/apps/web/app/api/cron/import/csv/route.ts b/apps/web/app/api/cron/import/csv/route.tsindex 9a45dd3ef3..69fb42c115 100644--- a/apps/web/app/api/cron/import/csv/route.ts+++ b/apps/web/app/api/cron/import/csv/route.ts@@ -14,6 +14,7 @@ import {DEFAULT_LINK_PROPS,DUB_DOMAINS_ARRAY,getPrettyUrl,+ linkConstructorSimple,log,normalizeString,parseDateTime,@@ -94,6 +95,10 @@ export async function POST(req: Request) {),domain,key,+ shortLink: linkConstructorSimple({+ domain,+ key,+ }),createdAt: mapping.createdAt? parseDateTime(getValueByNormalizedKey(mapping.createdAt)) ||undefined@@ -168,21 +173,20 @@ export async function POST(req: Request) {// Find links that already exist in the workspaceconst alreadyCreatedLinks = await prisma.link.findMany({where: {- domain: {- in: domains.map((domain) => domain.slug),- },- key: {+ shortLink: {in: data.map((row) => {const result = mapper(row);return "success" in result && result.success- ? result.data.key- : result.link.key;+ ? result.data.shortLink+ : linkConstructorSimple({+ domain: result.link.domain,+ key: result.link.key,+ });}),},},select: {- domain: true,- key: true,+ shortLink: true,},});@@ -194,9 +198,7 @@ export async function POST(req: Request) {"success" in result &&result.success === true &&!alreadyCreatedLinks.some(- (l) =>- l.domain === result.data.domain &&- l.key === result.data.key,+ (l) => l.shortLink === result.data.shortLink,) &&result.data.key !== "_root",)diff --git a/apps/web/app/api/cron/import/rebrandly/utils.ts b/apps/web/app/api/cron/import/rebrandly/utils.tsindex 3504cd273c..de31f83ed3 100644--- a/apps/web/app/api/cron/import/rebrandly/utils.ts+++ b/apps/web/app/api/cron/import/rebrandly/utils.ts@@ -6,7 +6,7 @@ import { randomBadgeColor } from "@/ui/links/tag-badge";import { sendEmail } from "@dub/email";import { LinksImported } from "@dub/email/templates/links-imported";import { prisma } from "@dub/prisma";-import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";+import { APP_DOMAIN_WITH_NGROK, linkConstructorSimple } from "@dub/utils";export const importTagsFromRebrandly = async ({workspaceId,@@ -192,6 +192,10 @@ export const importLinksFromRebrandly = async ({domain,key,url: destination,+ shortLink: linkConstructorSimple({+ domain,+ key,+ }),title,createdAt,updatedAt,@@ -204,19 +208,19 @@ export const importLinksFromRebrandly = async ({// check if links are already in the databaseconst alreadyCreatedLinks = await prisma.link.findMany({where: {- domain,- key: {- in: importedLinks.map((link) => link.key),+ shortLink: {+ in: importedLinks.map((link) => link.shortLink),},},select: {- key: true,+ shortLink: true,},});// filter out links that are already in the databaseconst linksToCreate = importedLinks.filter(- (link) => !alreadyCreatedLinks.some((l) => l.key === link.key),+ (link) =>+ !alreadyCreatedLinks.some((l) => l.shortLink === link.shortLink),);// bulk create linksdiff --git a/apps/web/app/api/cron/import/short/utils.ts b/apps/web/app/api/cron/import/short/utils.tsindex 99b81e9080..96eb7d2cd8 100644--- a/apps/web/app/api/cron/import/short/utils.ts+++ b/apps/web/app/api/cron/import/short/utils.ts@@ -6,7 +6,7 @@ import { randomBadgeColor } from "@/ui/links/tag-badge";import { sendEmail } from "@dub/email";import { LinksImported } from "@dub/email/templates/links-imported";import { prisma } from "@dub/prisma";-import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";+import { APP_DOMAIN_WITH_NGROK, linkConstructorSimple } from "@dub/utils";export const importLinksFromShort = async ({workspaceId,@@ -70,6 +70,10 @@ export const importLinksFromShort = async ({domain,key: path,url: originalURL,+ shortLink: linkConstructorSimple({+ domain,+ key: path,+ }),title,ios: iphoneURL,android: androidURL,@@ -84,19 +88,18 @@ export const importLinksFromShort = async ({// check if links are already in the databaseconst alreadyCreatedLinks = await prisma.link.findMany({where: {- domain,- key: {- in: importedLinks.map((link) => link.key),+ shortLink: {+ in: importedLinks.map((link) => link.shortLink),},},select: {- key: true,+ shortLink: true,},});// filter out links that are already in the databaseconst linksToCreate = importedLinks.filter(- (link) => !alreadyCreatedLinks.some((l) => l.key === link.key),+ (link) => !alreadyCreatedLinks.some((l) => l.shortLink === link.shortLink),);// import tags into database