This commit is contained in:
lendry
2026-07-10 12:37:54 +03:00
parent f00f3d411d
commit 7fc3ca7952
3 changed files with 77 additions and 23 deletions

View File

@@ -134,6 +134,32 @@ export function isVideoFile(file: Pick<File, 'type' | 'name'>) {
return resolveChatContentType(file).startsWith('video/');
}
export type ComposeMediaKind = 'image' | 'video' | 'audio' | 'file';
export function getComposeMediaKind(file: Pick<File, 'type' | 'name'>): ComposeMediaKind {
const contentType = resolveChatContentType(file);
if (contentType.startsWith('image/')) return 'image';
if (contentType.startsWith('video/')) return 'video';
if (contentType.startsWith('audio/')) return 'audio';
return 'file';
}
export function getComposeDialogTitle(files: Array<Pick<File, 'type' | 'name'>>) {
if (!files.length) return 'Отправить файл';
if (files.length > 1) return `Отправить ${files.length} файла`;
switch (getComposeMediaKind(files[0]!)) {
case 'video':
return 'Отправить видео';
case 'audio':
return 'Отправить аудио';
case 'image':
return 'Отправить изображение';
default:
return 'Отправить файл';
}
}
export function formatFileSize(bytes?: number) {
if (!bytes || bytes <= 0) return '';
if (bytes < 1024) return `${bytes} Б`;