char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
1.0 KiB39 linesraw
1/**
2 * Gets a display label for a file type from various input formats
3 *
4 * Handles:
5 * - MIME types: 'application/pdf' → 'PDF'
6 * - AttachmentType values: 'PDF', 'AUDIO' → 'PDF', 'AUDIO'
7 * - File names: 'document.pdf' → 'PDF'
8 * - Unknown: returns 'FILE'
9 *
10 * @param input - MIME type, AttachmentType value, or file name
11 * @returns Formatted file type label (uppercase)
12 */
13export function getFileTypeLabel(input: string | undefined): string {
14	if (!input) return 'FILE';
15
16	// Handle MIME types (contains '/')
17	if (input.includes('/')) {
18		const subtype = input.split('/').pop();
19
20		if (subtype) {
21			// Handle special cases like 'vnd.ms-excel' → 'EXCEL'
22			if (subtype.includes('.')) {
23				return subtype.split('.').pop()?.toUpperCase() || 'FILE';
24			}
25
26			return subtype.toUpperCase();
27		}
28	}
29
30	// Handle file names (contains '.')
31	if (input.includes('.')) {
32		const ext = input.split('.').pop();
33
34		if (ext) return ext.toUpperCase();
35	}
36
37	// Handle AttachmentType or other plain strings
38	return input.toUpperCase();
39}