Files
llama.cpp/tools/server/webui/src/lib/utils/file-preview.ts
T
0f4f35e7be Fix unreadable user markdown colors and truncate long texts in deletion dialogs (#17555)
* webui: limit conversation name length in dialogs

* webui: fix unreadable colors on links and table cell hover in user markdown

* webui: keep table borders visible in user markdown

* webui: updating unified exports

* Update tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentThumbnailFile.svelte

Co-authored-by: Aleksander Grygier <aleksander.grygier@gmail.com>

* chore: update webui build output

* chore: update webui build output

* chore: update webui build output

---------

Co-authored-by: Aleksander Grygier <aleksander.grygier@gmail.com>
2025-12-15 16:34:53 +01:00

37 lines
1.0 KiB
TypeScript

/**
* Gets a display label for a file type from various input formats
*
* Handles:
* - MIME types: 'application/pdf' → 'PDF'
* - AttachmentType values: 'PDF', 'AUDIO' → 'PDF', 'AUDIO'
* - File names: 'document.pdf' → 'PDF'
* - Unknown: returns 'FILE'
*
* @param input - MIME type, AttachmentType value, or file name
* @returns Formatted file type label (uppercase)
*/
export function getFileTypeLabel(input: string | undefined): string {
if (!input) return 'FILE';
// Handle MIME types (contains '/')
if (input.includes('/')) {
const subtype = input.split('/').pop();
if (subtype) {
// Handle special cases like 'vnd.ms-excel' → 'EXCEL'
if (subtype.includes('.')) {
return subtype.split('.').pop()?.toUpperCase() || 'FILE';
}
return subtype.toUpperCase();
}
}
// Handle file names (contains '.')
if (input.includes('.')) {
const ext = input.split('.').pop();
if (ext) return ext.toUpperCase();
}
// Handle AttachmentType or other plain strings
return input.toUpperCase();
}