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.

Add Rebrandly Migrator

Steven Tey625998482292
diff --git a/apps/web/app/api/cron/import/bitly/route.ts b/apps/web/app/api/cron/import/bitly/route.ts
index 9acc2ea998..a6d1ba6b5d 100644
--- a/apps/web/app/api/cron/import/bitly/route.ts
+++ b/apps/web/app/api/cron/import/bitly/route.ts
@@ -21,11 +21,11 @@ export async function POST(req: Request) {
}
try {
- const { projectId, bitlyGroup, keepTags } = body;
+ const { projectId, bitlyGroup, importTags } = body;
const bitlyApiKey = await redis.get(`import:bitly:${projectId}`);
let tagsToId: Record<string, string> | null = null;
- if (keepTags === true) {
+ if (importTags === true) {
const tagsImported = await redis.get(`import:bitly:${projectId}:tags`);
if (!tagsImported) {
diff --git a/apps/web/app/api/cron/import/bitly/utils.ts b/apps/web/app/api/cron/import/bitly/utils.ts
index 6dc40c7922..b1e74816d1 100644
--- a/apps/web/app/api/cron/import/bitly/utils.ts
+++ b/apps/web/app/api/cron/import/bitly/utils.ts
@@ -211,7 +211,7 @@ export const importLinksFromBitly = async ({
userId,
bitlyGroup,
domains,
- keepTags: tagsToId ? true : false,
+ importTags: tagsToId ? true : false,
searchAfter: nextSearchAfter,
count,
},
diff --git a/apps/web/app/api/cron/import/rebrandly/route.ts b/apps/web/app/api/cron/import/rebrandly/route.ts
new file mode 100644
index 0000000000..a86783fa1e
--- /dev/null
+++ b/apps/web/app/api/cron/import/rebrandly/route.ts
@@ -0,0 +1,80 @@
+import { receiver } from "@/lib/cron";
+import prisma from "@/lib/prisma";
+import { redis } from "@/lib/upstash";
+import { log } from "@dub/utils";
+import { NextResponse } from "next/server";
+import { importLinksFromRebrandly, importTagsFromRebrandly } from "./utils";
+
+export const maxDuration = 300;
+
+export async function POST(req: Request) {
+ const body = await req.json();
+ if (process.env.VERCEL === "1") {
+ const isValid = await receiver.verify({
+ signature: req.headers.get("Upstash-Signature") || "",
+ body: JSON.stringify(body),
+ });
+ if (!isValid) {
+ return new Response("Unauthorized", { status: 401 });
+ }
+ }
+
+ try {
+ const { projectId, importTags } = body;
+ const rebrandlyApiKey = await redis.get<string>(
+ `import:rebrandly:${projectId}`,
+ );
+
+ if (!rebrandlyApiKey) {
+ throw new Error("No Rebrandly API key found");
+ }
+
+ let tagsToId: Record<string, string> | null = null;
+ if (importTags === true) {
+ const tagsImported = await redis.get(
+ `import:rebrandly:${projectId}:tags`,
+ );
+
+ if (!tagsImported) {
+ await importTagsFromRebrandly({
+ projectId,
+ rebrandlyApiKey,
+ });
+
+ await redis.set(`import:rebrandly:${projectId}:tags`, "true");
+ }
+
+ tagsToId = await prisma.tag
+ .findMany({
+ where: {
+ projectId,
+ },
+ select: {
+ id: true,
+ name: true,
+ },
+ })
+ .then((tags) =>
+ tags.reduce((acc, tag) => {
+ acc[tag.name] = tag.id;
+ return acc;
+ }, {}),
+ );
+ }
+ await importLinksFromRebrandly({
+ ...body,
+ tagsToId,
+ rebrandlyApiKey,
+ });
+ return NextResponse.json({
+ response: "success",
+ });
+ } catch (error) {
+ await log({
+ message: "Import Rebrandly cron failed. Error: " + error.message,
+ type: "cron",
+ mention: true,
+ });
+ return NextResponse.json({ error: error.message });
+ }
+}
diff --git a/apps/web/app/api/cron/import/rebrandly/utils.ts b/apps/web/app/api/cron/import/rebrandly/utils.ts
new file mode 100644
index 0000000000..4a32835a68
--- /dev/null
+++ b/apps/web/app/api/cron/import/rebrandly/utils.ts
@@ -0,0 +1,234 @@
+import { qstash } from "@/lib/cron";
+import prisma from "@/lib/prisma";
+import { redis } from "@/lib/upstash";
+import { randomBadgeColor } from "@/ui/links/tag-badge";
+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
+import { sendEmail } from "emails";
+import LinksImported from "emails/links-imported";
+
+export const importTagsFromRebrandly = async ({
+ projectId,
+ rebrandlyApiKey,
+ lastTagId = null,
+}: {
+ projectId: string;
+ rebrandlyApiKey: string;
+ lastTagId?: string | null;
+}) => {
+ const tags = (await fetch(
+ `https://api.rebrandly.com/v1/tags?orderBy=name&orderDir=desc&limit=25${
+ lastTagId ? `&last=${lastTagId}` : ""
+ }`,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ apikey: rebrandlyApiKey as string,
+ },
+ },
+ ).then((r) => r.json())) as {
+ id: string;
+ name: string;
+ color: string;
+ }[];
+
+ // if no tags left, meaning import is complete
+ if (tags.length === 0) {
+ return;
+ }
+
+ const newLastTagId = tags[tags.length - 1].id;
+
+ // import tags into database
+ await prisma.tag.createMany({
+ data: tags.map((tag) => ({
+ name: tag.name,
+ color: randomBadgeColor(),
+ projectId,
+ })),
+ skipDuplicates: true,
+ });
+
+ // wait 500 ms before making another request
+ await new Promise((resolve) => setTimeout(resolve, 500));
+
+ return await importTagsFromRebrandly({
+ projectId,
+ rebrandlyApiKey,
+ lastTagId: newLastTagId,
+ });
+};
+
+export const importLinksFromRebrandly = async ({
+ projectId,
+ userId,
+ domainId,
+ domain,
+ tagsToId,
+ rebrandlyApiKey,
+ lastLinkId = null,
+ count = 0,
+}: {
+ projectId: string;
+ userId: string;
+ domainId: number;
+ domain: string;
+ tagsToId?: Record<string, string>;
+ rebrandlyApiKey: string;
+ lastLinkId?: string | null;
+ count?: number;
+}) => {
+ const links = await fetch(
+ `https://api.rebrandly.com/v1/links?domain.id=${domainId}&orderBy=createdAt&orderDir=asc&limit=25${
+ lastLinkId ? `&last=${lastLinkId}` : ""
+ }`,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ apikey: rebrandlyApiKey as string,
+ },
+ },
+ ).then((res) => res.json());
+
+ // if no more links, meaning import is complete
+ if (links.length === 0) {
+ const project = await prisma.project.findUnique({
+ where: {
+ id: projectId,
+ },
+ select: {
+ name: true,
+ slug: true,
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ },
+ links: {
+ select: {
+ domain: true,
+ key: true,
+ createdAt: true,
+ },
+ where: {
+ domain,
+ },
+ take: 5,
+ orderBy: {
+ createdAt: "desc",
+ },
+ },
+ },
+ });
+ const ownerEmail = project?.users[0].user.email ?? "";
+ const links = project?.links ?? [];
+
+ await Promise.all([
+ // delete keys from redis
+ redis.del(`import:rebrandly:${projectId}`),
+ redis.del(`import:rebrandly:${projectId}:tags`),
+
+ // delete tags that have no links
+ prisma.tag.deleteMany({
+ where: {
+ projectId,
+ links: {
+ none: {},
+ },
+ },
+ }),
+
+ // send email to user
+ sendEmail({
+ subject: `Your Rebrandly links have been imported!`,
+ email: ownerEmail,
+ react: LinksImported({
+ email: ownerEmail,
+ provider: "Rebrandly",
+ count,
+ links,
+ domains: [domain],
+ projectName: project?.name ?? "",
+ projectSlug: project?.slug ?? "",
+ }),
+ }),
+ ]);
+ return count;
+
+ // if there are more links, import them
+ } else {
+ const newLastLinkId = links[links.length - 1].id;
+
+ const pipeline = redis.pipeline();
+
+ // convert links to format that can be imported into database
+ const importedLinks = links
+ .map(({ title, slashtag, destination, tags, createdAt, updatedAt }) => {
+ pipeline.set(
+ `${domain}:${slashtag}`,
+ {
+ url: encodeURIComponent(destination),
+ },
+ {
+ nx: true,
+ },
+ );
+
+ // if tagsToId is provided and tags array is not empty, get the tagId
+ const tagId =
+ tagsToId && tags.length > 0 ? tagsToId[tags[0].name] : null;
+
+ return {
+ projectId,
+ userId,
+ domain,
+ key: slashtag,
+ url: destination,
+ title,
+ createdAt,
+ updatedAt,
+ ...(tagId ? { tagId } : {}),
+ };
+ })
+ .filter(Boolean);
+
+ // import links into database
+ await Promise.all([
+ prisma.link.createMany({
+ data: importedLinks,
+ skipDuplicates: true,
+ }),
+ pipeline.exec(),
+ ]);
+
+ count += importedLinks.length;
+
+ console.log({
+ importedLinksLength: importedLinks.length,
+ count,
+ newLastLinkId,
+ });
+
+ // wait 500 ms before making another request
+ await new Promise((resolve) => setTimeout(resolve, 500));
+
+ return await qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/rebrandly`,
+ body: {
+ projectId,
+ userId,
+ domainId,
+ domain,
+ importTags: tagsToId ? true : false,
+ lastLinkId: newLastLinkId,
+ count,
+ },
+ });
+ }
+};
diff --git a/apps/web/app/api/projects/[slug]/import/bitly/route.ts b/apps/web/app/api/projects/[slug]/import/bitly/route.ts
index 99ac799fb7..4b7f49ca25 100644
--- a/apps/web/app/api/projects/[slug]/import/bitly/route.ts
+++ b/apps/web/app/api/projects/[slug]/import/bitly/route.ts
@@ -82,7 +82,7 @@ export const POST = withAuth(async ({ req, project, session }) => {
result.push({
bitlyGroup,
domains: [domain],
- keepTags: selectedGroupTags.includes(bitlyGroup),
+ importTags: selectedGroupTags.includes(bitlyGroup),
});
}
return result;
@@ -92,7 +92,7 @@ export const POST = withAuth(async ({ req, project, session }) => {
groups
// only add groups that have at least 1 domain selected for import
.filter(({ domains }) => domains.length > 0)
- .map(({ bitlyGroup, domains, keepTags }) =>
+ .map(({ bitlyGroup, domains, importTags }) =>
qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/bitly`,
body: {
@@ -100,7 +100,7 @@ export const POST = withAuth(async ({ req, project, session }) => {
userId: session?.user?.id,
bitlyGroup,
domains,
- keepTags,
+ importTags,
},
}),
),
diff --git a/apps/web/app/api/projects/[slug]/import/rebrandly/route.ts b/apps/web/app/api/projects/[slug]/import/rebrandly/route.ts
new file mode 100644
index 0000000000..fa394be877
--- /dev/null
+++ b/apps/web/app/api/projects/[slug]/import/rebrandly/route.ts
@@ -0,0 +1,107 @@
+import { addDomainToVercel } from "@/lib/api/domains";
+import { withAuth } from "@/lib/auth";
+import { qstash } from "@/lib/cron";
+import prisma from "@/lib/prisma";
+import { redis } from "@/lib/upstash";
+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
+import { NextResponse } from "next/server";
+
+// GET /api/projects/[slug]/import/rebrandly – get all Rebrandly domains for a project
+export const GET = withAuth(async ({ project }) => {
+ const accessToken = await redis.get(`import:rebrandly:${project.id}`);
+ if (!accessToken) {
+ return new Response("No Rebrandly access token found", { status: 400 });
+ }
+
+ const response = await fetch(`https://api.rebrandly.com/v1/domains`, {
+ headers: {
+ "Content-Type": "application/json",
+ apikey: accessToken as string,
+ },
+ });
+ const data = await response.json();
+ if (data.error === "Unauthorized") {
+ return new Response("Invalid Rebrandly access token", { status: 403 });
+ }
+
+ const domains = await Promise.all(
+ data
+ .filter(({ fullName }) => fullName !== "rebrand.ly")
+ .map(async ({ id, fullName }: { id: number; fullName: string }) => ({
+ id,
+ domain: fullName,
+ links: await fetch(
+ `https://api.rebrandly.com/v1/links/count?domain.id=${id}`,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ apikey: accessToken as string,
+ },
+ },
+ )
+ .then((r) => r.json())
+ .then((data) => data.count) // subtract 1 to exclude root domain
+ .catch(() => 0),
+ })),
+ );
+
+ const tagsCount = await fetch("https://api.rebrandly.com/v1/tags/count", {
+ headers: {
+ "Content-Type": "application/json",
+ apikey: accessToken as string,
+ },
+ })
+ .then((r) => r.json())
+ .then((data) => data.count);
+
+ return NextResponse.json({ domains, tagsCount });
+});
+
+// PUT /api/projects/[slug]/import/rebrandly - save Rebrandly API key
+export const PUT = withAuth(async ({ req, project }) => {
+ const { apiKey } = await req.json();
+ const response = await redis.set(`import:rebrandly:${project.id}`, apiKey);
+ return NextResponse.json(response);
+});
+
+// POST /api/projects/[slug]/import/rebrandly - create job to import links from Rebrandly
+export const POST = withAuth(async ({ req, project, session }) => {
+ const { selectedDomains, importTags } = await req.json();
+
+ // check if there are domains that are not in the project
+ // if yes, add them to the project
+ const domainsNotInProject = selectedDomains.filter(
+ ({ domain }) => !project.domains?.find((d) => d.slug === domain),
+ );
+ if (domainsNotInProject.length > 0) {
+ await Promise.allSettled([
+ prisma.domain.createMany({
+ data: domainsNotInProject.map(({ domain }) => ({
+ slug: domain,
+ target: null,
+ type: "redirect",
+ projectId: project.id,
+ primary: false,
+ })),
+ skipDuplicates: true,
+ }),
+ domainsNotInProject.map(({ domain }) => addDomainToVercel(domain)),
+ ]);
+ }
+
+ const response = await Promise.all(
+ selectedDomains.map(({ id, domain }) =>
+ qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/import/rebrandly`,
+ body: {
+ projectId: project.id,
+ userId: session?.user?.id,
+ domainId: id,
+ domain,
+ importTags,
+ },
+ }),
+ ),
+ );
+ return NextResponse.json(response);
+});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
index 6206933b75..99cc546f79 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
@@ -52,7 +52,7 @@ const AddLinkOptions = () => {
<Tooltip
content={
<TooltipContent
- title="Your project has exceeded its usage limit. We're still collecting data on your existing links, but you need to upgrade to edit them."
+ title="Your project has exceeded its usage limit. We're still collecting data on your existing links, but you need to upgrade to add more links."
cta="Upgrade to Pro"
onClick={() => {
setOpenPopover(false);
@@ -88,7 +88,7 @@ const AddLinkOptions = () => {
<img
src="/_static/icons/bitly.svg"
alt="Bitly logo"
- className="h-4 w-4 rounded-full grayscale"
+ className="h-4 w-4 rounded-full"
/>
}
/>
@@ -98,7 +98,7 @@ const AddLinkOptions = () => {
<Tooltip
content={
<TooltipContent
- title="Your project has exceeded its usage limit. We're still collecting data on your existing links, but you need to upgrade to edit them."
+ title="Your project has exceeded its usage limit. We're still collecting data on your existing links, but you need to upgrade to add more links."
cta="Upgrade to Pro"
onClick={() => {
setOpenPopover(false);
@@ -134,7 +134,53 @@ const AddLinkOptions = () => {
<img
src="/_static/icons/short.svg"
alt="Short.io logo"
- className="h-4 w-4 grayscale"
+ className="h-4 w-4"
+ />
+ }
+ />
+ </button>
+ )}
+ {slug && exceededUsage ? (
+ <Tooltip
+ content={
+ <TooltipContent
+ title="Your project has exceeded its usage limit. We're still collecting data on your existing links, but you need to upgrade to add more links."
+ cta="Upgrade to Pro"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowUpgradePlanModal(true);
+ }}
+ />
+ }
+ >
+ <div className="flex w-full cursor-not-allowed items-center justify-between space-x-2 rounded-md p-2 text-sm text-gray-400">
+ <IconMenu
+ text="Import from Rebrandly"
+ icon={
+ <img
+ src="/_static/icons/rebrandly.svg"
+ alt="Rebrandly logo"
+ className="h-4 w-4 grayscale"
+ />
+ }
+ />
+ </div>
+ </Tooltip>
+ ) : (
+ <button
+ onClick={() => {
+ setOpenPopover(false);
+ router.push(`/${slug}?import=rebrandly`);
+ }}
+ className="w-full rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <IconMenu
+ text="Import from Rebrandly"
+ icon={
+ <img
+ src="/_static/icons/rebrandly.svg"
+ alt="Rebrandly logo"
+ className="h-5 w-5"
/>
}
/>
diff --git a/apps/web/emails/links-imported.tsx b/apps/web/emails/links-imported.tsx
index 0f3ed5cfb2..a64576edc3 100644
--- a/apps/web/emails/links-imported.tsx
+++ b/apps/web/emails/links-imported.tsx
@@ -53,7 +53,7 @@ export default function LinksImported({
domains = ["ac.me"],
}: {
email: string;
- provider: "Bitly" | "Short.io" | "CSV";
+ provider: "Bitly" | "Short.io" | "Rebrandly" | "CSV";
count: number;
links: {
domain: string;
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 3aab7753bb..241d53d6df 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -81,7 +81,7 @@ export interface BitlyGroupProps {
tags: string[];
}
-export interface ShortioDomainProps {
+export interface ImportedDomainCountProps {
id: number;
domain: string;
links: number;
diff --git a/apps/web/public/_static/icons/rebrandly.svg b/apps/web/public/_static/icons/rebrandly.svg
new file mode 100644
index 0000000000..0cefcb6394
--- /dev/null
+++ b/apps/web/public/_static/icons/rebrandly.svg
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0.00 0.00 400.00 400.00">
+<g stroke-width="2.00" fill="none" stroke-linecap="butt">
+<path stroke="#91caf1" vector-effect="non-scaling-stroke" d="
+ M 368.05 202.00
+ A 168.05 168.05 0.0 0 0 200.00 33.95
+ A 168.05 168.05 0.0 0 0 31.95 202.00
+ A 168.05 168.05 0.0 0 0 200.00 370.05
+ A 168.05 168.05 0.0 0 0 368.05 202.00"
+/>
+<path stroke="#91caf1" vector-effect="non-scaling-stroke" d="
+ M 353.08 202.00
+ A 143.17 143.17 0.0 0 0 209.91 58.83
+ A 143.17 143.17 0.0 0 0 66.74 202.00
+ A 143.17 143.17 0.0 0 0 209.91 345.17
+ A 143.17 143.17 0.0 0 0 353.08 202.00"
+/>
+<path stroke="#91caf1" vector-effect="non-scaling-stroke" d="
+ M 200.15 239.30
+ Q 200.55 238.86 200.75 239.42
+ Q 205.76 252.95 211.08 268.61
+ C 215.37 281.24 222.52 291.19 237.16 290.34
+ Q 245.03 289.89 251.72 286.33
+ C 261.27 281.27 269.24 273.15 275.84 264.63
+ Q 284.53 253.43 290.74 242.56
+ A 2.48 2.47 -35.5 0 0 291.02 240.90
+ Q 290.61 238.77 289.27 238.60
+ Q 286.22 238.21 284.36 240.68
+ Q 272.44 256.50 258.27 266.96
+ C 253.29 270.63 244.06 276.23 239.15 269.47
+ Q 236.55 265.90 235.49 263.05
+ C 231.36 251.96 227.40 240.58 220.40 230.94
+ Q 219.94 230.32 220.71 230.25
+ C 236.95 228.79 251.74 223.74 263.69 213.77
+ C 278.44 201.47 286.65 184.39 285.49 165.25
+ C 283.27 128.79 250.40 110.46 217.06 110.07
+ C 187.13 109.72 156.09 115.84 130.25 130.43
+ C 124.06 133.92 110.71 142.74 109.35 150.12
+ C 107.20 161.75 115.23 172.26 124.59 178.25
+ A 0.69 0.68 -57.0 0 0 125.52 178.05
+ Q 128.68 173.25 132.59 169.20
+ Q 140.81 160.69 150.07 153.36
+ Q 158.46 146.72 169.63 141.42
+ Q 186.18 133.58 200.49 130.37
+ C 215.46 127.01 236.44 126.42 248.81 137.59
+ C 255.66 143.78 259.78 151.79 259.57 161.35
+ C 258.94 191.09 242.01 213.94 212.81 222.25
+ Q 212.17 222.43 211.60 222.09
+ L 207.35 219.59
+ A 0.64 0.64 0.0 0 1 207.07 218.82
+ C 215.50 195.57 224.68 172.67 232.44 149.08
+ Q 233.51 145.84 233.17 143.99
+ C 232.31 139.24 224.53 138.52 220.72 138.67
+ Q 214.30 138.92 207.78 140.76
+ Q 207.24 140.91 207.05 141.43
+ C 198.22 165.41 188.07 190.47 179.60 215.65
+ Q 179.43 216.17 178.90 216.31
+ Q 175.53 217.16 173.14 219.43
+ C 169.70 222.70 170.74 227.62 174.25 230.39
+ Q 174.76 230.79 174.58 231.41
+ Q 169.47 248.87 164.01 268.60
+ Q 161.80 276.57 160.90 282.81
+ C 159.93 289.56 166.15 293.80 172.39 293.87
+ Q 176.71 293.92 181.25 293.42
+ Q 181.80 293.36 181.98 292.83
+ Q 190.92 266.44 199.91 239.72
+ Q 199.98 239.49 200.15 239.30"
+/>
+</g>
+<path fill="#ffffff" d="
+ M 0.00 0.00
+ L 400.00 0.00
+ L 400.00 400.00
+ L 0.00 400.00
+ L 0.00 0.00
+ Z
+ M 368.05 202.00
+ A 168.05 168.05 0.0 0 0 200.00 33.95
+ A 168.05 168.05 0.0 0 0 31.95 202.00
+ A 168.05 168.05 0.0 0 0 200.00 370.05
+ A 168.05 168.05 0.0 0 0 368.05 202.00
+ Z"
+/>
+<path fill="#2394e2" d="
+ M 368.05 202.00
+ A 168.05 168.05 0.0 0 1 200.00 370.05
+ A 168.05 168.05 0.0 0 1 31.95 202.00
+ A 168.05 168.05 0.0 0 1 200.00 33.95
+ A 168.05 168.05 0.0 0 1 368.05 202.00
+ Z
+ M 353.08 202.00
+ A 143.17 143.17 0.0 0 0 209.91 58.83
+ A 143.17 143.17 0.0 0 0 66.74 202.00
+ A 143.17 143.17 0.0 0 0 209.91 345.17
+ A 143.17 143.17 0.0 0 0 353.08 202.00
+ Z"
+/>
+<path fill="#ffffff" d="
+ M 353.08 202.00
+ A 143.17 143.17 0.0 0 1 209.91 345.17
+ A 143.17 143.17 0.0 0 1 66.74 202.00
+ A 143.17 143.17 0.0 0 1 209.91 58.83
+ A 143.17 143.17 0.0 0 1 353.08 202.00
+ Z
+ M 200.15 239.30
+ Q 200.55 238.86 200.75 239.42
+ Q 205.76 252.95 211.08 268.61
+ C 215.37 281.24 222.52 291.19 237.16 290.34
+ Q 245.03 289.89 251.72 286.33
+ C 261.27 281.27 269.24 273.15 275.84 264.63
+ Q 284.53 253.43 290.74 242.56
+ A 2.48 2.47 -35.5 0 0 291.02 240.90
+ Q 290.61 238.77 289.27 238.60
+ Q 286.22 238.21 284.36 240.68
+ Q 272.44 256.50 258.27 266.96
+ C 253.29 270.63 244.06 276.23 239.15 269.47
+ Q 236.55 265.90 235.49 263.05
+ C 231.36 251.96 227.40 240.58 220.40 230.94
+ Q 219.94 230.32 220.71 230.25
+ C 236.95 228.79 251.74 223.74 263.69 213.77
+ C 278.44 201.47 286.65 184.39 285.49 165.25
+ C 283.27 128.79 250.40 110.46 217.06 110.07
+ C 187.13 109.72 156.09 115.84 130.25 130.43
+ C 124.06 133.92 110.71 142.74 109.35 150.12
+ C 107.20 161.75 115.23 172.26 124.59 178.25
+ A 0.69 0.68 -57.0 0 0 125.52 178.05
+ Q 128.68 173.25 132.59 169.20
+ Q 140.81 160.69 150.07 153.36
+ Q 158.46 146.72 169.63 141.42
+ Q 186.18 133.58 200.49 130.37
+ C 215.46 127.01 236.44 126.42 248.81 137.59
+ C 255.66 143.78 259.78 151.79 259.57 161.35
+ C 258.94 191.09 242.01 213.94 212.81 222.25
+ Q 212.17 222.43 211.60 222.09
+ L 207.35 219.59
+ A 0.64 0.64 0.0 0 1 207.07 218.82
+ C 215.50 195.57 224.68 172.67 232.44 149.08
+ Q 233.51 145.84 233.17 143.99
+ C 232.31 139.24 224.53 138.52 220.72 138.67
+ Q 214.30 138.92 207.78 140.76
+ Q 207.24 140.91 207.05 141.43
+ C 198.22 165.41 188.07 190.47 179.60 215.65
+ Q 179.43 216.17 178.90 216.31
+ Q 175.53 217.16 173.14 219.43
+ C 169.70 222.70 170.74 227.62 174.25 230.39
+ Q 174.76 230.79 174.58 231.41
+ Q 169.47 248.87 164.01 268.60
+ Q 161.80 276.57 160.90 282.81
+ C 159.93 289.56 166.15 293.80 172.39 293.87
+ Q 176.71 293.92 181.25 293.42
+ Q 181.80 293.36 181.98 292.83
+ Q 190.92 266.44 199.91 239.72
+ Q 199.98 239.49 200.15 239.30
+ Z"
+/>
+<path fill="#2394e2" d="
+ M 200.15 239.30
+ Q 199.98 239.49 199.91 239.72
+ Q 190.92 266.44 181.98 292.83
+ Q 181.80 293.36 181.25 293.42
+ Q 176.71 293.92 172.39 293.87
+ C 166.15 293.80 159.93 289.56 160.90 282.81
+ Q 161.80 276.57 164.01 268.60
+ Q 169.47 248.87 174.58 231.41
+ Q 174.76 230.79 174.25 230.39
+ C 170.74 227.62 169.70 222.70 173.14 219.43
+ Q 175.53 217.16 178.90 216.31
+ Q 179.43 216.17 179.60 215.65
+ C 188.07 190.47 198.22 165.41 207.05 141.43
+ Q 207.24 140.91 207.78 140.76
+ Q 214.30 138.92 220.72 138.67
+ C 224.53 138.52 232.31 139.24 233.17 143.99
+ Q 233.51 145.84 232.44 149.08
+ C 224.68 172.67 215.50 195.57 207.07 218.82
+ A 0.64 0.64 0.0 0 0 207.35 219.59
+ L 211.60 222.09
+ Q 212.17 222.43 212.81 222.25
+ C 242.01 213.94 258.94 191.09 259.57 161.35
+ C 259.78 151.79 255.66 143.78 248.81 137.59
+ C 236.44 126.42 215.46 127.01 200.49 130.37
+ Q 186.18 133.58 169.63 141.42
+ Q 158.46 146.72 150.07 153.36
+ Q 140.81 160.69 132.59 169.20
+ Q 128.68 173.25 125.52 178.05
+ A 0.69 0.68 -57.0 0 1 124.59 178.25
+ C 115.23 172.26 107.20 161.75 109.35 150.12
+ C 110.71 142.74 124.06 133.92 130.25 130.43
+ C 156.09 115.84 187.13 109.72 217.06 110.07
+ C 250.40 110.46 283.27 128.79 285.49 165.25
+ C 286.65 184.39 278.44 201.47 263.69 213.77
+ C 251.74 223.74 236.95 228.79 220.71 230.25
+ Q 219.94 230.32 220.40 230.94
+ C 227.40 240.58 231.36 251.96 235.49 263.05
+ Q 236.55 265.90 239.15 269.47
+ C 244.06 276.23 253.29 270.63 258.27 266.96
+ Q 272.44 256.50 284.36 240.68
+ Q 286.22 238.21 289.27 238.60
+ Q 290.61 238.77 291.02 240.90
+ A 2.48 2.47 -35.5 0 1 290.74 242.56
+ Q 284.53 253.43 275.84 264.63
+ C 269.24 273.15 261.27 281.27 251.72 286.33
+ Q 245.03 289.89 237.16 290.34
+ C 222.52 291.19 215.37 281.24 211.08 268.61
+ Q 205.76 252.95 200.75 239.42
+ Q 200.55 238.86 200.15 239.30
+ Z"
+/>
+</svg>
diff --git a/apps/web/scripts/bulk-delete-links.ts b/apps/web/scripts/bulk-delete-links.ts
index 028cfe71dd..c1ec4bc296 100644
--- a/apps/web/scripts/bulk-delete-links.ts
+++ b/apps/web/scripts/bulk-delete-links.ts
@@ -2,7 +2,7 @@ import "dotenv-flow/config";
import prisma from "@/lib/prisma";
import { redis } from "./utils";
-const domain = "steven.blue";
+const domain = "song.fyi";
async function main() {
const links = await prisma.link.findMany({
diff --git a/apps/web/ui/modals/import-bitly-modal.tsx b/apps/web/ui/modals/import-bitly-modal.tsx
index 18158fb94e..bb4eaf7dd3 100644
--- a/apps/web/ui/modals/import-bitly-modal.tsx
+++ b/apps/web/ui/modals/import-bitly-modal.tsx
@@ -1,6 +1,5 @@
import useProject from "@/lib/swr/use-project";
import { BitlyGroupProps } from "@/lib/types";
-import { ModalContext } from "@/ui/modals/provider";
import { Button, LoadingSpinner, Logo, Modal, Switch, Tooltip } from "@dub/ui";
import { HOME_DOMAIN, fetcher } from "@dub/utils";
import { ArrowRight } from "lucide-react";
@@ -9,7 +8,6 @@ import {
Dispatch,
SetStateAction,
useCallback,
- useContext,
useEffect,
useMemo,
useState,
diff --git a/apps/web/ui/modals/import-rebrandly-modal.tsx b/apps/web/ui/modals/import-rebrandly-modal.tsx
new file mode 100644
index 0000000000..7c3ca778f0
--- /dev/null
+++ b/apps/web/ui/modals/import-rebrandly-modal.tsx
@@ -0,0 +1,282 @@
+import { ImportedDomainCountProps } from "@/lib/types";
+import {
+ Button,
+ InfoTooltip,
+ LoadingSpinner,
+ Logo,
+ Modal,
+ SimpleTooltipContent,
+ Switch,
+} from "@dub/ui";
+import { fetcher, nFormatter } from "@dub/utils";
+import { ArrowRight } from "lucide-react";
+import { useParams, useRouter, useSearchParams } from "next/navigation";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useEffect,
+ useMemo,
+ useState,
+} from "react";
+import { toast } from "sonner";
+import useSWR, { mutate } from "swr";
+
+function ImportRebrandlyModal({
+ showImportRebrandlyModal,
+ setShowImportRebrandlyModal,
+}: {
+ showImportRebrandlyModal: boolean;
+ setShowImportRebrandlyModal: Dispatch<SetStateAction<boolean>>;
+}) {
+ const router = useRouter();
+ const { slug } = useParams() as { slug?: string };
+ const searchParams = useSearchParams();
+
+ const {
+ data: { domains, tagsCount } = {
+ domains: null,
+ tagsCount: null,
+ },
+ isLoading,
+ } = useSWR<{
+ domains: ImportedDomainCountProps[] | null;
+ tagsCount: number | null;
+ }>(
+ slug &&
+ showImportRebrandlyModal &&
+ `/api/projects/${slug}/import/rebrandly`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ revalidateOnMount: false,
+ revalidateOnReconnect: false,
+ refreshWhenOffline: false,
+ refreshWhenHidden: false,
+ refreshInterval: 0,
+ onError: (err) => {
+ if (err.message !== "No Rebrandly access token found") {
+ toast.error(err.message);
+ }
+ },
+ },
+ );
+
+ const [submitting, setSubmitting] = useState(false);
+
+ const [selectedDomains, setSelectedDomains] = useState<
+ ImportedDomainCountProps[]
+ >([]);
+ const [importTags, setImportTags] = useState<boolean>(false);
+
+ const [importing, setImporting] = useState(false);
+
+ useEffect(() => {
+ if (searchParams?.get("import") === "rebrandly") {
+ mutate(`/api/projects/${slug}/import/rebrandly`);
+ setShowImportRebrandlyModal(true);
+ } else {
+ setShowImportRebrandlyModal(false);
+ }
+ }, [searchParams]);
+
+ const isSelected = (domain: string) => {
+ return selectedDomains.find((d) => d.domain === domain) ? true : false;
+ };
+
+ return (
+ <Modal
+ showModal={showImportRebrandlyModal}
+ setShowModal={setShowImportRebrandlyModal}
+ onClose={() => router.push(`/${slug}`)}
+ >
+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-8 sm:px-16">
+ <div className="flex items-center space-x-3 py-4">
+ <img
+ src="/_static/icons/rebrandly.svg"
+ alt="Rebrandly logo"
+ className="h-12 w-12"
+ />
+ <ArrowRight className="h-5 w-5 text-gray-600" />
+ <Logo />
+ </div>
+ <h3 className="text-lg font-medium">Import Your Rebrandly Links</h3>
+ <p className="text-center text-sm text-gray-500">
+ Easily import all your existing Rebrandly links into{" "}
+ {process.env.NEXT_PUBLIC_APP_NAME} with just a few clicks.
+ </p>
+ </div>
+
+ <div className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16">
+ {isLoading ? (
+ <button className="flex flex-col items-center justify-center space-y-4 bg-none">
+ <LoadingSpinner />
+ <p className="text-sm text-gray-500">Connecting to Rebrandly</p>
+ </button>
+ ) : domains ? (
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ setImporting(true);
+ toast.promise(
+ fetch(`/api/projects/${slug}/import/rebrandly`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ selectedDomains,
+ importTags,
+ }),
+ }).then(async (res) => {
+ if (res.ok) {
+ await mutate(`/api/projects/${slug}/domains`);
+ router.push(`/${slug}`);
+ } else {
+ setImporting(false);
+ throw new Error();
+ }
+ }),
+ {
+ loading: "Adding links to import queue...",
+ success:
+ "Successfully added links to import queue! You can now safely navigate from this tab – we will send you an email when your links have been fully imported.",
+ error: "Error adding links to import queue",
+ },
+ );
+ }}
+ className="flex flex-col space-y-4"
+ >
+ <div className="flex flex-col space-y-2">
+ <p className="text-sm font-medium text-gray-700">Domains</p>
+ {domains.map(({ id, domain, links }) => (
+ <div className="flex items-center justify-between space-x-2 rounded-md border border-gray-200 bg-white px-4 py-2">
+ <div>
+ <p className="font-medium text-gray-800">{domain}</p>
+ {links > 0 && (
+ <p className="text-xs text-gray-500">
+ {nFormatter(links)} links found
+ </p>
+ )}
+ </div>
+ <Switch
+ fn={() => {
+ const selected = isSelected(domain);
+ if (selected) {
+ setSelectedDomains((prev) =>
+ prev.filter((d) => d.domain !== domain),
+ );
+ } else {
+ setSelectedDomains((prev) => [
+ ...prev,
+ {
+ id,
+ domain,
+ links,
+ },
+ ]);
+ }
+ }}
+ checked={isSelected(domain)}
+ />
+ </div>
+ ))}
+ {tagsCount && (
+ <div className="flex items-center justify-between space-x-2 rounded-md py-1 pl-2 pr-4">
+ <p className="text-xs text-gray-500">
+ {tagsCount} tags found. Import all?
+ </p>
+ <Switch
+ fn={() => setImportTags(!importTags)}
+ checked={importTags}
+ />
+ </div>
+ )}
+ </div>
+ <Button
+ text="Confirm import"
+ loading={importing}
+ disabled={selectedDomains.length === 0}
+ />
+ </form>
+ ) : (
+ // form to add API key to redis manually
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ setSubmitting(true);
+ fetch(`/api/projects/${slug}/import/rebrandly`, {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ apiKey: e.currentTarget.apiKey.value,
+ }),
+ }).then(async (res) => {
+ if (res.ok) {
+ await mutate(`/api/projects/${slug}/import/rebrandly`);
+ toast.success("Successfully added API key");
+ } else {
+ toast.error("Error adding API key");
+ }
+ setSubmitting(false);
+ });
+ }}
+ className="flex flex-col space-y-4"
+ >
+ <div>
+ <div className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Rebrandly API Key
+ </h2>
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title={`Your Rebrandly API Key can be found in your Rebrandly account under`}
+ cta="Account > API"
+ href="https://app.rebrandly.com/account/api"
+ />
+ }
+ />
+ </div>
+ <input
+ id="apiKey"
+ name="apiKey"
+ autoFocus
+ type="text"
+ placeholder="93467061146a64622df83c12bcc0bffb"
+ autoComplete="off"
+ required
+ className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
+ />
+ </div>
+ <Button text="Confirm API Key" loading={submitting} />
+ </form>
+ )}
+ </div>
+ </Modal>
+ );
+}
+
+export function useImportRebrandlyModal() {
+ const [showImportRebrandlyModal, setShowImportRebrandlyModal] =
+ useState(false);
+
+ const ImportRebrandlyModalCallback = useCallback(() => {
+ return (
+ <ImportRebrandlyModal
+ showImportRebrandlyModal={showImportRebrandlyModal}
+ setShowImportRebrandlyModal={setShowImportRebrandlyModal}
+ />
+ );
+ }, [showImportRebrandlyModal, setShowImportRebrandlyModal]);
+
+ return useMemo(
+ () => ({
+ setShowImportRebrandlyModal,
+ ImportRebrandlyModal: ImportRebrandlyModalCallback,
+ }),
+ [setShowImportRebrandlyModal, ImportRebrandlyModalCallback],
+ );
+}
diff --git a/apps/web/ui/modals/import-short-modal.tsx b/apps/web/ui/modals/import-short-modal.tsx
index 9f423ba8f7..8d7ae47649 100644
--- a/apps/web/ui/modals/import-short-modal.tsx
+++ b/apps/web/ui/modals/import-short-modal.tsx
@@ -1,5 +1,4 @@
-import { ShortioDomainProps } from "@/lib/types";
-import { ModalContext } from "@/ui/modals/provider";
+import { ImportedDomainCountProps } from "@/lib/types";
import {
Button,
InfoTooltip,
@@ -16,7 +15,6 @@ import {
Dispatch,
SetStateAction,
useCallback,
- useContext,
useEffect,
useMemo,
useState,
@@ -35,7 +33,7 @@ function ImportShortModal({
const { slug } = useParams() as { slug?: string };
const searchParams = useSearchParams();
- const { data: domains, isLoading } = useSWR<ShortioDomainProps[]>(
+ const { data: domains, isLoading } = useSWR<ImportedDomainCountProps[]>(
slug && showImportShortModal && `/api/projects/${slug}/import/short`,
fetcher,
{
@@ -55,9 +53,9 @@ function ImportShortModal({
const [submitting, setSubmitting] = useState(false);
- const [selectedDomains, setSelectedDomains] = useState<ShortioDomainProps[]>(
- [],
- );
+ const [selectedDomains, setSelectedDomains] = useState<
+ ImportedDomainCountProps[]
+ >([]);
const [importing, setImporting] = useState(false);
diff --git a/apps/web/ui/modals/provider.tsx b/apps/web/ui/modals/provider.tsx
index 8ab71e3089..cdb518196e 100644
--- a/apps/web/ui/modals/provider.tsx
+++ b/apps/web/ui/modals/provider.tsx
@@ -16,12 +16,12 @@ import {
SetStateAction,
createContext,
useEffect,
- useState,
} from "react";
import { mutate } from "swr";
import { useCookies } from "@dub/ui";
import { SimpleLinkProps } from "@/lib/types";
import { toast } from "sonner";
+import { useImportRebrandlyModal } from "./import-rebrandly-modal";
export const ModalContext = createContext<{
setShowAddProjectModal: Dispatch<SetStateAction<boolean>>;
@@ -31,6 +31,7 @@ export const ModalContext = createContext<{
setShowUpgradePlanModal: Dispatch<SetStateAction<boolean>>;
setShowImportBitlyModal: Dispatch<SetStateAction<boolean>>;
setShowImportShortModal: Dispatch<SetStateAction<boolean>>;
+ setShowImportRebrandlyModal: Dispatch<SetStateAction<boolean>>;
}>({
setShowAddProjectModal: () => {},
setShowCompleteSetupModal: () => {},
@@ -39,6 +40,7 @@ export const ModalContext = createContext<{
setShowUpgradePlanModal: () => {},
setShowImportBitlyModal: () => {},
setShowImportShortModal: () => {},
+ setShowImportRebrandlyModal: () => {},
});
export default function ModalProvider({ children }: { children: ReactNode }) {
@@ -53,6 +55,8 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
const { setShowUpgradePlanModal, UpgradePlanModal } = useUpgradePlanModal();
const { setShowImportBitlyModal, ImportBitlyModal } = useImportBitlyModal();
const { setShowImportShortModal, ImportShortModal } = useImportShortModal();
+ const { setShowImportRebrandlyModal, ImportRebrandlyModal } =
+ useImportRebrandlyModal();
const params = useParams() as { slug?: string };
const { slug } = params;
@@ -102,6 +106,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
setShowUpgradePlanModal,
setShowImportBitlyModal,
setShowImportShortModal,
+ setShowImportRebrandlyModal,
}}
>
<AddProjectModal />
@@ -112,6 +117,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
<UpgradePlanModal />
<ImportBitlyModal />
<ImportShortModal />
+ <ImportRebrandlyModal />
{children}
</ModalContext.Provider>
);