UNPKG

@rxap/n8n-utilities

Version:

This package provides utility functions and classes for n8n nodes, including custom authentication methods (Bearer Auth, Oauth2 Proxy Auth, Base URL), a decorator for capturing execution errors, and base classes for creating nodes from OpenAPI specificati

35 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addFilesToResults = addFilesToResults; const tslib_1 = require("tslib"); const fs_1 = require("fs"); const path_1 = require("path"); /** * Recursively adds files from a directory to the binary data of a result object. * Traverses through the directory and its subdirectories, reading files * and preparing their binary data to include in the provided result object. * * @param {string} dir - The directory path to process. * @param {string} workDir - The base working directory, used to generate relative file paths. * @param {INodeExecutionData & { binary: IBinaryKeyData }} result - The result object to which binary data of files will be added. * @param {function} prepareBinaryData - A function that prepares binary data from a file's buffer, file path, and MIME type. * It returns a Promise that resolves to a prepared IBinaryData object. * @return {Promise<void>} A promise that resolves when all files in the directory and its subdirectories have been processed and their binary data added to the result. */ function addFilesToResults(dir, workDir, result, prepareBinaryData) { return tslib_1.__awaiter(this, void 0, void 0, function* () { for (const fragment of (0, fs_1.readdirSync)(dir)) { const path = (0, path_1.join)(dir, fragment); if ((0, fs_1.statSync)(path).isDirectory()) { yield addFilesToResults(path, workDir, result, prepareBinaryData); } else { const buffer = (0, fs_1.readFileSync)(path, null); const shortPath = (0, path_1.relative)(workDir, path); const name = shortPath.split('/').join('_').split('.').join('_'); result.binary[name] = yield prepareBinaryData(buffer, path); } } }); } //# sourceMappingURL=add-files-to-results.js.map