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.

Add uploadedImageSchema

Steven Tey24dc9db9a0de
diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.ts
index 9ae9063269..ae527225c2 100644
--- a/apps/web/app/api/user/route.ts
+++ b/apps/web/app/api/user/route.ts
@@ -2,7 +2,7 @@ import { DubApiError } from "@/lib/api/errors";
import { hashToken, withSession } from "@/lib/auth";
import { storage } from "@/lib/storage";
import { ratelimit, redis } from "@/lib/upstash";
-import { base64ImageSchema } from "@/lib/zod/schemas/misc";
+import { uploadedImageSchema } from "@/lib/zod/schemas/misc";
import { sendEmail } from "@dub/email";
import { unsubscribe } from "@dub/email/resend/unsubscribe";
import ConfirmEmailChange from "@dub/email/templates/confirm-email-change";
@@ -16,7 +16,7 @@ import { z } from "zod";
const updateUserSchema = z.object({
name: z.preprocess(trim, z.string().min(1).max(64)).optional(),
email: z.preprocess(trim, z.string().email()).optional(),
- image: base64ImageSchema.nullish(),
+ image: uploadedImageSchema.nullish(),
source: z.preprocess(trim, z.string().min(1).max(32)).optional(),
defaultWorkspace: z.preprocess(trim, z.string().min(1)).optional(),
});
diff --git a/apps/web/lib/actions/partners/program-resources/add-program-resource.ts b/apps/web/lib/actions/partners/program-resources/add-program-resource.ts
index df54da586e..a65cd8726b 100644
--- a/apps/web/lib/actions/partners/program-resources/add-program-resource.ts
+++ b/apps/web/lib/actions/partners/program-resources/add-program-resource.ts
@@ -2,7 +2,7 @@
import { createId } from "@/lib/api/create-id";
import { storage } from "@/lib/storage";
-import { base64ImageSchema } from "@/lib/zod/schemas/misc";
+import { uploadedImageSchema } from "@/lib/zod/schemas/misc";
import {
programResourceColorSchema,
programResourceFileSchema,
@@ -23,7 +23,7 @@ const baseResourceSchema = z.object({
// Schema for logo resources
const logoResourceSchema = baseResourceSchema.extend({
resourceType: z.literal("logo"),
- file: base64ImageSchema,
+ file: uploadedImageSchema,
extension: z.string().nullish(),
});
diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.ts
index 7a137112dd..eda2a0caf5 100644
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@ -13,13 +13,13 @@ import { PartnerProfileType } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { stripe } from "../../stripe";
import z from "../../zod";
-import { base64ImageSchema } from "../../zod/schemas/misc";
+import { uploadedImageSchema } from "../../zod/schemas/misc";
import { authPartnerActionClient } from "../safe-action";
const updatePartnerProfileSchema = z
.object({
name: z.string(),
- image: base64ImageSchema.nullish(),
+ image: uploadedImageSchema.nullish(),
description: z.string().nullable(),
country: z.enum(Object.keys(COUNTRIES) as [string, ...string[]]).nullable(),
profileType: z.nativeEnum(PartnerProfileType),
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index df66b730b1..ef7ba2ca38 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -1,9 +1,9 @@
import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import z from "@/lib/zod";
import {
- base64ImageSchema,
booleanQuerySchema,
getPaginationQuerySchema,
+ uploadedImageSchema,
} from "./misc";
import { parseUrlSchemaAllowEmpty } from "./utils";
@@ -144,7 +144,7 @@ export const createDomainBodySchema = z.object({
"Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened.",
)
.openapi({ example: "https://dub.co/help/article/what-is-dub" }),
- logo: base64ImageSchema.nullish().describe("The logo of the domain."),
+ logo: uploadedImageSchema.nullish().describe("The logo of the domain."),
assetLinks: z
.string()
.nullish()
diff --git a/apps/web/lib/zod/schemas/integration.ts b/apps/web/lib/zod/schemas/integration.ts
index 3f8be33d0f..856f89e1cf 100644
--- a/apps/web/lib/zod/schemas/integration.ts
+++ b/apps/web/lib/zod/schemas/integration.ts
@@ -1,6 +1,6 @@
import { R2_URL } from "@dub/utils";
import { z } from "zod";
-import { base64ImageSchema } from "./misc";
+import { uploadedImageSchema } from "./misc";
export const integrationSchema = z.object({
id: z.string(),
@@ -38,7 +38,7 @@ export const createIntegrationSchema = z.object({
message: "installUrl must be a valid URL",
})
.nullish(),
- logo: base64ImageSchema.nullish().describe("The logo of the integration."),
+ logo: uploadedImageSchema.nullish().describe("The logo of the integration."),
description: z
.string()
.max(120, {
diff --git a/apps/web/lib/zod/schemas/misc.ts b/apps/web/lib/zod/schemas/misc.ts
index 17fbeaa10b..0a65a29acd 100644
--- a/apps/web/lib/zod/schemas/misc.ts
+++ b/apps/web/lib/zod/schemas/misc.ts
@@ -75,3 +75,16 @@ export const base64ImageSchema = z
},
)
.transform((v) => v || null);
+
+// Base64 encoded image or dubassets.com URL
+export const uploadedImageSchema = z
+ .union([
+ base64ImageSchema,
+ z
+ .string()
+ .url()
+ .refine((url) => url.startsWith("https://dubassets.com"), {
+ message: "URL must start with https://dubassets.com",
+ }),
+ ])
+ .transform((v) => v || null);
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index d32d207ad4..a799fd766f 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -2,7 +2,7 @@ import z from "@/lib/zod";
import { DEFAULT_REDIRECTS, RESERVED_SLUGS, validSlugRegex } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
import { DomainSchema } from "./domains";
-import { base64ImageSchema, planSchema, roleSchema } from "./misc";
+import { planSchema, roleSchema, uploadedImageSchema } from "./misc";
export const workspaceIdSchema = z.object({
workspaceId: z
@@ -139,7 +139,7 @@ export const createWorkspaceSchema = z.object({
message: "Cannot use reserved slugs",
},
),
- logo: base64ImageSchema.nullish(),
+ logo: uploadedImageSchema.nullish(),
conversionEnabled: z.boolean().optional(),
});