The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix removing screenshots
Kiran Kf615f4d8377d
diff --git a/apps/web/app/api/oauth/apps/[appId]/route.ts b/apps/web/app/api/oauth/apps/[appId]/route.tsindex d53d000540..0d3bedf713 100644--- a/apps/web/app/api/oauth/apps/[appId]/route.ts+++ b/apps/web/app/api/oauth/apps/[appId]/route.ts@@ -5,6 +5,7 @@ import { prisma } from "@/lib/prisma";import { storage } from "@/lib/storage";import { oAuthAppSchema, updateOAuthAppSchema } from "@/lib/zod/schemas/oauth";import { nanoid, R2_URL } from "@dub/utils";+import { Prisma } from "@prisma/client";import { waitUntil } from "@vercel/functions";import { NextResponse } from "next/server";@@ -57,6 +58,7 @@ export const PATCH = withWorkspace(},select: {logo: true,+ screenshots: true,},});@@ -101,6 +103,17 @@ export const PATCH = withWorkspace() {await storage.delete(app.logo.replace(`${R2_URL}/`, ""));}++ // Remove old screenshots+ const oldScreenshots = app.screenshots+ ? (app.screenshots as string[])+ : [];++ const removedScreenshots = oldScreenshots?.filter(+ (s) => !screenshots?.includes(s),+ );++ await deleteScreenshots(removedScreenshots);})(),);@@ -153,6 +166,8 @@ export const DELETE = withWorkspace(if (app.logo && app.logo.startsWith(`${R2_URL}/integrations`)) {await storage.delete(app.logo.replace(`${R2_URL}/`, ""));}++ await deleteScreenshots(app.screenshots);})(),);@@ -163,3 +178,21 @@ export const DELETE = withWorkspace(featureFlag: "integrations",},);++const deleteScreenshots = async (screenshots: Prisma.JsonValue | null) => {+ console.log("To delete screenshots", screenshots);++ const images = screenshots as string[];++ if (!images || images.length === 0) {+ return;+ }++ await Promise.all(+ images.map(async (image: string) => {+ if (image.startsWith(`${R2_URL}/integration-screenshots`)) {+ return storage.delete(image.replace(`${R2_URL}/`, ""));+ }+ }),+ );+};diff --git a/apps/web/app/api/oauth/apps/screenshots/upload/route.ts b/apps/web/app/api/oauth/apps/screenshots/upload/route.tsindex 98a068122a..102c7b8dd2 100644--- a/apps/web/app/api/oauth/apps/screenshots/upload/route.ts+++ b/apps/web/app/api/oauth/apps/screenshots/upload/route.ts@@ -17,9 +17,7 @@ export const GET = withWorkspace(async ({ searchParams }) => {const key = `integration-screenshots/${nanoid(7)}/${name}`;- const signedUrl = await storage.getSignedUrl({- key,- });+ const signedUrl = await storage.getSignedUrl(key);return NextResponse.json({ key, signedUrl });});diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsxindex 08f1cdc5e3..8688bc111a 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx@@ -100,6 +100,7 @@ export default function IntegrationPageClient({</Popover>)}</div>+<div className="flex gap-12 rounded-lg border border-gray-200 bg-white p-4">{integration.installed && (<div className="flex items-center gap-2">@@ -139,7 +140,7 @@ export default function IntegrationPageClient({<div className="w-full rounded-lg border border-gray-200 bg-white"><div className="flex items-center gap-x-2 border-b border-gray-200 px-6 py-4"><BookOpenText className="size-4" />- <p className="text-sm font-medium text-gray-700">README</p>+ <p className="text-sm font-medium text-gray-700">Overview</p></div>{integration.screenshots?.length && (@@ -152,7 +153,7 @@ export default function IntegrationPageClient({alt={`Screenshot of ${integration.name}`}width={2880}height={1640}- className="aspect-[2880/1640] w-[5/6] overflow-hidden rounded-t-2xl border border-gray-200 object-cover"+ className="aspect-[2880/1640] w-[5/6] overflow-hidden rounded-md border border-gray-200 object-cover"/></CarouselItem>))}diff --git a/apps/web/lib/storage.ts b/apps/web/lib/storage.tsindex 9ebe1ca93c..32e3ea7639 100644--- a/apps/web/lib/storage.ts+++ b/apps/web/lib/storage.ts@@ -61,7 +61,7 @@ class StorageClient {return { success: true };}- async getSignedUrl({ key }: { key: string }) {+ async getSignedUrl(key: string) {const url = new URL(`${process.env.STORAGE_ENDPOINT}/${key}`);// 10 minutes expiration