The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
only delete old image when editing link if old image is not the same as the new one
Steven Tey845a083fec41
diff --git a/apps/web/app/api/links/bulk/route.ts b/apps/web/app/api/links/bulk/route.tsindex 99a6868baa..3babcb9882 100644--- a/apps/web/app/api/links/bulk/route.ts+++ b/apps/web/app/api/links/bulk/route.ts@@ -249,17 +249,22 @@ export const PATCH = withWorkspace(async ({ req, workspace, headers }) => {: [];waitUntil(- Promise.allSettled(- links.map(async (link) => {- // delete old proxy image urls if exist and match the link ID- if (- link.image &&- link.image.startsWith(`${R2_URL}/images/${link.id}`)- ) {- storage.delete(link.image.replace(`${R2_URL}/`, ""));- }- }),- ),+ (async () => {+ if (data.proxy && data.image) {+ await Promise.allSettled(+ links.map(async (link) => {+ // delete old proxy image urls if exist and match the link ID+ if (+ link.image &&+ link.image.startsWith(`${R2_URL}/images/${link.id}`) &&+ link.image !== data.image+ ) {+ storage.delete(link.image.replace(`${R2_URL}/`, ""));+ }+ }),+ );+ }+ })(),);return NextResponse.json([...response, ...errorLinks], { headers });diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.tsindex eb1d9877e9..aa8fcc0acd 100644--- a/apps/web/lib/api/links/bulk-update-links.ts+++ b/apps/web/lib/api/links/bulk-update-links.ts@@ -40,6 +40,7 @@ export async function bulkUpdateLinks(data: {...rest,url,+ proxy,title: truncate(title, 120),description: truncate(description, 240),image:diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.tsindex 61925c6213..184042b730 100644--- a/apps/web/lib/api/links/update-link.ts+++ b/apps/web/lib/api/links/update-link.ts@@ -141,9 +141,10 @@ export async function updateLink({width: 1200,height: 630,}),- // if there's a valid old image and it has the same link ID, delete it+ // if there's a valid old image and it starts with the same link ID but is different from the new image, delete itoldLink.image &&oldLink.image.startsWith(`${R2_URL}/images/${id}`) &&+ oldLink.image !== image &&storage.delete(oldLink.image.replace(`${R2_URL}/`, "")),]),);