refactor: Format nodes-base package (A-F) (#3800)

* 🔨 prettier formated nodes - A

* 🔨 prettier formated nodes - B

*  prettier formated nodes - C

*  prettier formated nodes - D

*  prettier formated nodes - E-F

* 🎨 Adjust nodes-base formatting command (#3805)

* Format additional files in nodes A-F (#3811)

*  fixes

* 🎨 Add Mindee to ignored dirs

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Michael Kret
2022-08-01 23:47:55 +03:00
committed by GitHub
parent 2c17e6f3ca
commit 0ecbb4a19d
411 changed files with 12906 additions and 20148 deletions

View File

@@ -8,7 +8,6 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import { DiscordAttachment, DiscordWebhook } from './Interfaces';
export class Discord implements INodeType {
description: INodeTypeDescription = {
@@ -23,7 +22,7 @@ export class Discord implements INodeType {
},
inputs: ['main'],
outputs: ['main'],
properties:[
properties: [
{
displayName: 'Webhook URL',
name: 'webhookUri',
@@ -136,21 +135,27 @@ export class Discord implements INodeType {
const options = this.getNodeParameter('options', i) as IDataObject;
if (!body.content && !options.embeds) {
throw new NodeOperationError(this.getNode(), 'Either content or embeds must be set.', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'Either content or embeds must be set.', {
itemIndex: i,
});
}
if (options.embeds) {
try {
//@ts-expect-error
body.embeds = JSON.parse(options.embeds);
if (!Array.isArray(body.embeds)) {
throw new NodeOperationError(this.getNode(), 'Embeds must be an array of embeds.', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'Embeds must be an array of embeds.', {
itemIndex: i,
});
}
} catch (e) {
throw new NodeOperationError(this.getNode(), 'Embeds must be valid JSON.', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'Embeds must be valid JSON.', {
itemIndex: i,
});
}
}
if (options.username) {
body.username = options.username as string;
body.username = options.username as string;
}
if (options.components) {
@@ -158,13 +163,15 @@ export class Discord implements INodeType {
//@ts-expect-error
body.components = JSON.parse(options.components);
} catch (e) {
throw new NodeOperationError(this.getNode(), 'Components must be valid JSON.', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'Components must be valid JSON.', {
itemIndex: i,
});
}
}
if (options.allowed_mentions) {
//@ts-expect-error
body.allowed_mentions = JSON.parse(options.allowed_mentions);
//@ts-expect-error
body.allowed_mentions = JSON.parse(options.allowed_mentions);
}
if (options.avatarUrl) {
@@ -202,7 +209,7 @@ export class Discord implements INodeType {
let requestOptions;
if(!body.payload_json){
if (!body.payload_json) {
requestOptions = {
resolveWithFullResponse: true,
method: 'POST',
@@ -213,7 +220,7 @@ export class Discord implements INodeType {
},
json: true,
};
}else {
} else {
requestOptions = {
resolveWithFullResponse: true,
method: 'POST',
@@ -236,9 +243,7 @@ export class Discord implements INodeType {
// remaining requests 0
// https://discord.com/developers/docs/topics/rate-limits
if (!+remainingRatelimit) {
await new Promise<void>((resolve) =>
setTimeout(resolve, resetAfter || 1000),
);
await new Promise<void>((resolve) => setTimeout(resolve, resetAfter || 1000));
}
break;
@@ -249,9 +254,7 @@ export class Discord implements INodeType {
if (error.statusCode === 429) {
const retryAfter = error.response?.headers['retry-after'] || 1000;
await new Promise<void>((resolve) =>
setTimeout(resolve, +retryAfter),
);
await new Promise<void>((resolve) => setTimeout(resolve, +retryAfter));
continue;
}
@@ -261,10 +264,9 @@ export class Discord implements INodeType {
} while (--maxTries);
if (maxTries <= 0) {
throw new NodeApiError(
this.getNode(),
{ error: 'Could not send Webhook message. Max amount of rate-limit retries reached.' },
);
throw new NodeApiError(this.getNode(), {
error: 'Could not send Webhook message. Max amount of rate-limit retries reached.',
});
}
returnData.push({ success: true });