mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
✨ Remove "Read File From Url" node and add functionality to
"HTTP Request" node
This commit is contained in:
parent
7108320297
commit
c1e753e9d1
|
@ -2,6 +2,48 @@
|
||||||
|
|
||||||
This list shows all the versions which include breaking changes and how to upgrade
|
This list shows all the versions which include breaking changes and how to upgrade
|
||||||
|
|
||||||
|
## 0.19.0
|
||||||
|
|
||||||
|
### What changed?
|
||||||
|
|
||||||
|
The node "Read File From Url" got removed as its functionality got added to
|
||||||
|
"HTTP Request" node where it belongs.
|
||||||
|
|
||||||
|
### When is action necessary?
|
||||||
|
|
||||||
|
If the "Read File From Url" gets used in any workflow.
|
||||||
|
|
||||||
|
### How to upgrade:
|
||||||
|
|
||||||
|
After upgrading open all workflows which contain a "Read File From Url" node.
|
||||||
|
They will have a "?" as icon as they are not known anymore. Create a new
|
||||||
|
"HTTP Request" node to replace the old one and add the same URL as the previous
|
||||||
|
node had (in case you do not know it anymore you can select the old node, copy
|
||||||
|
it and paste it in a text-editor, it will display all the data the node
|
||||||
|
contained). Then set the "Response Format" to "File". Everything will then
|
||||||
|
function again like before.
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
### What changed?
|
||||||
|
|
||||||
|
When "HTTP Request" property "Response Format" was set to "String" it did save
|
||||||
|
the data by default in the property "response". In the new version that can now
|
||||||
|
be configured. The default value got also changed from "response" to "data" to
|
||||||
|
match other nodes with similar functionality.
|
||||||
|
|
||||||
|
### When is action necessary?
|
||||||
|
|
||||||
|
When "HTTP Request" nodes get used which have "Response Format" set to "String".
|
||||||
|
|
||||||
|
### How to upgrade:
|
||||||
|
|
||||||
|
After upgrading open all workflows which contain the concerning Nodes and set
|
||||||
|
"Binary Property" to "response".
|
||||||
|
|
||||||
|
|
||||||
## 0.18.0
|
## 0.18.0
|
||||||
|
|
||||||
### What changed?
|
### What changed?
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class HttpRequest implements INodeType {
|
||||||
version: 1,
|
version: 1,
|
||||||
description: 'Makes a HTTP request and returns the received data',
|
description: 'Makes a HTTP request and returns the received data',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: 'Http Request',
|
name: 'HTTP Request',
|
||||||
color: '#2200DD',
|
color: '#2200DD',
|
||||||
},
|
},
|
||||||
inputs: ['main'],
|
inputs: ['main'],
|
||||||
|
@ -143,6 +143,10 @@ export class HttpRequest implements INodeType {
|
||||||
name: 'responseFormat',
|
name: 'responseFormat',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'File',
|
||||||
|
value: 'file'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'JSON',
|
name: 'JSON',
|
||||||
value: 'json'
|
value: 'json'
|
||||||
|
@ -151,14 +155,43 @@ export class HttpRequest implements INodeType {
|
||||||
name: 'String',
|
name: 'String',
|
||||||
value: 'string'
|
value: 'string'
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// name: 'XML (not implemented)',
|
|
||||||
// value: 'xml'
|
|
||||||
// },
|
|
||||||
],
|
],
|
||||||
default: 'json',
|
default: 'json',
|
||||||
description: 'The format in which the data gets returned from the URL.',
|
description: 'The format in which the data gets returned from the URL.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
displayName: 'Property Name',
|
||||||
|
name: 'dataPropertyName',
|
||||||
|
type: 'string',
|
||||||
|
default: 'data',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
responseFormat: [
|
||||||
|
'string',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'Name of the property to which to write the response data.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Binary Property',
|
||||||
|
name: 'dataPropertyName',
|
||||||
|
type: 'string',
|
||||||
|
default: 'data',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
responseFormat: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
description: 'Name of the binary property to which to<br />write the data of the read file.',
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
displayName: 'JSON Parameters',
|
displayName: 'JSON Parameters',
|
||||||
name: 'jsonParameters',
|
name: 'jsonParameters',
|
||||||
|
@ -350,12 +383,13 @@ export class HttpRequest implements INodeType {
|
||||||
// TODO: Should have a setting which makes clear that this parameter can not change for each item
|
// TODO: Should have a setting which makes clear that this parameter can not change for each item
|
||||||
const requestMethod = this.getNodeParameter('requestMethod', 0) as string;
|
const requestMethod = this.getNodeParameter('requestMethod', 0) as string;
|
||||||
const parametersAreJson = this.getNodeParameter('jsonParameters', 0) as boolean;
|
const parametersAreJson = this.getNodeParameter('jsonParameters', 0) as boolean;
|
||||||
|
const responseFormat = this.getNodeParameter('responseFormat', 0) as string;
|
||||||
|
|
||||||
const httpBasicAuth = this.getCredentials('httpBasicAuth');
|
const httpBasicAuth = this.getCredentials('httpBasicAuth');
|
||||||
const httpDigestAuth = this.getCredentials('httpDigestAuth');
|
const httpDigestAuth = this.getCredentials('httpDigestAuth');
|
||||||
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
|
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
|
||||||
|
|
||||||
let url: string, responseFormat: string;
|
let url: string;
|
||||||
let requestOptions: OptionsWithUri;
|
let requestOptions: OptionsWithUri;
|
||||||
let setUiParameter: IDataObject;
|
let setUiParameter: IDataObject;
|
||||||
|
|
||||||
|
@ -383,7 +417,6 @@ export class HttpRequest implements INodeType {
|
||||||
const returnItems: INodeExecutionData[] = [];
|
const returnItems: INodeExecutionData[] = [];
|
||||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
url = this.getNodeParameter('url', itemIndex) as string;
|
url = this.getNodeParameter('url', itemIndex) as string;
|
||||||
responseFormat = this.getNodeParameter('responseFormat', itemIndex) as string;
|
|
||||||
|
|
||||||
requestOptions = {
|
requestOptions = {
|
||||||
headers: {},
|
headers: {},
|
||||||
|
@ -432,7 +465,6 @@ export class HttpRequest implements INodeType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
requestOptions.json = true;
|
|
||||||
|
|
||||||
// Add credentials if any are set
|
// Add credentials if any are set
|
||||||
if (httpBasicAuth !== undefined) {
|
if (httpBasicAuth !== undefined) {
|
||||||
|
@ -452,18 +484,54 @@ export class HttpRequest implements INodeType {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (responseFormat === 'file') {
|
||||||
|
requestOptions.encoding = null;
|
||||||
|
} else {
|
||||||
|
requestOptions.json = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Now that the options are all set make the actual http request
|
// Now that the options are all set make the actual http request
|
||||||
const response = await this.helpers.request(requestOptions);
|
const response = await this.helpers.request(requestOptions);
|
||||||
|
|
||||||
if (responseFormat === 'json') {
|
if (responseFormat === 'file') {
|
||||||
returnItems.push({ json: response });
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
||||||
// } else if (responseFormat === 'xml') {
|
|
||||||
// // TODO: Not implemented yet
|
const newItem: INodeExecutionData = {
|
||||||
|
json: items[itemIndex].json,
|
||||||
|
binary: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (items[itemIndex].binary !== undefined) {
|
||||||
|
// Create a shallow copy of the binary data so that the old
|
||||||
|
// data references which do not get changed still stay behind
|
||||||
|
// but the incoming data does not get changed.
|
||||||
|
Object.assign(newItem.binary, items[itemIndex].binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
items[itemIndex] = newItem;
|
||||||
|
|
||||||
|
const fileName = (url).split('/').pop();
|
||||||
|
|
||||||
|
items[itemIndex].binary![dataPropertyName] = await this.helpers.prepareBinaryData(response, fileName);
|
||||||
|
} else if (responseFormat === 'json') {
|
||||||
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
||||||
|
|
||||||
|
returnItems.push({
|
||||||
|
json: {
|
||||||
|
[dataPropertyName]: response,
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
returnItems.push({ json: { response } });
|
returnItems.push({ json: { response } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.prepareOutputData(returnItems);
|
if (responseFormat === 'file') {
|
||||||
|
// For file downloads the files get attached to the existing items
|
||||||
|
return this.prepareOutputData(items);
|
||||||
|
} else {
|
||||||
|
// For all other ones does the output items get replaced
|
||||||
|
return [this.helpers.returnJsonArray(returnItems)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,88 +0,0 @@
|
||||||
import { IExecuteSingleFunctions } from 'n8n-core';
|
|
||||||
import {
|
|
||||||
INodeTypeDescription,
|
|
||||||
INodeExecutionData,
|
|
||||||
INodeType,
|
|
||||||
} from 'n8n-workflow';
|
|
||||||
import { UriOptions } from 'request';
|
|
||||||
|
|
||||||
|
|
||||||
export class ReadFileFromUrl implements INodeType {
|
|
||||||
description: INodeTypeDescription = {
|
|
||||||
displayName: 'Read File From Url',
|
|
||||||
name: 'readFileFromUrl',
|
|
||||||
icon: 'fa:file-download',
|
|
||||||
group: ['input'],
|
|
||||||
version: 1,
|
|
||||||
description: 'Reads a file from an URL',
|
|
||||||
defaults: {
|
|
||||||
name: 'Read File URL',
|
|
||||||
color: '#119955',
|
|
||||||
},
|
|
||||||
inputs: ['main'],
|
|
||||||
outputs: ['main'],
|
|
||||||
properties: [
|
|
||||||
{
|
|
||||||
displayName: 'URL',
|
|
||||||
name: 'url',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
required: true,
|
|
||||||
placeholder: 'http://example.com/index.html',
|
|
||||||
description: 'URL of the file to read.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Property Name',
|
|
||||||
name: 'dataPropertyName',
|
|
||||||
type: 'string',
|
|
||||||
default: 'data',
|
|
||||||
description: 'Name of the binary property to which to<br />write the data of the URL.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Ignore SSL Issues',
|
|
||||||
name: 'allowUnauthorizedCerts',
|
|
||||||
type: 'boolean',
|
|
||||||
default: false,
|
|
||||||
description: 'Still download the file even if SSL certificate validation is not possible.',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
|
||||||
const url = this.getNodeParameter('url') as string;
|
|
||||||
const dataPropertyName = this.getNodeParameter('dataPropertyName') as string;
|
|
||||||
|
|
||||||
const options: UriOptions = {
|
|
||||||
uri: url,
|
|
||||||
// @ts-ignore
|
|
||||||
encoding: null,
|
|
||||||
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', false) as boolean,
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Should have a catch here
|
|
||||||
const data = await this.helpers.request(options);
|
|
||||||
|
|
||||||
// Get the filename and also add it to the binary data
|
|
||||||
const fileName = (url).split('/').pop();
|
|
||||||
|
|
||||||
// Get the current item and add the binary data
|
|
||||||
const item = this.getInputData();
|
|
||||||
|
|
||||||
const newItem: INodeExecutionData = {
|
|
||||||
json: item.json,
|
|
||||||
binary: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (item.binary !== undefined) {
|
|
||||||
// Create a shallow copy of the binary data so that the old
|
|
||||||
// data references which do not get changed still stay behind
|
|
||||||
// but the incoming data does not get changed.
|
|
||||||
Object.assign(newItem.binary, item.binary);
|
|
||||||
}
|
|
||||||
|
|
||||||
newItem.binary![dataPropertyName as string] = await this.helpers.prepareBinaryData(data, fileName);
|
|
||||||
|
|
||||||
return newItem;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -83,7 +83,6 @@
|
||||||
"dist/nodes/ReadBinaryFile.node.js",
|
"dist/nodes/ReadBinaryFile.node.js",
|
||||||
"dist/nodes/ReadBinaryFiles.node.js",
|
"dist/nodes/ReadBinaryFiles.node.js",
|
||||||
"dist/nodes/Redis/Redis.node.js",
|
"dist/nodes/Redis/Redis.node.js",
|
||||||
"dist/nodes/ReadFileFromUrl.node.js",
|
|
||||||
"dist/nodes/ReadPdf.node.js",
|
"dist/nodes/ReadPdf.node.js",
|
||||||
"dist/nodes/RenameKeys.node.js",
|
"dist/nodes/RenameKeys.node.js",
|
||||||
"dist/nodes/RssFeedRead.node.js",
|
"dist/nodes/RssFeedRead.node.js",
|
||||||
|
|
Loading…
Reference in a new issue