UNPKG

n8n

Version:

n8n Workflow Automation Tool

47 lines 2.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.restoreBinaryDataId = restoreBinaryDataId; const typedi_1 = __importDefault(require("typedi")); const n8n_core_1 = require("n8n-core"); const config_1 = __importDefault(require("../config")); const Logger_1 = require("../Logger"); async function restoreBinaryDataId(run, executionId, workflowExecutionMode) { if (workflowExecutionMode !== 'webhook' || config_1.default.getEnv('binaryDataManager.mode') === 'default') { return; } try { const { runData } = run.data.resultData; const promises = Object.keys(runData).map(async (nodeName) => { var _a, _b, _c, _d, _e, _f, _g, _h; const binaryDataId = (_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = runData[nodeName]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.main) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.binary) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.id; if (!binaryDataId) return; const [mode, fileId] = binaryDataId.split(':'); const isMissingExecutionId = fileId.includes('/temp/'); if (!isMissingExecutionId) return; const correctFileId = fileId.replace('temp', executionId); await typedi_1.default.get(n8n_core_1.BinaryDataService).rename(fileId, correctFileId); const correctBinaryDataId = `${mode}:${correctFileId}`; run.data.resultData.runData[nodeName][0].data.main[0][0].binary.data.id = correctBinaryDataId; }); await Promise.all(promises); } catch (e) { const error = e instanceof Error ? e : new Error(`${e}`); const logger = typedi_1.default.get(Logger_1.Logger); if (error.message.includes('ENOENT')) { logger.warn('Failed to restore binary data ID - No such file or dir', { executionId, error, }); return; } logger.error('Failed to restore binary data ID - Unknown error', { executionId, error }); } } //# sourceMappingURL=restoreBinaryDataId.js.map