mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 04:47:29 -08:00
⚡ Improvements
This commit is contained in:
parent
91c40367e1
commit
4e9490a88d
|
@ -241,13 +241,26 @@ export class ActiveWorkflowRunner {
|
|||
}
|
||||
|
||||
} catch (error) {
|
||||
// The workflow was saved with two webhooks with the
|
||||
// same path/method so delete all webhooks saved
|
||||
|
||||
let errorMessage = '';
|
||||
|
||||
await Db.collections.Webhook?.delete({ workflowId: workflow.id });
|
||||
|
||||
// then show error to the user
|
||||
throw new Error(error.message || error.detail);
|
||||
// if it's a workflow from the the insert
|
||||
// TODO check if there is standard error code for deplicate key violation that works
|
||||
// with all databases
|
||||
if (error.name === 'QueryFailedError') {
|
||||
|
||||
errorMessage = `The webhook path [${webhook.webhookPath}] and method [${webhook.method}] already exist.`;
|
||||
|
||||
} else if (error.detail) {
|
||||
// it's a error runnig the webhook methods (checkExists, create)
|
||||
errorMessage = error.detail;
|
||||
} else {
|
||||
errorMessage = error;
|
||||
}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
// Save static data!
|
||||
|
|
|
@ -44,7 +44,6 @@ export interface IDatabaseCollections {
|
|||
}
|
||||
|
||||
export interface IWebhookDb {
|
||||
id?: number | ObjectID;
|
||||
workflowId: number | string | ObjectID;
|
||||
webhookPath: string;
|
||||
method: string;
|
||||
|
|
|
@ -141,12 +141,14 @@ export class TestWebhooks {
|
|||
let key: string;
|
||||
for (const webhookData of webhooks) {
|
||||
key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
|
||||
|
||||
await this.activeWebhooks!.add(workflow, webhookData, mode);
|
||||
|
||||
this.testWebhookData[key] = {
|
||||
sessionId,
|
||||
timeout,
|
||||
workflowData,
|
||||
};
|
||||
await this.activeWebhooks!.add(workflow, webhookData, mode);
|
||||
|
||||
// Save static data!
|
||||
this.testWebhookData[key].workflowData.staticData = workflow.staticData;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Unique,
|
||||
ObjectIdColumn,
|
||||
ObjectID,
|
||||
PrimaryColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
|
@ -11,19 +9,15 @@ import {
|
|||
} from '../../Interfaces';
|
||||
|
||||
@Entity()
|
||||
@Unique(['webhookPath', 'method'])
|
||||
export class WebhookEntity implements IWebhookDb {
|
||||
|
||||
@ObjectIdColumn()
|
||||
id: ObjectID;
|
||||
|
||||
@Column()
|
||||
workflowId: number;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
webhookPath: string;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
method: string;
|
||||
|
||||
@Column()
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Unique,
|
||||
PrimaryGeneratedColumn,
|
||||
PrimaryColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
|
@ -10,19 +9,15 @@ import {
|
|||
} from '../../Interfaces';
|
||||
|
||||
@Entity()
|
||||
@Unique(['webhookPath', 'method'])
|
||||
export class WebhookEntity implements IWebhookDb {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
workflowId: number;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
webhookPath: string;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
method: string;
|
||||
|
||||
@Column()
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Unique,
|
||||
PrimaryGeneratedColumn,
|
||||
PrimaryColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
|
@ -10,19 +9,15 @@ import {
|
|||
} from '../../';
|
||||
|
||||
@Entity()
|
||||
@Unique(['webhookPath', 'method'])
|
||||
export class WebhookEntity implements IWebhookDb {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
workflowId: number;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
webhookPath: string;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
method: string;
|
||||
|
||||
@Column()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import {
|
||||
MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
import * as config from '../../../../config';
|
||||
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
import {MigrationInterface, QueryRunner} from 'typeorm';
|
||||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
IWorkflowDb,
|
||||
NodeTypes,
|
||||
WebhookHelpers,
|
||||
} from '../../..';
|
||||
|
||||
import {
|
||||
Workflow,
|
||||
} from 'n8n-workflow/dist/src/Workflow';
|
||||
|
||||
import { IWorkflowDb, NodeTypes, WebhookHelpers } from '../../..';
|
||||
import { Workflow } from 'n8n-workflow/dist/src/Workflow';
|
||||
import {
|
||||
IWebhookDb,
|
||||
} from '../../../Interfaces';
|
||||
|
@ -18,7 +29,7 @@ export class WebhookModel1589476000887 implements MigrationInterface {
|
|||
tablePrefix = schema + '.' + tablePrefix;
|
||||
}
|
||||
|
||||
await queryRunner.query(`CREATE TABLE ${tablePrefix}webhook_entity ("id" SERIAL NOT NULL, "workflowId" integer NOT NULL, "webhookPath" character varying NOT NULL, "method" character varying NOT NULL, "node" character varying NOT NULL, CONSTRAINT "UQ_b21ace2e13596ccd87dc9bf4ea6" UNIQUE ("webhookPath", "method"), CONSTRAINT "PK_202217c8b912cf70b93b1e87256" PRIMARY KEY ("id"))`, undefined);
|
||||
await queryRunner.query(`CREATE TABLE ${tablePrefix}webhook_entity ("workflowId" integer NOT NULL, "webhookPath" character varying NOT NULL, "method" character varying NOT NULL, "node" character varying NOT NULL, CONSTRAINT "PK_b21ace2e13596ccd87dc9bf4ea6" PRIMARY KEY ("webhookPath", "method"))`, undefined);
|
||||
|
||||
const workflows = await queryRunner.query(`SELECT * FROM ${tablePrefix}workflow_entity WHERE active=true`) as IWorkflowDb[];
|
||||
const data: IWebhookDb[] = [];
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Unique,
|
||||
PrimaryGeneratedColumn,
|
||||
PrimaryColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
|
@ -10,19 +9,15 @@ import {
|
|||
} from '../../Interfaces';
|
||||
|
||||
@Entity()
|
||||
@Unique(['webhookPath', 'method'])
|
||||
export class WebhookEntity implements IWebhookDb {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
workflowId: number;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
webhookPath: string;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
method: string;
|
||||
|
||||
@Column()
|
||||
|
|
|
@ -35,13 +35,20 @@ export class ActiveWebhooks {
|
|||
throw new Error('Webhooks can only be added for saved workflows as an id is needed!');
|
||||
}
|
||||
|
||||
const webhookKey = this.getWebhookKey(webhookData.httpMethod, webhookData.path);
|
||||
|
||||
//check that there is not a webhook already registed with that path/method
|
||||
if (this.webhookUrls[webhookKey] !== undefined) {
|
||||
throw new Error('There is test wenhook registered on that path');
|
||||
}
|
||||
|
||||
if (this.workflowWebhooks[webhookData.workflowId] === undefined) {
|
||||
this.workflowWebhooks[webhookData.workflowId] = [];
|
||||
}
|
||||
|
||||
// Make the webhook available directly because sometimes to create it successfully
|
||||
// it gets called
|
||||
this.webhookUrls[this.getWebhookKey(webhookData.httpMethod, webhookData.path)] = webhookData;
|
||||
this.webhookUrls[webhookKey] = webhookData;
|
||||
|
||||
const webhookExists = await workflow.runWebhookMethod('checkExists', webhookData, NodeExecuteFunctions, mode, this.testWebhooks);
|
||||
if (webhookExists === false) {
|
||||
|
|
|
@ -1585,6 +1585,11 @@ export default mixins(
|
|||
console.error(e); // eslint-disable-line no-console
|
||||
}
|
||||
node.parameters = nodeParameters !== null ? nodeParameters : {};
|
||||
|
||||
// if it's a webhook and the path is empty set the UUID as the default path
|
||||
if (node.type === 'n8n-nodes-base.webhook' && node.parameters.path === '') {
|
||||
node.parameters.path = node.webhookPath as string;
|
||||
}
|
||||
}
|
||||
|
||||
foundNodeIssues = this.getNodeIssues(nodeType, node);
|
||||
|
|
Loading…
Reference in a new issue