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.

update implementation

Steven Teyea61cb3f3910
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index 28842f22e1..2c66857bcb 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -1,6 +1,5 @@
import {
addDomainToVercel,
- changeDomainForImages,
deleteDomainAndLinks,
removeDomainFromVercel,
setRootDomain,
@@ -95,12 +94,6 @@ export const PUT = withAuth(async ({ req, project, domain }) => {
archived,
},
}),
- ...(newDomain !== domain
- ? [
- removeDomainFromVercel(domain),
- changeDomainForImages(domain, newDomain),
- ]
- : []),
// if the domain is being set as the primary domain, set the current primary domain to false
primary &&
prisma.domain.updateMany({
@@ -112,6 +105,8 @@ export const PUT = withAuth(async ({ req, project, domain }) => {
primary: false,
},
}),
+ // remove old domain from Vercel
+ newDomain !== domain && removeDomainFromVercel(domain),
]);
await setRootDomain({
diff --git a/apps/web/lib/api/domains.ts b/apps/web/lib/api/domains.ts
index 8f1ab3d019..0148a0745c 100644
--- a/apps/web/lib/api/domains.ts
+++ b/apps/web/lib/api/domains.ts
@@ -7,7 +7,6 @@ import {
validDomainRegex,
} from "@dub/utils";
import cloudinary from "cloudinary";
-import { r2 } from "../r2";
import { recordLink } from "../tinybird";
export const validateDomain = async (domain: string) => {
@@ -204,28 +203,6 @@ export async function setRootDomain({
]);
}
-/* Change the domain for all images for a given project on Cloudinary */
-export async function changeDomainForImages(domain: string, newDomain: string) {
- const links = await prisma.link.findMany({
- where: {
- domain,
- },
- select: {
- key: true,
- },
- });
- if (links.length === 0) return null;
- try {
- return await Promise.all(
- links.map(({ key }) =>
- r2.rename(`${domain}/${key}`, `${newDomain}/${key}`),
- ),
- );
- } catch (e) {
- return null;
- }
-}
-
/* Delete a domain and all links & images associated with it */
export async function deleteDomainAndLinks(
domain: string,
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 90054fa21f..9d617e8b5a 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -748,7 +748,7 @@ export async function editLink({
}
} else {
// if there's no proxy enabled or no image, delete the image in R2
- await r2.delete(`${domain}/${key}`);
+ await r2.delete(`images/${id}`);
}
const [response, ..._effects] = await Promise.all([
@@ -843,7 +843,7 @@ export async function deleteLink(linkId: string) {
id: link.id,
},
}),
- r2.delete(`${link.domain}/${link.key}`),
+ r2.delete(`images/${link.id}`),
redis.hdel(link.domain, link.key.toLowerCase()),
recordLink({ link, deleted: true }),
link.projectId &&
diff --git a/apps/web/lib/api/projects.ts b/apps/web/lib/api/projects.ts
index c11a5d00e9..a555c3c07a 100644
--- a/apps/web/lib/api/projects.ts
+++ b/apps/web/lib/api/projects.ts
@@ -26,6 +26,7 @@ export async function deleteProject(
},
},
select: {
+ id: true,
domain: true,
key: true,
proxy: true,
@@ -60,8 +61,8 @@ export async function deleteProject(
// delete all default domain links from redis
pipeline.exec(),
// remove all images from R2
- ...defaultDomainLinks.map(({ domain, key, proxy }) =>
- proxy ? r2.delete(`${domain}/${key}`) : Promise.resolve(),
+ ...defaultDomainLinks.map(({ id, proxy }) =>
+ proxy ? r2.delete(`images/${id}`) : Promise.resolve(),
),
]);