Skip to content

Commit 92398f3

Browse files
committed
refactor(ai): use wildcards for MIME type detection
1 parent 28bfcba commit 92398f3

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

packages/core/src/utils/ai/mediaFiltering.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
import { getClient } from '../../currentScopes';
22

3-
const MEDIA_MIME_TYPES = new Set([
4-
'image/jpeg',
5-
'image/jpg',
6-
'image/png',
7-
'image/gif',
8-
'image/webp',
9-
'image/svg+xml',
10-
'image/bmp',
11-
'image/tiff',
12-
'video/mp4',
13-
'video/avi',
14-
'video/mov',
15-
'video/wmv',
16-
'video/flv',
17-
'video/webm',
18-
'video/mkv',
19-
'audio/mp3',
20-
'audio/wav',
21-
'audio/ogg',
22-
'audio/mpeg',
23-
'audio/aac',
24-
'audio/flac',
25-
'application/pdf',
26-
'application/zip',
27-
'application/x-zip-compressed',
28-
]);
3+
function isMediaMimeType(mimeType: string): boolean {
4+
const type = mimeType.toLowerCase();
5+
return type.startsWith('image/') || type.startsWith('video/') || type.startsWith('audio/');
6+
}
297

308
function isMediaContent(item: unknown): boolean {
319
if (typeof item !== 'object' || item === null) {
@@ -38,11 +16,11 @@ function isMediaContent(item: unknown): boolean {
3816
return true;
3917
}
4018

41-
if (typeof obj.mime_type === 'string' && MEDIA_MIME_TYPES.has(obj.mime_type.toLowerCase())) {
19+
if (typeof obj.mime_type === 'string' && isMediaMimeType(obj.mime_type)) {
4220
return true;
4321
}
4422

45-
if (typeof obj.mimeType === 'string' && MEDIA_MIME_TYPES.has(obj.mimeType.toLowerCase())) {
23+
if (typeof obj.mimeType === 'string' && isMediaMimeType(obj.mimeType)) {
4624
return true;
4725
}
4826

0 commit comments

Comments
 (0)