chore: lint
This commit is contained in:
@@ -23,7 +23,7 @@ chromium.use(stealthPlugin());
|
|||||||
export const router = Router();
|
export const router = Router();
|
||||||
|
|
||||||
export const processWorkflowActions = async (workflow: any[], checkLimit: boolean = false): Promise<any[]> => {
|
export const processWorkflowActions = async (workflow: any[], checkLimit: boolean = false): Promise<any[]> => {
|
||||||
const processedWorkflow = JSON.parse(JSON.stringify(workflow));
|
const processedWorkflow = JSON.parse(JSON.stringify(workflow));
|
||||||
|
|
||||||
processedWorkflow.forEach((pair: any) => {
|
processedWorkflow.forEach((pair: any) => {
|
||||||
pair.what.forEach((action: any) => {
|
pair.what.forEach((action: any) => {
|
||||||
@@ -108,52 +108,52 @@ router.get('/recordings/:id', requireSignIn, async (req, res) => {
|
|||||||
router.get(('/recordings/:id/runs'), requireSignIn, async (req, res) => {
|
router.get(('/recordings/:id/runs'), requireSignIn, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const runs = await Run.findAll({
|
const runs = await Run.findAll({
|
||||||
where: {
|
where: {
|
||||||
robotMetaId: req.params.id
|
robotMetaId: req.params.id
|
||||||
},
|
},
|
||||||
raw: true
|
raw: true
|
||||||
});
|
});
|
||||||
const formattedRuns = runs.map(formatRunResponse);
|
const formattedRuns = runs.map(formatRunResponse);
|
||||||
const response = {
|
const response = {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
messageCode: "success",
|
messageCode: "success",
|
||||||
runs: {
|
runs: {
|
||||||
totalCount: formattedRuns.length,
|
totalCount: formattedRuns.length,
|
||||||
items: formattedRuns,
|
items: formattedRuns,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).json(response);
|
res.status(200).json(response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching runs:", error);
|
console.error("Error fetching runs:", error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
messageCode: "error",
|
messageCode: "error",
|
||||||
message: "Failed to retrieve runs",
|
message: "Failed to retrieve runs",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function formatRunResponse(run: any) {
|
function formatRunResponse(run: any) {
|
||||||
const formattedRun = {
|
const formattedRun = {
|
||||||
id: run.id,
|
id: run.id,
|
||||||
status: run.status,
|
status: run.status,
|
||||||
name: run.name,
|
name: run.name,
|
||||||
robotId: run.robotMetaId, // Renaming robotMetaId to robotId
|
robotId: run.robotMetaId, // Renaming robotMetaId to robotId
|
||||||
startedAt: run.startedAt,
|
startedAt: run.startedAt,
|
||||||
finishedAt: run.finishedAt,
|
finishedAt: run.finishedAt,
|
||||||
runId: run.runId,
|
runId: run.runId,
|
||||||
runByUserId: run.runByUserId,
|
runByUserId: run.runByUserId,
|
||||||
runByScheduleId: run.runByScheduleId,
|
runByScheduleId: run.runByScheduleId,
|
||||||
runByAPI: run.runByAPI,
|
runByAPI: run.runByAPI,
|
||||||
data: {},
|
data: {},
|
||||||
screenshot: null,
|
screenshot: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (run.serializableOutput && run.serializableOutput['item-0']) {
|
if (run.serializableOutput && run.serializableOutput['item-0']) {
|
||||||
formattedRun.data = run.serializableOutput['item-0'];
|
formattedRun.data = run.serializableOutput['item-0'];
|
||||||
} else if (run.binaryOutput && run.binaryOutput['item-0']) {
|
} else if (run.binaryOutput && run.binaryOutput['item-0']) {
|
||||||
formattedRun.screenshot = run.binaryOutput['item-0'];
|
formattedRun.screenshot = run.binaryOutput['item-0'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return formattedRun;
|
return formattedRun;
|
||||||
@@ -170,81 +170,81 @@ interface Credentials {
|
|||||||
|
|
||||||
function handleWorkflowActions(workflow: any[], credentials: Credentials) {
|
function handleWorkflowActions(workflow: any[], credentials: Credentials) {
|
||||||
return workflow.map(step => {
|
return workflow.map(step => {
|
||||||
if (!step.what) return step;
|
if (!step.what) return step;
|
||||||
|
|
||||||
const newWhat: any[] = [];
|
const newWhat: any[] = [];
|
||||||
const processedSelectors = new Set<string>();
|
const processedSelectors = new Set<string>();
|
||||||
|
|
||||||
for (let i = 0; i < step.what.length; i++) {
|
for (let i = 0; i < step.what.length; i++) {
|
||||||
const action = step.what[i];
|
const action = step.what[i];
|
||||||
|
|
||||||
if (!action?.action || !action?.args?.[0]) {
|
if (!action?.action || !action?.args?.[0]) {
|
||||||
newWhat.push(action);
|
newWhat.push(action);
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
const selector = action.args[0];
|
|
||||||
const credential = credentials[selector];
|
|
||||||
|
|
||||||
if (!credential) {
|
|
||||||
newWhat.push(action);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action.action === 'click') {
|
|
||||||
newWhat.push(action);
|
|
||||||
|
|
||||||
if (!processedSelectors.has(selector) &&
|
|
||||||
i + 1 < step.what.length &&
|
|
||||||
(step.what[i + 1].action === 'type' || step.what[i + 1].action === 'press')) {
|
|
||||||
|
|
||||||
newWhat.push({
|
|
||||||
action: 'type',
|
|
||||||
args: [selector, encrypt(credential.value), credential.type]
|
|
||||||
});
|
|
||||||
|
|
||||||
newWhat.push({
|
|
||||||
action: 'waitForLoadState',
|
|
||||||
args: ['networkidle']
|
|
||||||
});
|
|
||||||
|
|
||||||
processedSelectors.add(selector);
|
|
||||||
|
|
||||||
while (i + 1 < step.what.length &&
|
|
||||||
(step.what[i + 1].action === 'type' ||
|
|
||||||
step.what[i + 1].action === 'press' ||
|
|
||||||
step.what[i + 1].action === 'waitForLoadState')) {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ((action.action === 'type' || action.action === 'press') &&
|
|
||||||
!processedSelectors.has(selector)) {
|
|
||||||
newWhat.push({
|
|
||||||
action: 'type',
|
|
||||||
args: [selector, encrypt(credential.value), credential.type]
|
|
||||||
});
|
|
||||||
|
|
||||||
newWhat.push({
|
|
||||||
action: 'waitForLoadState',
|
|
||||||
args: ['networkidle']
|
|
||||||
});
|
|
||||||
|
|
||||||
processedSelectors.add(selector);
|
|
||||||
|
|
||||||
// Skip subsequent type/press/waitForLoadState actions for this selector
|
|
||||||
while (i + 1 < step.what.length &&
|
|
||||||
(step.what[i + 1].action === 'type' ||
|
|
||||||
step.what[i + 1].action === 'press' ||
|
|
||||||
step.what[i + 1].action === 'waitForLoadState')) {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const selector = action.args[0];
|
||||||
...step,
|
const credential = credentials[selector];
|
||||||
what: newWhat
|
|
||||||
};
|
if (!credential) {
|
||||||
|
newWhat.push(action);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.action === 'click') {
|
||||||
|
newWhat.push(action);
|
||||||
|
|
||||||
|
if (!processedSelectors.has(selector) &&
|
||||||
|
i + 1 < step.what.length &&
|
||||||
|
(step.what[i + 1].action === 'type' || step.what[i + 1].action === 'press')) {
|
||||||
|
|
||||||
|
newWhat.push({
|
||||||
|
action: 'type',
|
||||||
|
args: [selector, encrypt(credential.value), credential.type]
|
||||||
|
});
|
||||||
|
|
||||||
|
newWhat.push({
|
||||||
|
action: 'waitForLoadState',
|
||||||
|
args: ['networkidle']
|
||||||
|
});
|
||||||
|
|
||||||
|
processedSelectors.add(selector);
|
||||||
|
|
||||||
|
while (i + 1 < step.what.length &&
|
||||||
|
(step.what[i + 1].action === 'type' ||
|
||||||
|
step.what[i + 1].action === 'press' ||
|
||||||
|
step.what[i + 1].action === 'waitForLoadState')) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((action.action === 'type' || action.action === 'press') &&
|
||||||
|
!processedSelectors.has(selector)) {
|
||||||
|
newWhat.push({
|
||||||
|
action: 'type',
|
||||||
|
args: [selector, encrypt(credential.value), credential.type]
|
||||||
|
});
|
||||||
|
|
||||||
|
newWhat.push({
|
||||||
|
action: 'waitForLoadState',
|
||||||
|
args: ['networkidle']
|
||||||
|
});
|
||||||
|
|
||||||
|
processedSelectors.add(selector);
|
||||||
|
|
||||||
|
// Skip subsequent type/press/waitForLoadState actions for this selector
|
||||||
|
while (i + 1 < step.what.length &&
|
||||||
|
(step.what[i + 1].action === 'type' ||
|
||||||
|
step.what[i + 1].action === 'press' ||
|
||||||
|
step.what[i + 1].action === 'waitForLoadState')) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...step,
|
||||||
|
what: newWhat
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user