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.

Make R2_URL URL dynamic

Kiran K52c23212ffdb
diff --git a/apps/web/.env.example b/apps/web/.env.example
index 70dde12438..09839034ba 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -95,6 +95,7 @@ UNSPLASH_ACCESS_KEY=
STORAGE_ACCESS_KEY_ID=
STORAGE_SECRET_ACCESS_KEY=
STORAGE_ENDPOINT=
+STORAGE_BASE_URL=
# Used for internal monitoring & paging
# You can remove this by removing `DUB_SLACK_HOOK_CRON` and `DUB_SLACK_HOOK_LINKS` from the codebase
diff --git a/apps/web/lib/zod/schemas/misc.ts b/apps/web/lib/zod/schemas/misc.ts
index 0a65a29acd..65521c96d9 100644
--- a/apps/web/lib/zod/schemas/misc.ts
+++ b/apps/web/lib/zod/schemas/misc.ts
@@ -1,5 +1,6 @@
import { plans, roles } from "@/lib/types";
import z from "@/lib/zod";
+import { R2_URL } from "@dub/utils";
export const RECURRING_MAX_DURATIONS = [0, 3, 6, 12, 18, 24];
@@ -76,15 +77,15 @@ export const base64ImageSchema = z
)
.transform((v) => v || null);
-// Base64 encoded image or dubassets.com URL
+// Base64 encoded image or R2_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",
+ .refine((url) => url.startsWith(R2_URL), {
+ message: `URL must start with ${R2_URL}`,
}),
])
.transform((v) => v || null);
diff --git a/packages/utils/src/constants/main.ts b/packages/utils/src/constants/main.ts
index 2948f35c80..7cfa86159d 100644
--- a/packages/utils/src/constants/main.ts
+++ b/packages/utils/src/constants/main.ts
@@ -74,4 +74,4 @@ export const ACME_PROGRAM_ID = "prog_CYCu7IMAapjkRpTnr8F1azjN";
export const LEGAL_WORKSPACE_ID = "clrflia0j0000vs7sqfhz9c7q";
export const LEGAL_USER_ID = "clqei1lgc0000vsnzi01pbf47";
-export const R2_URL = "https://dubassets.com";
+export const R2_URL = process.env.STORAGE_BASE_URL || "https://dubassets.com";