@atom8n/n8n 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -58,6 +58,7 @@ let CliController = CliController_1 = class CliController {
|
|
|
58
58
|
const fileData = body.workflowData;
|
|
59
59
|
const chatInput = body.chatInput;
|
|
60
60
|
const inputData = body.inputData;
|
|
61
|
+
const fileModifiedAt = body.fileModifiedAt;
|
|
61
62
|
this.logger.info(`[cli] inputData: ${inputData ? JSON.stringify(inputData) : '(none)'}`);
|
|
62
63
|
if (!fileData.nodes || !Array.isArray(fileData.nodes)) {
|
|
63
64
|
res.status(400).json({ error: 'Workflow does not contain valid nodes' });
|
|
@@ -70,7 +71,7 @@ let CliController = CliController_1 = class CliController {
|
|
|
70
71
|
this.logger.info(`[cli] Workflow: "${fileData.name}", Nodes: ${fileData.nodes.length}`);
|
|
71
72
|
try {
|
|
72
73
|
const user = await this.ownershipService.getInstanceOwner();
|
|
73
|
-
const workflowId = await this.syncWorkflow(fileData, user.id);
|
|
74
|
+
const workflowId = await this.syncWorkflow(fileData, user.id, fileModifiedAt);
|
|
74
75
|
const workflow = await this.workflowRepository.findOneBy({ id: workflowId });
|
|
75
76
|
if (!workflow) {
|
|
76
77
|
res.status(500).json({ error: 'Failed to sync workflow to database' });
|
|
@@ -228,17 +229,19 @@ let CliController = CliController_1 = class CliController {
|
|
|
228
229
|
});
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
|
-
async syncWorkflow(fileData, userId) {
|
|
232
|
+
async syncWorkflow(fileData, userId, fileModifiedAt) {
|
|
232
233
|
if (fileData.id && (0, utils_1.isWorkflowIdValid)(fileData.id)) {
|
|
233
234
|
const existing = await this.workflowRepository.findOneBy({ id: fileData.id });
|
|
234
235
|
if (existing) {
|
|
235
|
-
const fileUpdatedAt =
|
|
236
|
-
? new Date(fileData.updatedAt)
|
|
237
|
-
: null;
|
|
236
|
+
const fileUpdatedAt = fileModifiedAt ? new Date(fileModifiedAt) : null;
|
|
238
237
|
const serverUpdatedAt = existing.updatedAt
|
|
239
238
|
? new Date(existing.updatedAt)
|
|
240
239
|
: null;
|
|
241
|
-
|
|
240
|
+
this.logger.info(`[cli] Found existing workflow (ID match): ${existing.id}, ` +
|
|
241
|
+
`fileUpdatedAt=${fileUpdatedAt?.toISOString() ?? 'null'}, ` +
|
|
242
|
+
`serverUpdatedAt=${serverUpdatedAt?.toISOString() ?? 'null'}`);
|
|
243
|
+
const shouldUpdate = !fileUpdatedAt || !serverUpdatedAt || fileUpdatedAt >= serverUpdatedAt;
|
|
244
|
+
if (shouldUpdate) {
|
|
242
245
|
this.logger.info(`[cli] Updating existing workflow (ID match): ${existing.id}`);
|
|
243
246
|
await this.workflowRepository.update(existing.id, {
|
|
244
247
|
nodes: fileData.nodes,
|
|
@@ -249,7 +252,8 @@ let CliController = CliController_1 = class CliController {
|
|
|
249
252
|
});
|
|
250
253
|
}
|
|
251
254
|
else {
|
|
252
|
-
this.logger.info(`[cli] Using existing workflow (ID match): ${existing.id}`
|
|
255
|
+
this.logger.info(`[cli] Using existing workflow (ID match): ${existing.id} ` +
|
|
256
|
+
`(server is newer: ${serverUpdatedAt.toISOString()} > ${fileUpdatedAt.toISOString()})`);
|
|
253
257
|
}
|
|
254
258
|
return existing.id;
|
|
255
259
|
}
|
|
@@ -257,13 +261,15 @@ let CliController = CliController_1 = class CliController {
|
|
|
257
261
|
if (fileData.name) {
|
|
258
262
|
const existing = await this.workflowRepository.findOneBy({ name: fileData.name });
|
|
259
263
|
if (existing) {
|
|
260
|
-
const fileUpdatedAt =
|
|
261
|
-
? new Date(fileData.updatedAt)
|
|
262
|
-
: null;
|
|
264
|
+
const fileUpdatedAt = fileModifiedAt ? new Date(fileModifiedAt) : null;
|
|
263
265
|
const serverUpdatedAt = existing.updatedAt
|
|
264
266
|
? new Date(existing.updatedAt)
|
|
265
267
|
: null;
|
|
266
|
-
|
|
268
|
+
this.logger.info(`[cli] Found existing workflow (name match): ${existing.id}, ` +
|
|
269
|
+
`fileUpdatedAt=${fileUpdatedAt?.toISOString() ?? 'null'}, ` +
|
|
270
|
+
`serverUpdatedAt=${serverUpdatedAt?.toISOString() ?? 'null'}`);
|
|
271
|
+
const shouldUpdate = !fileUpdatedAt || !serverUpdatedAt || fileUpdatedAt >= serverUpdatedAt;
|
|
272
|
+
if (shouldUpdate) {
|
|
267
273
|
this.logger.info(`[cli] Updating existing workflow (name match): ${existing.id}`);
|
|
268
274
|
await this.workflowRepository.update(existing.id, {
|
|
269
275
|
nodes: fileData.nodes,
|
|
@@ -274,7 +280,8 @@ let CliController = CliController_1 = class CliController {
|
|
|
274
280
|
});
|
|
275
281
|
}
|
|
276
282
|
else {
|
|
277
|
-
this.logger.info(`[cli] Using existing workflow (name match): ${existing.id}`
|
|
283
|
+
this.logger.info(`[cli] Using existing workflow (name match): ${existing.id} ` +
|
|
284
|
+
`(server is newer: ${serverUpdatedAt.toISOString()} > ${fileUpdatedAt.toISOString()})`);
|
|
278
285
|
}
|
|
279
286
|
return existing.id;
|
|
280
287
|
}
|