Merge pull request #485 from getmaxun/edit-rob-url

feat: edit robot target url
This commit is contained in:
Karishma Shukla
2025-03-19 16:50:10 +05:30
committed by GitHub
3 changed files with 82 additions and 28 deletions

View File

@@ -259,11 +259,11 @@ function handleWorkflowActions(workflow: any[], credentials: Credentials) {
router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, res) => {
try {
const { id } = req.params;
const { name, limit, credentials } = req.body;
const { name, limit, credentials, targetUrl } = req.body;
// Validate input
if (!name && limit === undefined) {
return res.status(400).json({ error: 'Either "name" or "limit" must be provided.' });
if (!name && limit === undefined && !targetUrl) {
return res.status(400).json({ error: 'Either "name", "limit" or "target_url" must be provided.' });
}
// Fetch the robot by ID
@@ -278,6 +278,27 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
robot.set('recording_meta', { ...robot.recording_meta, name });
}
if (targetUrl) {
const updatedWorkflow = robot.recording.workflow.map((step) => {
if (step.where?.url && step.where.url !== "about:blank") {
step.where.url = targetUrl;
}
step.what.forEach((action) => {
if (action.action === "goto" && action.args?.length) {
action.args[0] = targetUrl;
}
});
return step;
});
robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });
robot.changed('recording', true);
}
await robot.save();
let workflow = [...robot.recording.workflow]; // Create a copy of the workflow
if (credentials) {