Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions server/src/workflow-management/classes/Interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,45 +550,36 @@ 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] = {};
}

this.serializableDataByType[typeKey][actionName] = flattened;

await this.persistDataToDatabase(typeKey, { [actionName]: flattened });
await this.persistDataToDatabase(typeKey, {
[actionName]: flattened,
});

this.socket.emit("serializableCallback", {
type: typeKey,
Expand All @@ -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 }) => {
Expand Down