pull:初次提交
This commit is contained in:
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/GenericFunctions.ts
Executable file
32
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/GenericFunctions.ts
Executable file
@@ -0,0 +1,32 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IHttpRequestMethods,
|
||||
IHttpRequestOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function uprocApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
_option: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const options: IHttpRequestOptions = {
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
url: 'https://api.uproc.io/api/v2/process',
|
||||
json: true,
|
||||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.httpRequestWithAuthentication.call(this, 'uprocApi', options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
31
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/GroupDescription.ts
Executable file
31
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/GroupDescription.ts
Executable file
@@ -0,0 +1,31 @@
|
||||
import type { IDataObject, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { groups } from './Json/Groups';
|
||||
|
||||
const finalGroups = {
|
||||
displayName: 'Resource',
|
||||
name: 'group',
|
||||
type: 'options',
|
||||
default: 'communication',
|
||||
options: [],
|
||||
};
|
||||
|
||||
const options = [];
|
||||
|
||||
for (const group of (groups as IDataObject).groups as IDataObject[]) {
|
||||
const item = {
|
||||
name: group.translated,
|
||||
value: group.name,
|
||||
description:
|
||||
'The ' +
|
||||
(group.translated as string) +
|
||||
' Resource allows you to get tools from this resource',
|
||||
};
|
||||
options.push(item);
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
finalGroups.options = options;
|
||||
const mappedGroups = [finalGroups];
|
||||
|
||||
export const groupOptions = mappedGroups as INodeProperties[];
|
||||
15
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/Json/Groups.ts
Executable file
15
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/Json/Groups.ts
Executable file
@@ -0,0 +1,15 @@
|
||||
export const groups = {
|
||||
groups: [
|
||||
{ translated: 'Audio', name: 'audio' },
|
||||
{ translated: 'Communication', name: 'communication' },
|
||||
{ translated: 'Company', name: 'company' },
|
||||
{ translated: 'Finance', name: 'finance' },
|
||||
{ translated: 'Geographical', name: 'geographic' },
|
||||
{ translated: 'Image', name: 'image' },
|
||||
{ translated: 'Internet', name: 'internet' },
|
||||
{ translated: 'Personal', name: 'personal' },
|
||||
{ translated: 'Product', name: 'product' },
|
||||
{ translated: 'Security', name: 'security' },
|
||||
{ translated: 'Text', name: 'text' },
|
||||
],
|
||||
};
|
||||
7967
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/Json/Tools.ts
Executable file
7967
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/Json/Tools.ts
Executable file
File diff suppressed because it is too large
Load Diff
116
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/ToolDescription.ts
Executable file
116
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/ToolDescription.ts
Executable file
@@ -0,0 +1,116 @@
|
||||
import type { IDataObject, INodeProperties } from 'n8n-workflow';
|
||||
import { deepCopy } from 'n8n-workflow';
|
||||
|
||||
import { groups } from './Json/Groups';
|
||||
import { tools } from './Json/Tools';
|
||||
|
||||
function capitalize(str: string): string {
|
||||
if (!str) {
|
||||
return '';
|
||||
} else {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
const operations = [];
|
||||
|
||||
for (const group of (groups as IDataObject).groups as IDataObject[]) {
|
||||
const item = {
|
||||
displayName: 'Operation',
|
||||
name: 'tool',
|
||||
type: 'options',
|
||||
description: 'The Operation to consume',
|
||||
displayOptions: {
|
||||
show: {
|
||||
group: [group.name],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
options: [],
|
||||
};
|
||||
|
||||
const options = [];
|
||||
for (const tool of (tools as IDataObject).processors as IDataObject[]) {
|
||||
if (tool.g === group.name) {
|
||||
const link =
|
||||
'https://app.uproc.io/#/tools/processor/' +
|
||||
(tool.k as string)
|
||||
.replace(/([A-Z]+)/g, '-$1')
|
||||
.toLowerCase()
|
||||
.replace('-', '/')
|
||||
.replace('-', '/');
|
||||
const option = {
|
||||
name: tool.d as string,
|
||||
value: tool.k,
|
||||
description: (tool.ed as string) + ` <a href="${link}" target='_blank'>Info</a>`,
|
||||
};
|
||||
options.push(option);
|
||||
}
|
||||
}
|
||||
|
||||
//Tool
|
||||
item.options = options.sort((a, b) => (a.name > b.name ? 1 : -1)) as any;
|
||||
item.default = options[0].value as string;
|
||||
operations.push(item);
|
||||
}
|
||||
|
||||
export const toolOperations = operations as INodeProperties[];
|
||||
|
||||
let parameters = [];
|
||||
//all tools
|
||||
for (const tool of (tools as IDataObject).processors as IDataObject[]) {
|
||||
//all parameters in tool
|
||||
for (const param of tool.p as IDataObject[]) {
|
||||
const displayName = param.n as string;
|
||||
const capitalizedDisplayName = capitalize(displayName.replace(/_/g, ' '));
|
||||
const description = `The "${capitalizedDisplayName}" value to use as a parameter for this Operation`;
|
||||
const parameter = {
|
||||
displayName: capitalizedDisplayName,
|
||||
name: param.n,
|
||||
type: param.t,
|
||||
default: '',
|
||||
placeholder: param.p,
|
||||
required: param.r,
|
||||
options: param.o,
|
||||
displayOptions: {
|
||||
show: {
|
||||
group: [tool.g],
|
||||
tool: [tool.k],
|
||||
},
|
||||
},
|
||||
description: deepCopy(description),
|
||||
};
|
||||
|
||||
let modifiedParam = null;
|
||||
//Check if param exists previously
|
||||
for (const currentParam of parameters) {
|
||||
//Get old param in parameters array
|
||||
if (currentParam.name === param.n) {
|
||||
modifiedParam = currentParam;
|
||||
}
|
||||
}
|
||||
//if exists, other wise
|
||||
if (modifiedParam) {
|
||||
//Assign new group and tool
|
||||
modifiedParam.displayOptions.show.group.push(tool.g);
|
||||
modifiedParam.displayOptions.show.tool.push(tool.k);
|
||||
|
||||
//build new array
|
||||
const newParameters = [];
|
||||
for (const currentParam of parameters) {
|
||||
//Get old param in parameters array
|
||||
if (currentParam.name === modifiedParam.name) {
|
||||
newParameters.push(modifiedParam);
|
||||
} else {
|
||||
newParameters.push(currentParam);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line n8n-local-rules/no-json-parse-json-stringify
|
||||
parameters = JSON.parse(JSON.stringify(newParameters));
|
||||
} else {
|
||||
parameters.push(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const toolParameters = parameters as INodeProperties[];
|
||||
29
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/UProc.node.json
Executable file
29
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/UProc.node.json
Executable file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.uproc",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Data & Storage"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/uProc/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.uproc/"
|
||||
}
|
||||
],
|
||||
"generic": [
|
||||
{
|
||||
"label": "How uProc scraped a multi-page website with a low-code workflow",
|
||||
"icon": " 🕸️",
|
||||
"url": "https://n8n.io/blog/how-uproc-scraped-a-multi-page-website-with-a-low-code-workflow/"
|
||||
},
|
||||
{
|
||||
"label": "7 no-code workflow automations for Amazon Web Services",
|
||||
"url": "https://n8n.io/blog/aws-workflow-automation/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
146
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/UProc.node.ts
Executable file
146
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/UProc.node.ts
Executable file
@@ -0,0 +1,146 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { uprocApiRequest } from './GenericFunctions';
|
||||
import { groupOptions } from './GroupDescription';
|
||||
import { toolOperations, toolParameters } from './ToolDescription';
|
||||
|
||||
export class UProc implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'uProc',
|
||||
name: 'uproc',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
||||
icon: 'file:uproc.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["tool"]}}',
|
||||
description: 'Consume uProc API',
|
||||
defaults: {
|
||||
name: 'uProc',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'uprocApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
...groupOptions,
|
||||
...toolOperations,
|
||||
...toolParameters,
|
||||
{
|
||||
displayName: 'Additional Options',
|
||||
name: 'additionalOptions',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
group: [
|
||||
'audio',
|
||||
'communication',
|
||||
'company',
|
||||
'finance',
|
||||
'geographic',
|
||||
'image',
|
||||
'internet',
|
||||
'personal',
|
||||
'product',
|
||||
'security',
|
||||
'text',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Data Webhook',
|
||||
name: 'dataWebhook',
|
||||
type: 'string',
|
||||
description: 'URL to send tool response when tool has resolved your request',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length;
|
||||
let responseData;
|
||||
const group = this.getNodeParameter('group', 0) as string;
|
||||
const tool = this.getNodeParameter('tool', 0) as string;
|
||||
const additionalOptions = this.getNodeParameter('additionalOptions', 0) as IDataObject;
|
||||
|
||||
const dataWebhook = additionalOptions.dataWebhook as string;
|
||||
|
||||
interface LooseObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
const fields = toolParameters
|
||||
.filter((field) => {
|
||||
return (
|
||||
field?.displayOptions?.show?.group &&
|
||||
field.displayOptions.show.tool &&
|
||||
field.displayOptions.show.group.indexOf(group) !== -1 &&
|
||||
field.displayOptions.show.tool.indexOf(tool) !== -1
|
||||
);
|
||||
})
|
||||
.map((field) => {
|
||||
return field.name;
|
||||
});
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
const toolKey = tool.replace(/([A-Z]+)/g, '-$1').toLowerCase();
|
||||
const body: LooseObject = {
|
||||
processor: toolKey,
|
||||
params: {},
|
||||
};
|
||||
|
||||
fields.forEach((field) => {
|
||||
if (field?.length) {
|
||||
const data = this.getNodeParameter(field, i) as string;
|
||||
body.params[field] = data + '';
|
||||
}
|
||||
});
|
||||
|
||||
if (dataWebhook?.length) {
|
||||
body.callback = {};
|
||||
}
|
||||
|
||||
if (dataWebhook?.length) {
|
||||
body.callback.data = dataWebhook;
|
||||
}
|
||||
|
||||
//Change to multiple requests
|
||||
responseData = await uprocApiRequest.call(this, 'POST', body);
|
||||
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
BIN
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/uproc.png
Executable file
BIN
n8n-n8n-1.109.2/packages/nodes-base/nodes/UProc/uproc.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user