n8n-nodes-base
Version:
Base nodes of n8n
49 lines • 2.44 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorMapper = errorMapper;
exports.escapeSpecialCharacters = escapeSpecialCharacters;
exports.normalizeFileSelector = normalizeFileSelector;
const n8n_workflow_1 = require("n8n-workflow");
const node_path_1 = __importDefault(require("node:path"));
function errorMapper(error, itemIndex, context) {
let message;
let description;
if (typeof error.message === 'string') {
if (error.message.includes('Cannot create a string longer than')) {
message = 'The file is too large';
description =
'The binary file you are attempting to read exceeds 512MB, which is limit when using default binary data mode, try using the filesystem binary mode. More information <a href="https://docs.n8n.io/hosting/scaling/binary-data/" target="_blank">here</a>.';
}
else if (error.message.includes('EACCES') && context?.operation === 'read') {
const path = error.path || context?.filePath;
message = `You don't have the permissions to access ${path}`;
description =
"Verify that the path specified in 'File(s) Selector' is correct, or change the file(s) permissions if needed";
}
else if (error.message.includes('EACCES') && context?.operation === 'write') {
const path = error.path || context?.filePath;
message = `You don't have the permissions to write the file ${path}`;
description =
"Specify another destination folder in 'File Path and Name', or change the permissions of the parent folder";
}
}
return new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex, message, description });
}
function escapeSpecialCharacters(str) {
// Escape parentheses
str = str.replace(/[()]/g, '\\$&');
return str;
}
function normalizeFileSelector(fileSelectorRaw) {
let fileSelector = String(fileSelectorRaw);
const isWindows = /^[a-zA-Z]:/.test(fileSelector);
if (isWindows) {
fileSelector = node_path_1.default.win32.normalize(fileSelector).replace(/\\/g, '/');
}
fileSelector = escapeSpecialCharacters(fileSelector);
return fileSelector;
}
//# sourceMappingURL=utils.js.map