Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
69 changes: 29 additions & 40 deletions server/src/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,51 +167,26 @@ function updateTypeActionsInWorkflow(workflow: any[], credentials: Credentials)
return workflow.map(step => {
if (!step.what) return step;

const indicesToRemove = new Set<number>();
step.what.forEach((action: any, index: number) => {
if (!action.action || !action.args?.[0]) return;

if ((action.action === 'type' || action.action === 'press') && credentials[action.args[0]]) {
indicesToRemove.add(index);

if (step.what[index + 1]?.action === 'waitForLoadState') {
indicesToRemove.add(index + 1);
}
}
});

const filteredWhat = step.what.filter((_: any, index: number) => !indicesToRemove.has(index));

Object.entries(credentials).forEach(([selector, credentialInfo]) => {
const clickIndex = filteredWhat.findIndex((action: any) =>
action.action === 'click' && action.args?.[0] === selector
);

if (clickIndex !== -1) {
const chars = credentialInfo.value.split('');
step.what = step.what.map((action: any) => {
if (action.action === 'type' && action.args?.length >= 2) {
const selector = action.args[0];

chars.forEach((char, i) => {
filteredWhat.splice(clickIndex + 1 + (i * 2), 0, {
action: 'type',
if (credentials[selector]) {
return {
...action,
args: [
selector,
encrypt(char),
credentialInfo.type
encrypt(credentials[selector].value),
credentials[selector].type
]
});

filteredWhat.splice(clickIndex + 2 + (i * 2), 0, {
action: 'waitForLoadState',
args: ['networkidle']
});
});
};
}
}

return action;
});

return {
...step,
what: filteredWhat
};
return step;
});
}

Expand Down Expand Up @@ -281,9 +256,23 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
}
}

robot.set('recording', { ...robot.recording, workflow });
const updates: any = {
recording: {
...robot.recording,
workflow
}
};

await robot.save();
if (name) {
updates.recording_meta = {
...robot.recording_meta,
name
};
}

await Robot.update(updates, {
where: { 'recording_meta.id': id }
});
Comment on lines +312 to +328
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add type safety and validation for the update operation.

The update operation could fail if any of the spread properties are undefined. Consider adding type checking and validation.

-    const updates: any = {
+    const updates: {
+      recording?: {
+        workflow: any[];
+        [key: string]: any;
+      };
+      recording_meta?: {
+        name: string;
+        [key: string]: any;
+      };
+    } = {};
+
+    // Validate recording object before spread
+    if (robot.recording) {
       recording: {
-        ...robot.recording,
+        ...robot.recording,
         workflow
       }
+    }
 
     if (name) {
+      // Validate recording_meta object before spread
+      if (robot.recording_meta) {
         updates.recording_meta = {
           ...robot.recording_meta,
           name
         };
+      }
     }

Committable suggestion skipped: line range outside the PR's diff.


const updatedRobot = await Robot.findOne({ where: { 'recording_meta.id': id } });

Expand Down
Loading