fix: View option for binary-data shouldn't download the file on Chrome/Edge (#4995)

* delete unused code

* fix: Do not set the `Content-Disposition` header when viewing binary files

* remove the duplicate styles.

these already exist in BinaryDataDisplayEmbed.vue
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2022-12-21 13:30:51 +01:00
committed by GitHub
parent 80e07f86ac
commit e225c3190e
6 changed files with 8 additions and 26 deletions

View File

@@ -1515,7 +1515,9 @@ class App {
identifier, identifier,
); );
if (mimeType) res.setHeader('Content-Type', mimeType); if (mimeType) res.setHeader('Content-Type', mimeType);
if (fileName) res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`); if (req.query.mode === 'download' && fileName) {
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
}
res.setHeader('Content-Length', fileSize); res.setHeader('Content-Length', fileSize);
res.sendFile(binaryPath); res.sendFile(binaryPath);
}, },

View File

@@ -235,8 +235,7 @@ export interface IRestApi {
deleteExecutions(sendData: IExecutionDeleteFilter): Promise<void>; deleteExecutions(sendData: IExecutionDeleteFilter): Promise<void>;
retryExecution(id: string, loadWorkflow?: boolean): Promise<boolean>; retryExecution(id: string, loadWorkflow?: boolean): Promise<boolean>;
getTimezones(): Promise<IDataObject>; getTimezones(): Promise<IDataObject>;
getBinaryBufferString(dataPath: string): Promise<string>; getBinaryUrl(dataPath: string, mode: 'view' | 'download'): string;
getBinaryUrl(dataPath: string): string;
} }
export interface INodeTranslationHeaders { export interface INodeTranslationHeaders {

View File

@@ -111,19 +111,5 @@ export default mixins(nodeHelpers, restApi).extend({
height: 100%; height: 100%;
} }
} }
.binary-data {
background-color: var(--color-foreground-xlight);
&.image {
max-height: calc(100% - 1em);
max-width: calc(100% - 1em);
}
&.other {
height: calc(100% - 1em);
width: calc(100% - 1em);
}
}
} }
</style> </style>

View File

@@ -56,7 +56,7 @@ export default mixins(restApi).extend({
} }
} else { } else {
try { try {
const binaryUrl = this.restApi().getBinaryUrl(id); const binaryUrl = this.restApi().getBinaryUrl(id, 'view');
if (isJSONData) { if (isJSONData) {
this.jsonData = await (await fetch(binaryUrl)).json(); this.jsonData = await (await fetch(binaryUrl)).json();
} else { } else {

View File

@@ -1202,7 +1202,7 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers, pinData).exten
const { id, data, fileName, fileExtension, mimeType } = this.binaryData[index][key]; const { id, data, fileName, fileExtension, mimeType } = this.binaryData[index][key];
if (id) { if (id) {
const url = this.restApi().getBinaryUrl(id); const url = this.restApi().getBinaryUrl(id, 'download');
saveAs(url, [fileName, fileExtension].join('.')); saveAs(url, [fileName, fileExtension].join('.'));
return; return;
} else { } else {

View File

@@ -201,13 +201,8 @@ export const restApi = Vue.extend({
}, },
// Binary data // Binary data
getBinaryBufferString: (dataPath: string): Promise<string> => { getBinaryUrl: (dataPath, mode): string =>
return self.restApi().makeRestApiRequest('GET', `/data/${dataPath}`); self.rootStore.getRestApiContext.baseUrl + `/data/${dataPath}?mode=${mode}`,
},
getBinaryUrl: (dataPath: string): string => {
return self.rootStore.getRestApiContext.baseUrl + `/data/${dataPath}`;
},
}; };
}, },
}, },