You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
973 B
TypeScript
41 lines
973 B
TypeScript
export interface RuntimeNodeData {
|
|
nodeId?: string;
|
|
input?: Record<string, any>;
|
|
[key: string]: any;
|
|
}
|
|
|
|
const isRuntimeNode = (item: any): item is RuntimeNodeData => {
|
|
return !!item && typeof item === 'object' && typeof item.nodeId === 'string';
|
|
};
|
|
|
|
export const flattenRuntimeNodeData = (runtimeData: any): RuntimeNodeData[] => {
|
|
if (!Array.isArray(runtimeData)) {
|
|
return [];
|
|
}
|
|
|
|
return runtimeData.reduce<RuntimeNodeData[]>((nodes, item) => {
|
|
if (isRuntimeNode(item)) {
|
|
nodes.push(item);
|
|
return nodes;
|
|
}
|
|
|
|
if (Array.isArray(item?.nodes)) {
|
|
nodes.push(...item.nodes.filter(isRuntimeNode));
|
|
}
|
|
|
|
return nodes;
|
|
}, []);
|
|
};
|
|
|
|
export const getRuntimeImageUrl = (
|
|
runtimeData: any,
|
|
nodeId: string
|
|
): string => {
|
|
const nodeData = flattenRuntimeNodeData(runtimeData).find(
|
|
(item) => item.nodeId === nodeId
|
|
);
|
|
const imageUrl = nodeData?.input?.in;
|
|
|
|
return typeof imageUrl === 'string' ? imageUrl.trim() : '';
|
|
};
|