| | import { Logger } from '@n8n/backend-common'; |
| | import { Container } from '@n8n/di'; |
| | import type { BinaryData } from 'n8n-core'; |
| | import { BinaryDataConfig, BinaryDataService } from 'n8n-core'; |
| | import type { IRun, WorkflowExecuteMode } from 'n8n-workflow'; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export async function restoreBinaryDataId( |
| | run: IRun, |
| | executionId: string, |
| | workflowExecutionMode: WorkflowExecuteMode, |
| | ) { |
| | if (workflowExecutionMode !== 'webhook' || Container.get(BinaryDataConfig).mode === 'default') { |
| | return; |
| | } |
| |
|
| | try { |
| | const { runData } = run.data.resultData; |
| |
|
| | const promises = Object.keys(runData).map(async (nodeName) => { |
| | const binaryDataId = runData[nodeName]?.[0]?.data?.main?.[0]?.[0]?.binary?.data?.id; |
| |
|
| | if (!binaryDataId) return; |
| |
|
| | const [mode, fileId] = binaryDataId.split(':') as [BinaryData.StoredMode, string]; |
| |
|
| | const isMissingExecutionId = fileId.includes('/temp/'); |
| |
|
| | if (!isMissingExecutionId) return; |
| |
|
| | const correctFileId = fileId.replace('temp', executionId); |
| |
|
| | await Container.get(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 = Container.get(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 }); |
| | } |
| | } |
| |
|