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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 26 deletions

View file

@ -1515,7 +1515,9 @@ class App {
identifier,
);
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.sendFile(binaryPath);
},

View file

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

View file

@ -111,19 +111,5 @@ export default mixins(nodeHelpers, restApi).extend({
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>

View file

@ -56,7 +56,7 @@ export default mixins(restApi).extend({
}
} else {
try {
const binaryUrl = this.restApi().getBinaryUrl(id);
const binaryUrl = this.restApi().getBinaryUrl(id, 'view');
if (isJSONData) {
this.jsonData = await (await fetch(binaryUrl)).json();
} 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];
if (id) {
const url = this.restApi().getBinaryUrl(id);
const url = this.restApi().getBinaryUrl(id, 'download');
saveAs(url, [fileName, fileExtension].join('.'));
return;
} else {

View file

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