fix
This commit is contained in:
@@ -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} Б`;
|
||||
|
||||
Reference in New Issue
Block a user