mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(editor): Make PDF and Audio binary-data viewable in the UI (#7367)
fixes #7361
This commit is contained in:
committed by
GitHub
parent
732b15a1fa
commit
8187be1b7d
@@ -35,7 +35,7 @@ export type IAllExecuteFunctions =
|
||||
| ITriggerFunctions
|
||||
| IWebhookFunctions;
|
||||
|
||||
export type BinaryFileType = 'text' | 'json' | 'image' | 'video';
|
||||
export type BinaryFileType = 'text' | 'json' | 'image' | 'audio' | 'video' | 'pdf';
|
||||
export interface IBinaryData {
|
||||
[key: string]: string | undefined;
|
||||
data: string;
|
||||
|
||||
@@ -113,8 +113,10 @@ export const sleep = async (ms: number): Promise<void> =>
|
||||
export function fileTypeFromMimeType(mimeType: string): BinaryFileType | undefined {
|
||||
if (mimeType.startsWith('application/json')) return 'json';
|
||||
if (mimeType.startsWith('image/')) return 'image';
|
||||
if (mimeType.startsWith('audio/')) return 'audio';
|
||||
if (mimeType.startsWith('video/')) return 'video';
|
||||
if (mimeType.startsWith('text/')) return 'text';
|
||||
if (mimeType.startsWith('text/') || mimeType.startsWith('application/javascript')) return 'text';
|
||||
if (mimeType.startsWith('application/pdf')) return 'pdf';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { jsonParse, jsonStringify, deepCopy, isObjectEmpty } from '@/utils';
|
||||
import { jsonParse, jsonStringify, deepCopy, isObjectEmpty, fileTypeFromMimeType } from '@/utils';
|
||||
|
||||
describe('isObjectEmpty', () => {
|
||||
it('should handle null and undefined', () => {
|
||||
@@ -190,3 +190,41 @@ describe('deepCopy', () => {
|
||||
expect(copy.deep.arr.slice(-1)[0]).not.toBe(object);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileTypeFromMimeType', () => {
|
||||
it('should recognize json', () => {
|
||||
expect(fileTypeFromMimeType('application/json')).toEqual('json');
|
||||
});
|
||||
|
||||
it('should recognize image', () => {
|
||||
expect(fileTypeFromMimeType('image/jpeg')).toEqual('image');
|
||||
expect(fileTypeFromMimeType('image/png')).toEqual('image');
|
||||
expect(fileTypeFromMimeType('image/avif')).toEqual('image');
|
||||
expect(fileTypeFromMimeType('image/webp')).toEqual('image');
|
||||
});
|
||||
|
||||
it('should recognize audio', () => {
|
||||
expect(fileTypeFromMimeType('audio/wav')).toEqual('audio');
|
||||
expect(fileTypeFromMimeType('audio/webm')).toEqual('audio');
|
||||
expect(fileTypeFromMimeType('audio/ogg')).toEqual('audio');
|
||||
expect(fileTypeFromMimeType('audio/mp3')).toEqual('audio');
|
||||
});
|
||||
|
||||
it('should recognize video', () => {
|
||||
expect(fileTypeFromMimeType('video/mp4')).toEqual('video');
|
||||
expect(fileTypeFromMimeType('video/webm')).toEqual('video');
|
||||
expect(fileTypeFromMimeType('video/ogg')).toEqual('video');
|
||||
});
|
||||
|
||||
it('should recognize text', () => {
|
||||
expect(fileTypeFromMimeType('text/plain')).toEqual('text');
|
||||
expect(fileTypeFromMimeType('text/css')).toEqual('text');
|
||||
expect(fileTypeFromMimeType('text/html')).toEqual('text');
|
||||
expect(fileTypeFromMimeType('text/javascript')).toEqual('text');
|
||||
expect(fileTypeFromMimeType('application/javascript')).toEqual('text');
|
||||
});
|
||||
|
||||
it('should recognize pdf', () => {
|
||||
expect(fileTypeFromMimeType('application/pdf')).toEqual('pdf');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user