fix
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { resolveChatContentType } from '@/lib/chat-media';
|
||||
|
||||
const DEFAULT_MAX_EDGE = 2560;
|
||||
const DEFAULT_QUALITY = 0.82;
|
||||
|
||||
@@ -107,7 +109,8 @@ export async function readImageDimensions(file: File) {
|
||||
}
|
||||
|
||||
export function createFilePreviewUrl(file: File) {
|
||||
if (file.type.startsWith('image/')) {
|
||||
const contentType = resolveChatContentType(file);
|
||||
if (contentType.startsWith('image/') || contentType.startsWith('video/')) {
|
||||
return URL.createObjectURL(file);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -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