mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
revert this > context
This commit is contained in:
parent
05e529b423
commit
19736d6a76
|
@ -4,19 +4,21 @@ import type {
|
||||||
JsonObject,
|
JsonObject,
|
||||||
IHttpRequestMethods,
|
IHttpRequestMethods,
|
||||||
IHttpRequestOptions,
|
IHttpRequestOptions,
|
||||||
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { NodeApiError } from 'n8n-workflow';
|
import { NodeApiError } from 'n8n-workflow';
|
||||||
|
|
||||||
export async function gotifyApiRequest(
|
export async function gotifyApiRequest(
|
||||||
context: IExecuteFunctions,
|
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||||
method: IHttpRequestMethods,
|
method: IHttpRequestMethods,
|
||||||
path: string,
|
path: string,
|
||||||
|
|
||||||
body: any = {},
|
body: any = {},
|
||||||
qs: IDataObject = {},
|
qs: IDataObject = {},
|
||||||
uri?: string | undefined,
|
uri?: string | undefined,
|
||||||
_option = {},
|
_option = {},
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const credentials = await context.getCredentials('gotifyApi');
|
const credentials = await this.getCredentials('gotifyApi');
|
||||||
|
|
||||||
const options: IHttpRequestOptions = {
|
const options: IHttpRequestOptions = {
|
||||||
method,
|
method,
|
||||||
|
@ -30,17 +32,18 @@ export async function gotifyApiRequest(
|
||||||
if (Object.keys(body as IDataObject).length === 0) {
|
if (Object.keys(body as IDataObject).length === 0) {
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
return await context.helpers.httpRequestWithAuthentication.call(context, 'gotifyApi', options);
|
return await this.helpers.httpRequestWithAuthentication.call(this, 'gotifyApi', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(context.getNode(), error as JsonObject);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function gotifyApiRequestAllItems(
|
export async function gotifyApiRequestAllItems(
|
||||||
context: IExecuteFunctions,
|
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||||
propertyName: string,
|
propertyName: string,
|
||||||
method: IHttpRequestMethods,
|
method: IHttpRequestMethods,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
|
|
||||||
body: any = {},
|
body: any = {},
|
||||||
query: IDataObject = {},
|
query: IDataObject = {},
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
|
@ -50,7 +53,7 @@ export async function gotifyApiRequestAllItems(
|
||||||
let uri: string | undefined;
|
let uri: string | undefined;
|
||||||
query.limit = 100;
|
query.limit = 100;
|
||||||
do {
|
do {
|
||||||
responseData = await gotifyApiRequest(context, method, endpoint, body, query, uri);
|
responseData = await gotifyApiRequest.call(this, method, endpoint, body, query, uri);
|
||||||
if (responseData.paging.next) {
|
if (responseData.paging.next) {
|
||||||
uri = responseData.paging.next;
|
uri = responseData.paging.next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,14 @@ import type {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { Node, NodeConnectionType } from 'n8n-workflow';
|
import { NodeConnectionType } from 'n8n-workflow';
|
||||||
|
|
||||||
import { gotifyApiRequest, gotifyApiRequestAllItems } from './GenericFunctions';
|
import { gotifyApiRequest, gotifyApiRequestAllItems } from './GenericFunctions';
|
||||||
|
|
||||||
export class Gotify extends Node {
|
export class Gotify implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Gotify',
|
displayName: 'Gotify',
|
||||||
name: 'gotify',
|
name: 'gotify',
|
||||||
|
@ -193,22 +194,22 @@ export class Gotify extends Node {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
async execute(context: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = context.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: INodeExecutionData[] = [];
|
const returnData: INodeExecutionData[] = [];
|
||||||
const length = items.length;
|
const length = items.length;
|
||||||
const qs: IDataObject = {};
|
const qs: IDataObject = {};
|
||||||
let responseData;
|
let responseData;
|
||||||
const resource = context.getNodeParameter('resource', 0);
|
const resource = this.getNodeParameter('resource', 0);
|
||||||
const operation = context.getNodeParameter('operation', 0);
|
const operation = this.getNodeParameter('operation', 0);
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
try {
|
try {
|
||||||
if (resource === 'message') {
|
if (resource === 'message') {
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
const message = context.getNodeParameter('message', i) as string;
|
const message = this.getNodeParameter('message', i) as string;
|
||||||
|
|
||||||
const additionalFields = context.getNodeParameter('additionalFields', i);
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||||
const options = context.getNodeParameter('options', i);
|
const options = this.getNodeParameter('options', i);
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
message,
|
message,
|
||||||
|
@ -224,23 +225,21 @@ export class Gotify extends Node {
|
||||||
|
|
||||||
Object.assign(body, additionalFields);
|
Object.assign(body, additionalFields);
|
||||||
|
|
||||||
responseData = await gotifyApiRequest(context, 'POST', '/message', body);
|
responseData = await gotifyApiRequest.call(this, 'POST', '/message', body);
|
||||||
|
|
||||||
responseData = await gotifyApiRequest(context, 'POST', '/message', body);
|
|
||||||
}
|
}
|
||||||
if (operation === 'delete') {
|
if (operation === 'delete') {
|
||||||
const messageId = context.getNodeParameter('messageId', i) as string;
|
const messageId = this.getNodeParameter('messageId', i) as string;
|
||||||
|
|
||||||
responseData = await gotifyApiRequest(context, 'DELETE', `/message/${messageId}`);
|
responseData = await gotifyApiRequest.call(this, 'DELETE', `/message/${messageId}`);
|
||||||
responseData = { success: true };
|
responseData = { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const returnAll = context.getNodeParameter('returnAll', i);
|
const returnAll = this.getNodeParameter('returnAll', i);
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await gotifyApiRequestAllItems(
|
responseData = await gotifyApiRequestAllItems.call(
|
||||||
context,
|
this,
|
||||||
'messages',
|
'messages',
|
||||||
'GET',
|
'GET',
|
||||||
'/message',
|
'/message',
|
||||||
|
@ -248,20 +247,20 @@ export class Gotify extends Node {
|
||||||
qs,
|
qs,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
qs.limit = context.getNodeParameter('limit', i);
|
qs.limit = this.getNodeParameter('limit', i);
|
||||||
responseData = await gotifyApiRequest(context, 'GET', '/message', {}, qs);
|
responseData = await gotifyApiRequest.call(this, 'GET', '/message', {}, qs);
|
||||||
responseData = responseData.messages;
|
responseData = responseData.messages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const executionData = context.helpers.constructExecutionMetaData(
|
const executionData = this.helpers.constructExecutionMetaData(
|
||||||
context.helpers.returnJsonArray(responseData as IDataObject[]),
|
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||||
{ itemData: { item: i } },
|
{ itemData: { item: i } },
|
||||||
);
|
);
|
||||||
returnData.push(...executionData);
|
returnData.push(...executionData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (context.continueOnFail()) {
|
if (this.continueOnFail()) {
|
||||||
returnData.push({ json: { error: error.message } });
|
returnData.push({ json: { error: error.message } });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue