diff --git a/server/src/workflow-management/classes/Interpreter.ts b/server/src/workflow-management/classes/Interpreter.ts index 71cac8b70..9291091ec 100644 --- a/server/src/workflow-management/classes/Interpreter.ts +++ b/server/src/workflow-management/classes/Interpreter.ts @@ -550,37 +550,26 @@ export class WorkflowInterpreter { }, serializableCallback: async (data: any) => { try { - if (!data || typeof data !== "object") return; + if (!this.currentActionType || !this.currentActionName) return; - if (!this.currentActionType && Array.isArray(data) && data.length > 0) { - const first = data[0]; - if (first && Object.keys(first).some(k => k.toLowerCase().includes("label") || k.toLowerCase().includes("text"))) { - this.currentActionType = "scrapeSchema"; - } - } - - let typeKey = this.currentActionType || "unknown"; + let typeKey = this.currentActionType; + let actionName = this.currentActionName; - if (this.currentActionType === "scrapeList") { - typeKey = "scrapeList"; - } else if (this.currentActionType === "scrapeSchema") { - typeKey = "scrapeSchema"; - } + let subtree = + typeKey === "scrapeList" + ? data?.scrapeList + : typeKey === "scrapeSchema" + ? data?.scrapeSchema + : null; - if (this.currentActionType === "scrapeList" && data.scrapeList) { - data = data.scrapeList; - } else if (this.currentActionType === "scrapeSchema" && data.scrapeSchema) { - data = data.scrapeSchema; - } + if (!subtree) return; - let actionName = this.currentActionName || ""; if (typeKey === "scrapeList") { - actionName = this.getUniqueActionName(typeKey, this.currentActionName); + actionName = this.getUniqueActionName(typeKey, actionName); } - const flattened = Array.isArray(data) - ? data - : (data?.List ?? (data && typeof data === 'object' ? Object.values(data).flat?.() ?? data : [])); + const values = Object.values(subtree); + const flattened = values.flat(); if (!this.serializableDataByType[typeKey]) { this.serializableDataByType[typeKey] = {}; @@ -588,7 +577,9 @@ export class WorkflowInterpreter { this.serializableDataByType[typeKey][actionName] = flattened; - await this.persistDataToDatabase(typeKey, { [actionName]: flattened }); + await this.persistDataToDatabase(typeKey, { + [actionName]: flattened, + }); this.socket.emit("serializableCallback", { type: typeKey, @@ -599,7 +590,7 @@ export class WorkflowInterpreter { this.currentActionType = null; this.currentActionName = null; } catch (err: any) { - logger.log('error', `serializableCallback handler failed: ${err.message}`); + logger.log("error", `serializableCallback failed: ${err.message}`); } }, binaryCallback: async (payload: { name: string; data: Buffer; mimeType: string }) => {