Skip to content

Commit 71c39b1

Browse files
authored
Merge pull request #885 from getmaxun/replica-fix
fix: capture text data replicated
2 parents ddf0021 + c20f3fb commit 71c39b1

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

server/src/workflow-management/classes/Interpreter.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -550,45 +550,36 @@ export class WorkflowInterpreter {
550550
},
551551
serializableCallback: async (data: any) => {
552552
try {
553-
if (!data || typeof data !== "object") return;
553+
if (!this.currentActionType || !this.currentActionName) return;
554554

555-
if (!this.currentActionType && Array.isArray(data) && data.length > 0) {
556-
const first = data[0];
557-
if (first && Object.keys(first).some(k => k.toLowerCase().includes("label") || k.toLowerCase().includes("text"))) {
558-
this.currentActionType = "scrapeSchema";
559-
}
560-
}
561-
562-
let typeKey = this.currentActionType || "unknown";
555+
let typeKey = this.currentActionType;
556+
let actionName = this.currentActionName;
563557

564-
if (this.currentActionType === "scrapeList") {
565-
typeKey = "scrapeList";
566-
} else if (this.currentActionType === "scrapeSchema") {
567-
typeKey = "scrapeSchema";
568-
}
558+
let subtree =
559+
typeKey === "scrapeList"
560+
? data?.scrapeList
561+
: typeKey === "scrapeSchema"
562+
? data?.scrapeSchema
563+
: null;
569564

570-
if (this.currentActionType === "scrapeList" && data.scrapeList) {
571-
data = data.scrapeList;
572-
} else if (this.currentActionType === "scrapeSchema" && data.scrapeSchema) {
573-
data = data.scrapeSchema;
574-
}
565+
if (!subtree) return;
575566

576-
let actionName = this.currentActionName || "";
577567
if (typeKey === "scrapeList") {
578-
actionName = this.getUniqueActionName(typeKey, this.currentActionName);
568+
actionName = this.getUniqueActionName(typeKey, actionName);
579569
}
580570

581-
const flattened = Array.isArray(data)
582-
? data
583-
: (data?.List ?? (data && typeof data === 'object' ? Object.values(data).flat?.() ?? data : []));
571+
const values = Object.values(subtree);
572+
const flattened = values.flat();
584573

585574
if (!this.serializableDataByType[typeKey]) {
586575
this.serializableDataByType[typeKey] = {};
587576
}
588577

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

591-
await this.persistDataToDatabase(typeKey, { [actionName]: flattened });
580+
await this.persistDataToDatabase(typeKey, {
581+
[actionName]: flattened,
582+
});
592583

593584
this.socket.emit("serializableCallback", {
594585
type: typeKey,
@@ -599,7 +590,7 @@ export class WorkflowInterpreter {
599590
this.currentActionType = null;
600591
this.currentActionName = null;
601592
} catch (err: any) {
602-
logger.log('error', `serializableCallback handler failed: ${err.message}`);
593+
logger.log("error", `serializableCallback failed: ${err.message}`);
603594
}
604595
},
605596
binaryCallback: async (payload: { name: string; data: Buffer; mimeType: string }) => {

0 commit comments

Comments
 (0)