Skip to content

Commit

Permalink
⚡ Improve list of content-types to download
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed Oct 20, 2022
1 parent 8f14baf commit 22d4819
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
26 changes: 26 additions & 0 deletions packages/nodes-base/nodes/HttpRequest/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,29 @@ export const getOAuth2AdditionalParameters = (nodeCredentialType: string) => {
};
return oAuth2Options[nodeCredentialType];
};

//https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
export const binaryContentTypes = [
'image/',
'audio/',
'video/',
'application/octet-stream',
'application/gzip',
'application/zip',
'application/vnd.rar',
'application/epub+zip',
'application/x-bzip',
'application/x-bzip2',
'application/x-cdf',
'application/vnd.amazon.ebook',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-fontobject',
'application/vnd.oasis.opendocument.presentation',
'application/pdf',
'application/x-tar',
'application/vnd.visio',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/x-7z-compressed',
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {

import { OptionsWithUri } from 'request-promise-native';

import { getOAuth2AdditionalParameters, replaceNullValues } from '../GenericFunctions';
import {
binaryContentTypes,
getOAuth2AdditionalParameters,
replaceNullValues,
} from '../GenericFunctions';
export class HttpRequestV3 implements INodeType {
description: INodeTypeDescription;

Expand Down Expand Up @@ -1208,7 +1212,7 @@ export class HttpRequestV3 implements INodeType {
if (responseContentType.includes('application/json')) {
responseFormat = 'json';
response.body = JSON.parse(Buffer.from(response.body).toString());
} else if (['image/', 'audio/', 'video/', 'application/octet-stream'].some((e) => responseContentType.includes(e))) {
} else if (binaryContentTypes.some((e) => responseContentType.includes(e))) {
responseFormat = 'file';
} else {
responseFormat = 'text';
Expand Down

0 comments on commit 22d4819

Please sign in to comment.