कारतोफ्फेलस्क्रिप्ट™
2023-09-06 12:38:37 +02:00
committed by GitHub
parent 25dc4d7825
commit 273d0913fe
11 changed files with 388 additions and 111 deletions

View File

@@ -71,8 +71,6 @@
"@types/bcryptjs": "^2.4.2",
"@types/compression": "1.0.1",
"@types/connect-history-api-fallback": "^1.3.1",
"@types/content-disposition": "^0.5.5",
"@types/content-type": "^1.1.5",
"@types/convict": "^6.1.1",
"@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.6",
@@ -121,8 +119,6 @@
"class-validator": "^0.14.0",
"compression": "^1.7.4",
"connect-history-api-fallback": "^1.6.0",
"content-disposition": "^0.5.4",
"content-type": "^1.0.4",
"convict": "^6.2.4",
"cookie-parser": "^1.4.6",
"crypto-js": "~4.1.1",

View File

@@ -1,9 +1,8 @@
import { parse as parseContentDisposition } from 'content-disposition';
import { parse as parseContentType } from 'content-type';
import getRawBody from 'raw-body';
import type { Request, RequestHandler } from 'express';
import { parse as parseQueryString } from 'querystring';
import { Parser as XmlParser } from 'xml2js';
import { parseIncomingMessage } from 'n8n-core';
import { jsonParse } from 'n8n-workflow';
import config from '@/config';
import { UnprocessableRequestError } from '@/ResponseHelper';
@@ -17,26 +16,7 @@ const xmlParser = new XmlParser({
const payloadSizeMax = config.getEnv('endpoints.payloadSizeMax');
export const rawBodyReader: RequestHandler = async (req, res, next) => {
if ('content-type' in req.headers) {
const { type: contentType, parameters } = (() => {
try {
return parseContentType(req);
} catch {
return { type: undefined, parameters: undefined };
}
})();
req.contentType = contentType;
req.encoding = (parameters?.charset ?? 'utf-8').toLowerCase() as BufferEncoding;
const contentDispositionHeader = req.headers['content-disposition'];
if (contentDispositionHeader?.length) {
const {
type,
parameters: { filename },
} = parseContentDisposition(contentDispositionHeader);
req.contentDisposition = { type, filename };
}
}
parseIncomingMessage(req);
req.readRawBody = async () => {
if (!req.rawBody) {