fix
This commit is contained in:
@@ -77,6 +77,42 @@ export function resolveChatContentType(file: Pick<File, 'type' | 'name'>) {
|
||||
return aliased || 'application/octet-stream';
|
||||
}
|
||||
|
||||
const VIDEO_NOTE_FILE_NAME_PATTERNS = [
|
||||
/video[_-]?circle/i,
|
||||
/video[_-]?note/i,
|
||||
/videonote/i,
|
||||
/circle[_-]?video/i,
|
||||
/round[_-]?video/i,
|
||||
/tg[_-]?round/i,
|
||||
/кружок/i
|
||||
];
|
||||
|
||||
export function isVideoNoteFileName(fileName?: string | null) {
|
||||
if (!fileName?.trim()) return false;
|
||||
return VIDEO_NOTE_FILE_NAME_PATTERNS.some((pattern) => pattern.test(fileName.trim()));
|
||||
}
|
||||
|
||||
export function isVideoNoteMessage(
|
||||
message: {
|
||||
type: string;
|
||||
metadataJson?: string;
|
||||
mimeType?: string | null;
|
||||
content?: string | null;
|
||||
},
|
||||
e2ePayload?: { kind?: string; fileName?: string } | null
|
||||
) {
|
||||
if (message.type === 'VIDEO_NOTE') return true;
|
||||
if (e2ePayload?.kind === 'video_note') return true;
|
||||
|
||||
const meta = parseMessageMetadata(message.metadataJson);
|
||||
if (meta.videoNote) return true;
|
||||
|
||||
const fileName = e2ePayload?.fileName || meta.fileName || message.content;
|
||||
if (!isVideoNoteFileName(fileName)) return false;
|
||||
|
||||
return message.type === 'VIDEO' || message.type === 'FILE' || message.mimeType?.startsWith('video/') === true;
|
||||
}
|
||||
|
||||
export function inferChatMessageType(contentType: string, options?: { voice?: boolean; videoNote?: boolean }): ChatAttachmentKind {
|
||||
const normalized = resolveChatContentType({ type: contentType, name: '' });
|
||||
if (options?.videoNote && normalized.startsWith('video/')) return 'VIDEO_NOTE';
|
||||
@@ -90,7 +126,8 @@ export function inferChatMessageType(contentType: string, options?: { voice?: bo
|
||||
|
||||
export function detectChatMessageType(file: File, options?: { voice?: boolean; videoNote?: boolean }) {
|
||||
const contentType = resolveChatContentType(file);
|
||||
return inferChatMessageType(contentType, options);
|
||||
const videoNote = Boolean(options?.videoNote || isVideoNoteFileName(file.name));
|
||||
return inferChatMessageType(contentType, { ...options, videoNote });
|
||||
}
|
||||
|
||||
export function isVideoFile(file: Pick<File, 'type' | 'name'>) {
|
||||
|
||||
Reference in New Issue
Block a user