fix(editor): Restrict what binary-data types can be viewed in the UI (#14685)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-04-16 18:05:19 +02:00
committed by GitHub
parent 68a87619af
commit 11a36b758d
6 changed files with 93 additions and 29 deletions

View File

@@ -117,8 +117,8 @@ describe('RunData', () => {
expect(getByText('Json data 1')).toBeInTheDocument();
});
it('should render view and download buttons for PDFs', async () => {
const { getByTestId } = render({
it('should render only download buttons for PDFs', async () => {
const { getByTestId, queryByTestId } = render({
defaultRunItems: [
{
json: {},
@@ -135,6 +135,31 @@ describe('RunData', () => {
displayMode: 'binary',
});
await waitFor(() => {
expect(queryByTestId('ndv-view-binary-data')).not.toBeInTheDocument();
expect(getByTestId('ndv-download-binary-data')).toBeInTheDocument();
expect(getByTestId('ndv-binary-data_0')).toBeInTheDocument();
});
});
it('should render view and download buttons for JPEGs', async () => {
const { getByTestId } = render({
defaultRunItems: [
{
json: {},
binary: {
data: {
fileName: 'test.jpg',
fileType: 'image',
mimeType: 'image/jpeg',
data: '',
},
},
},
],
displayMode: 'binary',
});
await waitFor(() => {
expect(getByTestId('ndv-view-binary-data')).toBeInTheDocument();
expect(getByTestId('ndv-download-binary-data')).toBeInTheDocument();

View File

@@ -1,4 +1,5 @@
<script setup lang="ts">
import { ViewableMimeTypes } from '@n8n/api-types';
import { useStorage } from '@/composables/useStorage';
import { saveAs } from 'file-saver';
import type {
@@ -1182,10 +1183,8 @@ function closeBinaryDataDisplay() {
}
function isViewable(index: number, key: string | number): boolean {
const { fileType } = binaryData.value[index][key];
return (
!!fileType && ['image', 'audio', 'video', 'text', 'json', 'pdf', 'html'].includes(fileType)
);
const { mimeType } = binaryData.value[index][key];
return ViewableMimeTypes.includes(mimeType);
}
function isDownloadable(index: number, key: string | number): boolean {