diff --git a/src/components/Folder/index.tsx b/src/components/Folder/index.tsx
index ed378870..e731cd54 100644
--- a/src/components/Folder/index.tsx
+++ b/src/components/Folder/index.tsx
@@ -60,6 +60,10 @@ interface FileInfo {
isRemote?: boolean;
}
+const AUDIO_EXTENSIONS = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a', 'wma'];
+const VIDEO_EXTENSIONS = ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv'];
+const MEDIA_EXTENSIONS = [...AUDIO_EXTENSIONS, ...VIDEO_EXTENSIONS];
+
// FileTree component to render nested file structure
interface FileTreeProps {
node: FileTreeNode;
@@ -222,24 +226,7 @@ export default function Folder({ data: _data }: { data?: Agent }) {
console.log('file', JSON.parse(JSON.stringify(file)));
// For PDF and audio/video files, use data URL instead of custom protocol
- if (
- [
- 'pdf',
- 'mp3',
- 'wav',
- 'ogg',
- 'flac',
- 'aac',
- 'm4a',
- 'wma',
- 'mp4',
- 'webm',
- 'ogv',
- 'mov',
- 'avi',
- 'mkv',
- ].includes(file.type?.toLowerCase())
- ) {
+ if (['pdf', ...MEDIA_EXTENSIONS].includes(file.type?.toLowerCase())) {
window.ipcRenderer
.invoke('read-file-dataurl', file.path)
.then((dataUrl: string) => {
@@ -679,7 +666,7 @@ export default function Folder({ data: _data }: { data?: Agent }) {
- ) : ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a', 'wma'].includes(
+ ) : AUDIO_EXTENSIONS.includes(
selectedFile.type.toLowerCase()
) ? (
@@ -691,7 +678,7 @@ export default function Folder({ data: _data }: { data?: Agent }) {
{t('folder.audio-not-supported')}
- ) : ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv'].includes(
+ ) : VIDEO_EXTENSIONS.includes(
selectedFile.type.toLowerCase()
) ? (
diff --git a/test/unit/electron/main/fileReader.test.ts b/test/unit/electron/main/fileReader.test.ts
index c5ef79b6..991ca121 100644
--- a/test/unit/electron/main/fileReader.test.ts
+++ b/test/unit/electron/main/fileReader.test.ts
@@ -277,6 +277,48 @@ describe('File Operations and Utilities', () => {
});
});
+ describe('Multimedia File Type Detection', () => {
+ const audioExtensions = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a', 'wma'];
+ const videoExtensions = ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv'];
+ const mediaExtensions = [...audioExtensions, ...videoExtensions];
+
+ it('should recognize audio file extensions', () => {
+ audioExtensions.forEach((ext) => {
+ const filePath = `/path/to/file.${ext}`;
+ const fileExt = path.extname(filePath).slice(1);
+ expect(mediaExtensions).toContain(fileExt);
+ });
+ });
+
+ it('should recognize video file extensions', () => {
+ videoExtensions.forEach((ext) => {
+ const filePath = `/path/to/file.${ext}`;
+ const fileExt = path.extname(filePath).slice(1);
+ expect(mediaExtensions).toContain(fileExt);
+ });
+ });
+
+ it('should not treat non-media files as multimedia', () => {
+ const nonMediaExtensions = ['txt', 'json', 'csv', 'html', 'py', 'js'];
+ nonMediaExtensions.forEach((ext) => {
+ const isMedia = mediaExtensions.includes(ext);
+ expect(isMedia).toBe(false);
+ });
+ });
+
+ it('should distinguish audio from video extensions', () => {
+ audioExtensions.forEach((ext) => {
+ expect(audioExtensions).toContain(ext);
+ expect(videoExtensions).not.toContain(ext);
+ });
+
+ videoExtensions.forEach((ext) => {
+ expect(videoExtensions).toContain(ext);
+ expect(audioExtensions).not.toContain(ext);
+ });
+ });
+ });
+
describe('File Content Processing', () => {
it('should process text file content', () => {
const content = 'Line 1\nLine 2\nLine 3';