refactor: Delete a lot of unused and duplicate code in Server and WebhookServer (#5080)
* store n8n version string in a const and use that everywhere * reduce code duplication between Server and WebhookServer * unify redis checks * fix linting
This commit is contained in:
committed by
GitHub
parent
b67f803cbe
commit
8b19fdd5f0
@@ -5,28 +5,19 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import express from 'express';
|
||||
import { join as pathJoin } from 'path';
|
||||
import { readFile as fsReadFile } from 'fs/promises';
|
||||
import type { n8n } from 'n8n-core';
|
||||
import {
|
||||
ExecutionError,
|
||||
IDataObject,
|
||||
INode,
|
||||
IRunExecutionData,
|
||||
jsonParse,
|
||||
Workflow,
|
||||
WorkflowExecuteMode,
|
||||
} from 'n8n-workflow';
|
||||
import { validate } from 'class-validator';
|
||||
import config from '@/config';
|
||||
import * as Db from '@/Db';
|
||||
import {
|
||||
ICredentialsDb,
|
||||
IExecutionDb,
|
||||
IExecutionFlattedDb,
|
||||
IPackageVersions,
|
||||
IWorkflowDb,
|
||||
} from '@/Interfaces';
|
||||
import { ICredentialsDb, IExecutionDb, IExecutionFlattedDb, IWorkflowDb } from '@/Interfaces';
|
||||
import * as ResponseHelper from '@/ResponseHelper';
|
||||
// eslint-disable-next-line import/order
|
||||
import { Like } from 'typeorm';
|
||||
@@ -34,9 +25,6 @@ import { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import { TagEntity } from '@db/entities/TagEntity';
|
||||
import { User } from '@db/entities/User';
|
||||
import { CLI_DIR } from '@/constants';
|
||||
|
||||
let versionCache: IPackageVersions | undefined;
|
||||
|
||||
/**
|
||||
* Returns the base URL n8n is reachable from
|
||||
@@ -62,27 +50,8 @@ export function getSessionId(req: express.Request): string | undefined {
|
||||
return req.headers.sessionid as string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information which version of the packages are installed
|
||||
*/
|
||||
export async function getVersions(): Promise<IPackageVersions> {
|
||||
if (versionCache !== undefined) {
|
||||
return versionCache;
|
||||
}
|
||||
|
||||
const packageFile = await fsReadFile(pathJoin(CLI_DIR, 'package.json'), 'utf8');
|
||||
const packageData = jsonParse<n8n.PackageJson>(packageFile);
|
||||
|
||||
versionCache = {
|
||||
cli: packageData.version,
|
||||
};
|
||||
|
||||
return versionCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts configuration schema for key
|
||||
*
|
||||
*/
|
||||
function extractSchemaForKey(configKey: string, configSchema: IDataObject): IDataObject {
|
||||
const configKeyParts = configKey.split('.');
|
||||
|
||||
Reference in New Issue
Block a user