Merge pull request #885 from getmaxun/replica-fix
fix: capture text data replicated
This commit is contained in:
@@ -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;
|
||||
let actionName = this.currentActionName;
|
||||
|
||||
let typeKey = this.currentActionType || "unknown";
|
||||
let subtree =
|
||||
typeKey === "scrapeList"
|
||||
? data?.scrapeList
|
||||
: typeKey === "scrapeSchema"
|
||||
? data?.scrapeSchema
|
||||
: null;
|
||||
|
||||
if (this.currentActionType === "scrapeList") {
|
||||
typeKey = "scrapeList";
|
||||
} else if (this.currentActionType === "scrapeSchema") {
|
||||
typeKey = "scrapeSchema";
|
||||
}
|
||||
if (!subtree) return;
|
||||
|
||||
if (this.currentActionType === "scrapeList" && data.scrapeList) {
|
||||
data = data.scrapeList;
|
||||
} else if (this.currentActionType === "scrapeSchema" && data.scrapeSchema) {
|
||||
data = data.scrapeSchema;
|
||||
}
|
||||
|
||||
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 }) => {
|
||||
|
||||
Reference in New Issue
Block a user