The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
remove old logo
Kiran K78ed028c8752
diff --git a/apps/web/app/api/oauth/apps/[appId]/route.ts b/apps/web/app/api/oauth/apps/[appId]/route.tsindex 0b087097ca..383d7da811 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 { waitUntil } from "@vercel/functions";import { NextResponse } from "next/server";// GET /api/oauth/apps/[appId] – get an OAuth app created by the workspace@@ -48,9 +49,21 @@ export const PATCH = withWorkspace(} = updateOAuthAppSchema.parse(await parseRequestBody(req));try {+ const app = await prisma.oAuthApp.findUniqueOrThrow({+ where: {+ id: params.appId,+ projectId: workspace.id,+ },+ select: {+ logo: true,+ },+ });+let logoUrl: string | undefined;+ const logoUpdated = logo && app.logo !== logo;- if (logo && !logo.startsWith(R2_URL)) {+ // Logo has been changed+ if (logoUpdated) {const result = await storage.upload(`integrations/${params.appId}_${nanoid(7)}`,logo,@@ -59,7 +72,7 @@ export const PATCH = withWorkspace(logoUrl = result.url;}- const app = await prisma.oAuthApp.update({+ const updatedApp = await prisma.oAuthApp.update({where: {id: params.appId,projectId: workspace.id,@@ -77,7 +90,19 @@ export const PATCH = withWorkspace(},});- return NextResponse.json(oAuthAppSchema.parse(app));+ waitUntil(+ (async () => {+ if (+ logoUpdated &&+ app.logo &&+ app.logo.startsWith(`${R2_URL}/integrations`)+ ) {+ await storage.delete(app.logo.replace(`${R2_URL}/`, ""));+ }+ })(),+ );++ return NextResponse.json(oAuthAppSchema.parse(updatedApp));} catch (error) {if (error.code === "P2002") {throw new DubApiError({@@ -121,6 +146,14 @@ export const DELETE = withWorkspace(},});+ waitUntil(+ (async () => {+ if (app.logo && app.logo.startsWith(`${R2_URL}/integrations`)) {+ await storage.delete(app.logo.replace(`${R2_URL}/`, ""));+ }+ })(),+ );+return NextResponse.json({ id: params.appId });},{