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.

upload logo

Kiran K5c735f27a5f4
diff --git a/apps/web/app/api/oauth/apps/[appId]/route.ts b/apps/web/app/api/oauth/apps/[appId]/route.ts
index 5a31463f41..0b087097ca 100644
--- a/apps/web/app/api/oauth/apps/[appId]/route.ts
+++ b/apps/web/app/api/oauth/apps/[appId]/route.ts
@@ -2,7 +2,9 @@ import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
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 { NextResponse } from "next/server";
// GET /api/oauth/apps/[appId] – get an OAuth app created by the workspace
@@ -46,6 +48,17 @@ export const PATCH = withWorkspace(
} = updateOAuthAppSchema.parse(await parseRequestBody(req));
try {
+ let logoUrl: string | undefined;
+
+ if (logo && !logo.startsWith(R2_URL)) {
+ const result = await storage.upload(
+ `integrations/${params.appId}_${nanoid(7)}`,
+ logo,
+ );
+
+ logoUrl = result.url;
+ }
+
const app = await prisma.oAuthApp.update({
where: {
id: params.appId,
@@ -59,10 +72,11 @@ export const PATCH = withWorkspace(
description,
readme,
redirectUris,
- logo,
pkce,
+ ...(logoUrl && { logo: logoUrl }),
},
});
+
return NextResponse.json(oAuthAppSchema.parse(app));
} catch (error) {
if (error.code === "P2002") {
diff --git a/apps/web/app/api/oauth/apps/route.ts b/apps/web/app/api/oauth/apps/route.ts
index ecb40a21a6..3375382d78 100644
--- a/apps/web/app/api/oauth/apps/route.ts
+++ b/apps/web/app/api/oauth/apps/route.ts
@@ -4,7 +4,9 @@ import { createToken } from "@/lib/api/oauth/utils";
import { parseRequestBody } from "@/lib/api/utils";
import { hashToken, withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
+import { storage } from "@/lib/storage";
import { createOAuthAppSchema, oAuthAppSchema } from "@/lib/zod/schemas/oauth";
+import { nanoid } from "@dub/utils";
import { NextResponse } from "next/server";
import { z } from "zod";
@@ -74,8 +76,21 @@ export const POST = withWorkspace(
});
try {
- const client = await prisma.oAuthApp.create({
+ let logoUrl: string | undefined;
+ const appId = nanoid(25);
+
+ if (logo) {
+ const result = await storage.upload(
+ `integrations/${appId}_${nanoid(7)}`,
+ logo,
+ );
+
+ logoUrl = result.url;
+ }
+
+ const app = await prisma.oAuthApp.create({
data: {
+ id: appId,
projectId: workspace.id,
name,
slug,
@@ -84,18 +99,18 @@ export const POST = withWorkspace(
description,
readme,
redirectUris,
- logo,
clientId,
hashedClientSecret: await hashToken(clientSecret),
partialClientSecret: `dub_app_secret_****${clientSecret.slice(-8)}`,
userId: session.user.id,
pkce,
+ ...(logoUrl && { logo: logoUrl }),
},
});
return NextResponse.json(
{
- ...oAuthAppSchema.parse(client),
+ ...oAuthAppSchema.parse(app),
clientSecret,
},
{ status: 201 },
diff --git a/apps/web/lib/edge-config/get-feature-flags.ts b/apps/web/lib/edge-config/get-feature-flags.ts
index 81dcbfe6cd..ad94a82dc6 100644
--- a/apps/web/lib/edge-config/get-feature-flags.ts
+++ b/apps/web/lib/edge-config/get-feature-flags.ts
@@ -6,7 +6,7 @@ type BetaFeaturesRecord = Record<BetaFeatures, string[]>;
export const getFeatureFlags = async (workspaceId: string) => {
const workspaceFeatures: Record<BetaFeatures, boolean> = {
conversions: false,
- integrations: false,
+ integrations: true,
dublink: false,
};
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index adc320a8c6..26c2fbfd77 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -16,7 +16,6 @@ export const createOAuthAppSchema = z.object({
.url({
message: "Please provide a valid URL for the logo",
})
- .max(190)
.nullable(),
redirectUris: z
.string()
diff --git a/apps/web/ui/integrations/add-edit-integration-form.tsx b/apps/web/ui/integrations/add-edit-integration-form.tsx
index 41e8d52733..dc1d2cf8fa 100644
--- a/apps/web/ui/integrations/add-edit-integration-form.tsx
+++ b/apps/web/ui/integrations/add-edit-integration-form.tsx
@@ -6,7 +6,7 @@ import {
NewIntegration,
OAuthAppProps,
} from "@/lib/types";
-import { Button, InfoTooltip, Switch } from "@dub/ui";
+import { Button, FileUpload, InfoTooltip, Switch } from "@dub/ui";
import { nanoid } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
import { redirect, useRouter } from "next/navigation";
@@ -24,7 +24,7 @@ const defaultValues: NewIntegration = {
website: "",
partialClientSecret: "",
redirectUris: [],
- logo: "",
+ logo: null,
pkce: true,
createdAt: new Date(),
updatedAt: new Date(),
@@ -136,6 +136,23 @@ export default function AddEditIntegrationForm({
onSubmit={onSubmit}
className="flex flex-col space-y-5 pb-20 text-left"
>
+ <div>
+ <FileUpload
+ accept="images"
+ className="h-24 w-24 rounded-full border border-gray-300"
+ iconClassName="w-5 h-5"
+ variant="plain"
+ readFile
+ imageSrc={
+ logo ||
+ `https://api.dicebear.com/7.x/shapes/svg?seed=${integration?.clientId}`
+ }
+ onChange={({ src }) => setData({ ...data, logo: src })}
+ content={null}
+ maxFileSizeMB={2}
+ />
+ </div>
+
<div>
<label htmlFor="name" className="flex items-center space-x-2">
<h2 className="text-sm font-medium text-gray-900">
@@ -250,22 +267,6 @@ export default function AddEditIntegrationForm({
</div>
</div>
- <div>
- <label htmlFor="logo" className="flex items-center space-x-2">
- <h2 className="text-sm font-medium text-gray-900">Logo URL</h2>
- <InfoTooltip content="URL to your application's logo" />
- </label>
- <div className="relative mt-2 rounded-md shadow-sm">
- <input
- className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
- type="url"
- value={logo || ""}
- onChange={(e) => setData({ ...data, logo: e.target.value })}
- placeholder="https://acme.com/logo.png"
- />
- </div>
- </div>
-
<div>
<div className="flex items-center justify-between">
<label