Skip to content

Commit d982a49

Browse files
committed
fix(file-manager,esigner): display user-friendly file type labels (DOCX, XLSX, PDF) instead of raw MIME
- Add getMimeTypeDisplayLabel() in both apps: map long MIME types to short labels (XLSX, DOCX, PPTX, PDF) with fallback for unknown types - File Manager files/[id]: use for Type in subtitle and Details - eSigner files/[id]: use for Type in preview area and File Information
1 parent 75e6548 commit d982a49

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Returns a short, user-friendly label for a MIME type (e.g. DOCX, XLSX, PDF)
3+
* instead of long strings like application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
4+
*/
5+
export function getMimeTypeDisplayLabel(mimeType: string): string {
6+
if (!mimeType || typeof mimeType !== "string") return mimeType ?? "";
7+
const m = mimeType.toLowerCase();
8+
// Office / common document types
9+
if (m.includes("spreadsheetml.sheet") || m.includes("ms-excel")) return "XLSX";
10+
if (m.includes("wordprocessingml.document") || m.includes("msword")) return "DOCX";
11+
if (m.includes("presentationml") || m.includes("ms-powerpoint")) return "PPTX";
12+
if (m === "application/pdf") return "PDF";
13+
// Generic fallback: last meaningful part
14+
const parts = m.split(/[/+]/);
15+
const last = parts[parts.length - 1];
16+
if (last && last !== "application" && last.length <= 20) return last.toUpperCase();
17+
return mimeType;
18+
}

platforms/esigner/src/routes/(protected)/files/[id]/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { PUBLIC_ESIGNER_BASE_URL } from '$env/static/public';
1010
import { toast } from '$lib/stores/toast';
1111
import { isMobileDevice, getDeepLinkUrl } from '$lib/utils/mobile-detection';
12+
import { getMimeTypeDisplayLabel } from '$lib/utils/mime-type';
1213
1314
let file = $state<any>(null);
1415
let invitations = $state<any[]>([]);
@@ -376,7 +377,7 @@
376377
<div class="bg-white rounded-lg shadow-lg p-6 sm:p-12 text-center max-w-md">
377378
<div class="text-4xl sm:text-6xl mb-4">📄</div>
378379
<p class="text-gray-600 mb-2">Preview not available for this file type</p>
379-
<p class="text-sm text-gray-500">{file.mimeType}</p>
380+
<p class="text-sm text-gray-500">{getMimeTypeDisplayLabel(file.mimeType || '')}</p>
380381
<button
381382
onclick={() => showDownloadModal = true}
382383
class="inline-block mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-sm"
@@ -449,7 +450,7 @@
449450
</div>
450451
<div class="flex justify-between gap-2">
451452
<span class="text-gray-600 flex-shrink-0">Type:</span>
452-
<span class="text-gray-900 font-medium break-all text-right text-xs sm:text-sm">{file.mimeType}</span>
453+
<span class="text-gray-900 font-medium break-all text-right text-xs sm:text-sm">{getMimeTypeDisplayLabel(file.mimeType || '')}</span>
453454
</div>
454455
<div class="flex justify-between gap-2">
455456
<span class="text-gray-600 flex-shrink-0">Created:</span>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Returns a short, user-friendly label for a MIME type (e.g. DOCX, XLSX, PDF)
3+
* instead of long strings like application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
4+
*/
5+
export function getMimeTypeDisplayLabel(mimeType: string): string {
6+
if (!mimeType || typeof mimeType !== "string") return mimeType ?? "";
7+
const m = mimeType.toLowerCase();
8+
// Office / common document types
9+
if (m.includes("spreadsheetml.sheet") || m.includes("ms-excel")) return "XLSX";
10+
if (m.includes("wordprocessingml.document") || m.includes("msword")) return "DOCX";
11+
if (m.includes("presentationml") || m.includes("ms-powerpoint")) return "PPTX";
12+
if (m === "application/pdf") return "PDF";
13+
// Generic fallback: last meaningful part (e.g. "sheet", "pdf")
14+
const parts = m.split(/[/+]/);
15+
const last = parts[parts.length - 1];
16+
if (last && last !== "application" && last.length <= 20) return last.toUpperCase();
17+
return mimeType;
18+
}

platforms/file-manager/src/routes/(protected)/files/[id]/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { goto } from '$app/navigation';
55
import { isAuthenticated } from '$lib/stores/auth';
66
import { apiClient } from '$lib/utils/axios';
7+
import { getMimeTypeDisplayLabel } from '$lib/utils/mime-type';
78
import { PUBLIC_FILE_MANAGER_BASE_URL } from '$env/static/public';
89
import { toast } from '$lib/stores/toast';
910
import { fetchFileAccess, grantFileAccess, revokeFileAccess, fileAccess } from '$lib/stores/access';
@@ -367,7 +368,7 @@
367368
<div class="w-full lg:w-[70%] bg-white rounded-lg shadow-sm border border-gray-200 p-4 sm:p-6">
368369
<div class="mb-4">
369370
<h1 class="text-xl sm:text-2xl font-bold text-gray-900 mb-2">{file.displayName || file.name}</h1>
370-
<p class="text-xs sm:text-sm text-gray-500">Size: {formatFileSize(file.size)} • Type: {file.mimeType}</p>
371+
<p class="text-xs sm:text-sm text-gray-500">Size: {formatFileSize(file.size)} • Type: {getMimeTypeDisplayLabel(file.mimeType)}</p>
371372
</div>
372373

373374
{#if previewUrl}
@@ -417,7 +418,7 @@
417418
</div>
418419
<div>
419420
<dt class="text-gray-500 font-medium">Type</dt>
420-
<dd class="text-gray-900 mt-1">{file.mimeType}</dd>
421+
<dd class="text-gray-900 mt-1">{getMimeTypeDisplayLabel(file.mimeType)}</dd>
421422
</div>
422423
<div>
423424
<dt class="text-gray-500 font-medium">Created</dt>

0 commit comments

Comments
 (0)