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.

Show file extension in resource descriptions (#2988)

Marcus Farrell98b68b1d89d0
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx b/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx
index 877143546f..245eab7aa6 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx
@@ -2,7 +2,12 @@ import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
import { ResourceCard } from "@/ui/partners/resources/resource-card";
import { ResourceSection } from "@/ui/partners/resources/resource-section";
import { FileContent, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/ui";
-import { formatFileSize, getApexDomain, GOOGLE_FAVICON_URL } from "@dub/utils";
+import {
+ formatFileSize,
+ getApexDomain,
+ getFileExtension,
+ GOOGLE_FAVICON_URL,
+} from "@dub/utils";
import { motion } from "motion/react";
import { z } from "zod";
@@ -32,7 +37,7 @@ export function ReferralsEmbedResources({
</div>
}
title={logo.name || "Logo"}
- description={formatFileSize(logo.size, 0)}
+ description={`${getFileExtension(logo.url) || "Unknown"}・${formatFileSize(logo.size, 0)}`}
downloadUrl={logo.url}
/>
))}
@@ -94,7 +99,7 @@ export function ReferralsEmbedResources({
</div>
}
title={file.name || "File"}
- description={formatFileSize(file.size, 0)}
+ description={`${getFileExtension(file.url) || "Unknown"}・${formatFileSize(file.size, 0)}`}
downloadUrl={file.url}
/>
))}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page-client.tsx
index 0c584e4c1d..0789ee2440 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page-client.tsx
@@ -9,6 +9,7 @@ import { FileContent, FileZip2, Link4, Palette2, Post } from "@dub/ui/icons";
import {
formatFileSize,
getApexDomain,
+ getFileExtension,
getPrettyUrl,
GOOGLE_FAVICON_URL,
} from "@dub/utils";
@@ -49,7 +50,7 @@ export function ResourcesPageClient() {
</div>
}
title={logo.name || "Logo"}
- description={formatFileSize(logo.size, 0)}
+ description={`${getFileExtension(logo.url) || "Unknown"}・${formatFileSize(logo.size, 0)}`}
downloadUrl={logo.url}
/>
))}
@@ -126,7 +127,7 @@ export function ResourcesPageClient() {
</div>
}
title={file.name || "File"}
- description={formatFileSize(file.size, 0)}
+ description={`${getFileExtension(file.url) || "Unknown"}・${formatFileSize(file.size, 0)}`}
downloadUrl={file.url}
/>
))}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx
index c50f4cf87b..13a7bb93f3 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx
@@ -10,6 +10,7 @@ import {
capitalize,
formatFileSize,
getApexDomain,
+ getFileExtension,
getPrettyUrl,
GOOGLE_FAVICON_URL,
} from "@dub/utils";
@@ -106,7 +107,7 @@ export function ProgramBrandAssets() {
</div>
}
title={logo.name || "Logo"}
- description={formatFileSize(logo.size, 0)}
+ description={`${getFileExtension(logo.url) || "Unknown"}・${formatFileSize(logo.size, 0)}`}
downloadUrl={logo.url}
onDelete={() => handleDelete("logo", logo.id)}
/>
@@ -232,7 +233,7 @@ export function ProgramBrandAssets() {
</div>
}
title={file.name || "File"}
- description={formatFileSize(file.size, 0)}
+ description={`${getFileExtension(file.url) || "Unknown"}・${formatFileSize(file.size, 0)}`}
downloadUrl={file.url}
onDelete={() => handleDelete("file", file.id)}
/>
diff --git a/packages/utils/src/functions/urls.ts b/packages/utils/src/functions/urls.ts
index 5e41426544..0b1869a249 100644
--- a/packages/utils/src/functions/urls.ts
+++ b/packages/utils/src/functions/urls.ts
@@ -198,3 +198,15 @@ export function buildUrl(
return url.toString();
}
+
+export const getFileExtension = (url: string): string | null => {
+ try {
+ const pathname = new URL(url).pathname;
+ const extension = pathname.split(".").pop();
+ return extension ? extension.toUpperCase() : null;
+ } catch {
+ // If URL parsing fails, try to extract from the string directly
+ const extension = url.split(".").pop()?.split("?")[0];
+ return extension ? extension.toUpperCase() : null;
+ }
+};