refactor(core): Standardize filename casing for controllers and databases (no-changelog) (#10564)
This commit is contained in:
53
packages/cli/src/databases/entities/webhook-entity.ts
Normal file
53
packages/cli/src/databases/entities/webhook-entity.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { IHttpRequestMethods } from 'n8n-workflow';
|
||||
import { Column, Entity, Index, PrimaryColumn } from '@n8n/typeorm';
|
||||
|
||||
@Entity()
|
||||
@Index(['webhookId', 'method', 'pathLength'])
|
||||
export class WebhookEntity {
|
||||
@Column()
|
||||
workflowId: string;
|
||||
|
||||
@PrimaryColumn()
|
||||
webhookPath: string;
|
||||
|
||||
@PrimaryColumn({ type: 'text' })
|
||||
method: IHttpRequestMethods;
|
||||
|
||||
@Column()
|
||||
node: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
webhookId?: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
pathLength?: number;
|
||||
|
||||
/**
|
||||
* Unique section of webhook path.
|
||||
*
|
||||
* - Static: `${uuid}` or `user/defined/path`
|
||||
* - Dynamic: `${uuid}/user/:id/posts`
|
||||
*
|
||||
* Appended to `${instanceUrl}/webhook/` or `${instanceUrl}/test-webhook/`.
|
||||
*/
|
||||
private get uniquePath() {
|
||||
return this.webhookPath.includes(':')
|
||||
? [this.webhookId, this.webhookPath].join('/')
|
||||
: this.webhookPath;
|
||||
}
|
||||
|
||||
get cacheKey() {
|
||||
return `webhook:${this.method}-${this.uniquePath}`;
|
||||
}
|
||||
|
||||
get staticSegments() {
|
||||
return this.webhookPath.split('/').filter((s) => !s.startsWith(':'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the webhook has at least one dynamic path segment, e.g. `:id` in `<uuid>/user/:id/posts`.
|
||||
*/
|
||||
get isDynamic() {
|
||||
return this.webhookPath.split('/').some((s) => s.startsWith(':'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user