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.

fix punycode

Steven Tey33b9140d4403
diff --git a/apps/web/lib/api/links/bulk-create-links.ts b/apps/web/lib/api/links/bulk-create-links.ts
index a3ee1f6cd3..38656a11e4 100644
--- a/apps/web/lib/api/links/bulk-create-links.ts
+++ b/apps/web/lib/api/links/bulk-create-links.ts
@@ -98,16 +98,12 @@ export async function bulkCreateLinks({
// if there are no tags, we can use createMany to create the links
await prisma.link.createMany({
data: links.map((link) => {
- const shortLink = linkConstructor({
- domain: link.domain,
- key: link.key,
- });
const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =
getParamsFromURL(link.url);
return {
...link,
- shortLink,
+ shortLink: `https://${link.domain}/${link.key}`,
title: truncate(link.title, 120),
description: truncate(link.description, 240),
utm_source,
@@ -124,12 +120,7 @@ export async function bulkCreateLinks({
createdLinks = await prisma.link.findMany({
where: {
shortLink: {
- in: links.map((link) =>
- linkConstructor({
- domain: link.domain,
- key: link.key,
- }),
- ),
+ in: links.map((link) => `https://${link.domain}/${link.key}`),
},
},
});
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index 57b9f2697e..e292c218ef 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -8,7 +8,6 @@ import {
APP_DOMAIN_WITH_NGROK,
R2_URL,
getParamsFromURL,
- linkConstructor,
truncate,
} from "@dub/utils";
import { Prisma } from "@prisma/client";
@@ -26,13 +25,11 @@ export async function createLink(link: ProcessedLinkProps) {
const { tagId, tagIds, tagNames, ...rest } = link;
- const shortLink = linkConstructor({ domain: link.domain, key: link.key });
-
const response = await prisma.link.create({
data: {
...rest,
key,
- shortLink,
+ shortLink: `https://${link.domain}/${link.key}`,
title: truncate(title, 120),
description: truncate(description, 240),
// if it's an uploaded image, make this null first because we'll update it later
diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.ts
index 9ec1dc2398..330731fb59 100644
--- a/apps/web/lib/api/links/update-link.ts
+++ b/apps/web/lib/api/links/update-link.ts
@@ -3,13 +3,7 @@ import { isStored, storage } from "@/lib/storage";
import { recordLink } from "@/lib/tinybird";
import { LinkProps, ProcessedLinkProps } from "@/lib/types";
import { formatRedisLink, redis } from "@/lib/upstash";
-import {
- R2_URL,
- getParamsFromURL,
- linkConstructor,
- nanoid,
- truncate,
-} from "@dub/utils";
+import { R2_URL, getParamsFromURL, nanoid, truncate } from "@dub/utils";
import { Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { combineTagIds, transformLink } from "./utils";
@@ -56,11 +50,6 @@ export async function updateLink({
const imageUrlNonce = nanoid(7);
- const shortLink = linkConstructor({
- domain: updatedLink.domain,
- key: updatedLink.key,
- });
-
const response = await prisma.link.update({
where: {
id,
@@ -68,7 +57,7 @@ export async function updateLink({
data: {
...rest,
key,
- shortLink,
+ shortLink: `https://${updatedLink.domain}/${updatedLink.key}`,
title: truncate(title, 120),
description: truncate(description, 240),
image:
diff --git a/apps/web/scripts/backfill-short-links.ts b/apps/web/scripts/backfill-short-links.ts
index cf32ef2d2f..f9469f2c6f 100644
--- a/apps/web/scripts/backfill-short-links.ts
+++ b/apps/web/scripts/backfill-short-links.ts
@@ -1,5 +1,4 @@
import { prisma } from "@/lib/prisma";
-import { linkConstructor } from "@dub/utils";
import "dotenv-flow/config";
async function main() {
@@ -28,7 +27,7 @@ async function main() {
prisma.link.update({
where: { id: link.id },
data: {
- shortLink: linkConstructor({ domain: link.domain, key: link.key }),
+ shortLink: `https://${link.domain}/${link.key}`,
},
}),
),