feat: edit multiple list limits, change landing url
This commit is contained in:
@@ -254,11 +254,11 @@ function handleWorkflowActions(workflow: any[], credentials: Credentials) {
|
|||||||
router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, res) => {
|
router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, res) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
const { name, limit, credentials, targetUrl } = req.body;
|
const { name, limits, credentials, targetUrl } = req.body;
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!name && limit === undefined && !targetUrl) {
|
if (!name && !limits && !credentials && !targetUrl) {
|
||||||
return res.status(400).json({ error: 'Either "name", "limit" or "target_url" must be provided.' });
|
return res.status(400).json({ error: 'Either "name", "limits", "credentials" or "target_url" must be provided.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the robot by ID
|
// Fetch the robot by ID
|
||||||
@@ -274,22 +274,26 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (targetUrl) {
|
if (targetUrl) {
|
||||||
const updatedWorkflow = robot.recording.workflow.map((step) => {
|
const updatedWorkflow = [...robot.recording.workflow];
|
||||||
if (step.where?.url && step.where.url !== "about:blank") {
|
|
||||||
step.where.url = targetUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
step.what.forEach((action) => {
|
for (let i = updatedWorkflow.length - 1; i >= 0; i--) {
|
||||||
|
const step = updatedWorkflow[i];
|
||||||
|
for (let j = 0; j < step.what.length; j++) {
|
||||||
|
const action = step.what[j];
|
||||||
if (action.action === "goto" && action.args?.length) {
|
if (action.action === "goto" && action.args?.length) {
|
||||||
|
|
||||||
action.args[0] = targetUrl;
|
action.args[0] = targetUrl;
|
||||||
|
if (step.where?.url && step.where.url !== "about:blank") {
|
||||||
|
step.where.url = targetUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });
|
||||||
|
robot.changed('recording', true);
|
||||||
|
i = -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
return step;
|
|
||||||
});
|
|
||||||
|
|
||||||
robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });
|
|
||||||
robot.changed('recording', true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await robot.save();
|
await robot.save();
|
||||||
@@ -300,38 +304,20 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
|
|||||||
workflow = handleWorkflowActions(workflow, credentials);
|
workflow = handleWorkflowActions(workflow, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the limit
|
if (limits && Array.isArray(limits) && limits.length > 0) {
|
||||||
if (limit !== undefined) {
|
for (const limitInfo of limits) {
|
||||||
// Ensure the workflow structure is valid before updating
|
const { pairIndex, actionIndex, argIndex, limit } = limitInfo;
|
||||||
if (
|
|
||||||
workflow.length > 0 &&
|
const pair = workflow[pairIndex];
|
||||||
workflow[0]?.what?.[0]
|
if (!pair || !pair.what) continue;
|
||||||
) {
|
|
||||||
// Create a new workflow object with the updated limit
|
const action = pair.what[actionIndex];
|
||||||
workflow = workflow.map((step, index) => {
|
if (!action || !action.args) continue;
|
||||||
if (index === 0) { // Assuming you want to update the first step
|
|
||||||
return {
|
const arg = action.args[argIndex];
|
||||||
...step,
|
if (!arg || typeof arg !== 'object') continue;
|
||||||
what: step.what.map((action, actionIndex) => {
|
|
||||||
if (actionIndex === 0) { // Assuming the first action needs updating
|
(arg as { limit: number }).limit = limit;
|
||||||
return {
|
|
||||||
...action,
|
|
||||||
args: (action.args ?? []).map((arg, argIndex) => {
|
|
||||||
if (argIndex === 0) { // Assuming the first argument needs updating
|
|
||||||
return { ...arg, limit };
|
|
||||||
}
|
|
||||||
return arg;
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return action;
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return step;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return res.status(400).json({ error: 'Invalid workflow structure for updating limit.' });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user