mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Extract from File Node): Detect file encoding (#12081)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -15,6 +15,7 @@ import type {
|
||||
import { ClientOAuth2 } from '@n8n/client-oauth2';
|
||||
import type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import axios from 'axios';
|
||||
import chardet from 'chardet';
|
||||
import crypto, { createHmac } from 'crypto';
|
||||
import FileType from 'file-type';
|
||||
import FormData from 'form-data';
|
||||
@@ -1050,6 +1051,10 @@ export async function getBinaryDataBuffer(
|
||||
return await Container.get(BinaryDataService).getAsBuffer(binaryData);
|
||||
}
|
||||
|
||||
export function detectBinaryEncoding(buffer: Buffer): string {
|
||||
return chardet.detect(buffer) as string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an incoming IBinaryData & related buffer using the configured binary data manager.
|
||||
*
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
getSSHTunnelFunctions,
|
||||
getFileSystemHelperFunctions,
|
||||
getCheckProcessedHelperFunctions,
|
||||
detectBinaryEncoding,
|
||||
} from '@/NodeExecuteFunctions';
|
||||
|
||||
import { BaseExecuteContext } from './base-execute-context';
|
||||
@@ -96,6 +97,7 @@ export class ExecuteContext extends BaseExecuteContext implements IExecuteFuncti
|
||||
assertBinaryData(inputData, node, itemIndex, propertyName, 0),
|
||||
getBinaryDataBuffer: async (itemIndex, propertyName) =>
|
||||
await getBinaryDataBuffer(inputData, itemIndex, propertyName, 0),
|
||||
detectBinaryEncoding: (buffer: Buffer) => detectBinaryEncoding(buffer),
|
||||
};
|
||||
|
||||
this.nodeHelpers = {
|
||||
|
||||
@@ -16,6 +16,7 @@ import { ApplicationError, createDeferredPromise, NodeConnectionType } from 'n8n
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import {
|
||||
assertBinaryData,
|
||||
detectBinaryEncoding,
|
||||
getBinaryDataBuffer,
|
||||
getBinaryHelperFunctions,
|
||||
getRequestHelperFunctions,
|
||||
@@ -69,6 +70,7 @@ export class ExecuteSingleContext extends BaseExecuteContext implements IExecute
|
||||
assertBinaryData(inputData, node, itemIndex, propertyName, inputIndex),
|
||||
getBinaryDataBuffer: async (propertyName, inputIndex = 0) =>
|
||||
await getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex),
|
||||
detectBinaryEncoding: (buffer) => detectBinaryEncoding(buffer),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
assertBinaryData,
|
||||
constructExecutionMetaData,
|
||||
copyInputItems,
|
||||
detectBinaryEncoding,
|
||||
getBinaryDataBuffer,
|
||||
getBinaryHelperFunctions,
|
||||
getCheckProcessedHelperFunctions,
|
||||
@@ -87,6 +88,7 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData
|
||||
assertBinaryData(inputData, node, itemIndex, propertyName, 0),
|
||||
getBinaryDataBuffer: async (itemIndex, propertyName) =>
|
||||
await getBinaryDataBuffer(inputData, itemIndex, propertyName, 0),
|
||||
detectBinaryEncoding: (buffer: Buffer) => detectBinaryEncoding(buffer),
|
||||
|
||||
returnJsonArray,
|
||||
normalizeItems,
|
||||
|
||||
Reference in New Issue
Block a user