fix: rm data replication across different actions
This commit is contained in:
@@ -550,37 +550,26 @@ export class WorkflowInterpreter {
|
|||||||
},
|
},
|
||||||
serializableCallback: async (data: any) => {
|
serializableCallback: async (data: any) => {
|
||||||
try {
|
try {
|
||||||
if (!data || typeof data !== "object") return;
|
if (!this.currentActionType || !this.currentActionName) return;
|
||||||
|
|
||||||
if (!this.currentActionType && Array.isArray(data) && data.length > 0) {
|
let typeKey = this.currentActionType;
|
||||||
const first = data[0];
|
let actionName = this.currentActionName;
|
||||||
if (first && Object.keys(first).some(k => k.toLowerCase().includes("label") || k.toLowerCase().includes("text"))) {
|
|
||||||
this.currentActionType = "scrapeSchema";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let typeKey = this.currentActionType || "unknown";
|
let subtree =
|
||||||
|
typeKey === "scrapeList"
|
||||||
|
? data?.scrapeList
|
||||||
|
: typeKey === "scrapeSchema"
|
||||||
|
? data?.scrapeSchema
|
||||||
|
: null;
|
||||||
|
|
||||||
if (this.currentActionType === "scrapeList") {
|
if (!subtree) return;
|
||||||
typeKey = "scrapeList";
|
|
||||||
} else if (this.currentActionType === "scrapeSchema") {
|
|
||||||
typeKey = "scrapeSchema";
|
|
||||||
}
|
|
||||||
|
|
||||||
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") {
|
if (typeKey === "scrapeList") {
|
||||||
actionName = this.getUniqueActionName(typeKey, this.currentActionName);
|
actionName = this.getUniqueActionName(typeKey, actionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const flattened = Array.isArray(data)
|
const values = Object.values(subtree);
|
||||||
? data
|
const flattened = values.flat();
|
||||||
: (data?.List ?? (data && typeof data === 'object' ? Object.values(data).flat?.() ?? data : []));
|
|
||||||
|
|
||||||
if (!this.serializableDataByType[typeKey]) {
|
if (!this.serializableDataByType[typeKey]) {
|
||||||
this.serializableDataByType[typeKey] = {};
|
this.serializableDataByType[typeKey] = {};
|
||||||
@@ -588,7 +577,9 @@ export class WorkflowInterpreter {
|
|||||||
|
|
||||||
this.serializableDataByType[typeKey][actionName] = flattened;
|
this.serializableDataByType[typeKey][actionName] = flattened;
|
||||||
|
|
||||||
await this.persistDataToDatabase(typeKey, { [actionName]: flattened });
|
await this.persistDataToDatabase(typeKey, {
|
||||||
|
[actionName]: flattened,
|
||||||
|
});
|
||||||
|
|
||||||
this.socket.emit("serializableCallback", {
|
this.socket.emit("serializableCallback", {
|
||||||
type: typeKey,
|
type: typeKey,
|
||||||
@@ -599,7 +590,7 @@ export class WorkflowInterpreter {
|
|||||||
this.currentActionType = null;
|
this.currentActionType = null;
|
||||||
this.currentActionName = null;
|
this.currentActionName = null;
|
||||||
} catch (err: any) {
|
} 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 }) => {
|
binaryCallback: async (payload: { name: string; data: Buffer; mimeType: string }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user