mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-30 11:55:12 +00:00
refactor: extract media extension constants to reduce duplication
Co-authored-by: lightaime <23632352+lightaime@users.noreply.github.com>
This commit is contained in:
parent
7050511188
commit
571e82db82
2 changed files with 49 additions and 20 deletions
|
|
@ -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 }) {
|
|||
<div className="flex h-full items-center justify-center">
|
||||
<ImageLoader selectedFile={selectedFile} />
|
||||
</div>
|
||||
) : ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a', 'wma'].includes(
|
||||
) : AUDIO_EXTENSIONS.includes(
|
||||
selectedFile.type.toLowerCase()
|
||||
) ? (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
|
|
@ -691,7 +678,7 @@ export default function Folder({ data: _data }: { data?: Agent }) {
|
|||
{t('folder.audio-not-supported')}
|
||||
</audio>
|
||||
</div>
|
||||
) : ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv'].includes(
|
||||
) : VIDEO_EXTENSIONS.includes(
|
||||
selectedFile.type.toLowerCase()
|
||||
) ? (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue