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 link import

Kiran Kd0fa7036e236
diff --git a/apps/web/lib/middleware/bitly.ts b/apps/web/lib/middleware/bitly.ts
index ed036a6565..73e2ae6777 100644
--- a/apps/web/lib/middleware/bitly.ts
+++ b/apps/web/lib/middleware/bitly.ts
@@ -3,6 +3,7 @@ import { getUrlFromStringIfValid, linkConstructorSimple } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { ExpandedLink } from "../api/links";
import { createId } from "../api/utils";
+import { EdgeLinkProps } from "../planetscale";
import { conn } from "../planetscale/connection";
import { recordLink } from "../tinybird/record-link";
@@ -16,10 +17,10 @@ type BitlyLink = {
};
// Create a new Bitly link in Dub on-demand
-export const createBitlyLink = async (bitlyLink: string) => {
- const workspaceId = "";
- const userId = "";
- const folderId = "";
+export const importBitlyLink = async (bitlyLink: string) => {
+ const workspaceId = "cl7pj5kq4006835rbjlt2ofka";
+ const userId = "cm1ypncqa0000tc44pfgxp6qs";
+ const folderId = "cm7oiaon50003sz0bdpm36snu";
const bitlyApiKey = await redis.get(`import:bitly:${workspaceId}`); // TODO: We might want to move this to a different key
@@ -74,15 +75,12 @@ export const createBitlyLink = async (bitlyLink: string) => {
tagIds: [], // TODO: add tags
createdAt: new Date(link.created_at),
updatedAt: new Date(link.created_at),
- tenantId: null,
- programId: null,
- partnerId: null,
};
console.log("[Bitly] Creating link", newLink);
await conn.execute(
- "INSERT INTO Link (id, projectId, userId, domain, `key`, url, shortLink, archived, createdAt, updatedAt, folderId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ "INSERT INTO Link (id, projectId, userId, domain, `key`, url, shortLink, archived, folderId, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[
newLink.id,
newLink.projectId,
@@ -92,9 +90,9 @@ export const createBitlyLink = async (bitlyLink: string) => {
newLink.url,
newLink.shortLink,
newLink.archived,
+ newLink.folderId,
newLink.createdAt,
newLink.updatedAt,
- newLink.folderId,
],
);
@@ -102,9 +100,12 @@ export const createBitlyLink = async (bitlyLink: string) => {
waitUntil(
recordLink({
...newLink,
+ tenantId: null,
+ programId: null,
+ partnerId: null,
tags: [],
} as unknown as ExpandedLink),
);
- return newLink;
+ return newLink as unknown as EdgeLinkProps;
};
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 93bbdc286e..62575f46ea 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -26,7 +26,7 @@ import {
import { linkCache } from "../api/links/cache";
import { getLinkViaEdge } from "../planetscale";
import { getDomainViaEdge } from "../planetscale/get-domain-via-edge";
-import { createBitlyLink } from "./bitly";
+import { importBitlyLink } from "./bitly";
import { hasEmptySearchParams } from "./utils/has-empty-search-params";
export default async function LinkMiddleware(
@@ -71,15 +71,15 @@ export default async function LinkMiddleware(
if (!link) {
let linkData = await getLinkViaEdge(domain, key);
- if (domain === "buff.ly") {
- const newLink = await createBitlyLink(`buff.ly/${key}`);
+ if (!linkData) {
+ if (domain === "buff.ly") {
+ const newLink = await importBitlyLink(`buff.ly/${key}`);
- if (newLink) {
- linkData = newLink;
+ if (newLink) {
+ linkData = newLink;
+ }
}
- }
- if (!linkData) {
// check if domain has notFoundUrl configured
const domainData = await getDomainViaEdge(domain);
if (domainData?.notFoundUrl) {