This commit is contained in:
2026-08-28 17:31:02 +02:00
commit 2b30e8bd39
694 changed files with 49243 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
import type { BuildUploadHintOptions } from '@/types/BuildUploadHintOptions';
import { formatFileSize } from '@/utils/formatFileSize';
const MIME_LABEL: Record<string, string> = {
'application/json': 'JSON',
'application/pdf': 'PDF',
'application/zip': 'ZIP',
'image/gif': 'GIF',
'image/jpeg': 'JPEG',
'image/jpg': 'JPEG',
'image/png': 'PNG',
'image/vnd.microsoft.icon': 'ICO',
'image/x-icon': 'ICO',
'image/webp': 'WebP',
'text/csv': 'CSV',
'text/plain': 'plain text'
};
const formatTypeList = (types: string[]): string => {
if (types.length === 0) {
return '';
}
if (types.length === 1) {
return types[0];
}
if (types.length === 2) {
return `${types[0]} or ${types[1]}`;
}
return `${types.slice(0, -1).join(', ')}, or ${types.at(-1)}`;
};
export const buildUploadHint = ({
allowedMimesCsv,
maxFileBytes,
maxFiles,
maxFilesLabel,
encryptedAtRest
}: BuildUploadHintOptions): string => {
const types = [
...new Set(
allowedMimesCsv
.split(',')
.map(s => s.trim().toLowerCase())
.filter(Boolean)
.map(m => MIME_LABEL[m] ?? m)
)
];
const sizePart = formatFileSize(maxFileBytes);
const typePart = formatTypeList(types) || allowedMimesCsv.trim();
const parts: string[] = [];
if (typePart) {
parts.push(`${typePart} up to ${sizePart} each.`);
} else {
parts.push(`Up to ${sizePart} each.`);
}
if (maxFiles !== undefined && maxFilesLabel) {
parts.push(`Max ${maxFiles} ${maxFilesLabel}.`);
}
if (encryptedAtRest) {
parts.push('Encrypted at rest on the server.');
}
return parts.join(' ');
};