feat: check limit while processing workflow

This commit is contained in:
Rohit
2025-02-12 19:14:33 +05:30
parent be7c599195
commit 14a391e0bf

View File

@@ -25,35 +25,43 @@ chromium.use(stealthPlugin());
export const router = Router(); export const router = Router();
export const decryptWorkflowActions = async (workflow: any[],): Promise<any[]> => { export const processWorkflowActions = async (workflow: any[], checkLimit: boolean = false): Promise<any[]> => {
// Create a deep copy to avoid mutating the original workflow
const processedWorkflow = JSON.parse(JSON.stringify(workflow)); const processedWorkflow = JSON.parse(JSON.stringify(workflow));
// Process each step in the workflow processedWorkflow.workflow.forEach((pair: any) => {
for (const step of processedWorkflow) { pair.what.forEach((action: any) => {
if (!step.what) continue; // Handle limit validation for scrapeList action
if (action.action === 'scrapeList' && checkLimit && Array.isArray(action.args) && action.args.length > 0) {
const scrapeConfig = action.args[0];
if (scrapeConfig && typeof scrapeConfig === 'object' && 'limit' in scrapeConfig) {
if (typeof scrapeConfig.limit === 'number' && scrapeConfig.limit > 5) {
scrapeConfig.limit = 5;
}
}
}
// Process each action in the step // Handle decryption for type and press actions
for (const action of step.what) {
// Only process type and press actions
if ((action.action === 'type' || action.action === 'press') && Array.isArray(action.args) && action.args.length > 1) { if ((action.action === 'type' || action.action === 'press') && Array.isArray(action.args) && action.args.length > 1) {
// The second argument contains the encrypted value try {
const encryptedValue = action.args[1]; const encryptedValue = action.args[1];
if (typeof encryptedValue === 'string') { if (typeof encryptedValue === 'string') {
try { const decryptedValue = decrypt(encryptedValue);
// Decrypt the value and update the args array action.args[1] = decryptedValue;
action.args[1] = await decrypt(encryptedValue); } else {
} catch (error) { logger.log('error', 'Encrypted value is not a string');
console.error('Failed to decrypt value:', error); action.args[1] = '';
// Keep the encrypted value if decryption fails }
} } catch (error: unknown) {
} const errorMessage = error instanceof Error ? error.message : String(error);
} logger.log('error', `Failed to decrypt input value: ${errorMessage}`);
action.args[1] = '';
} }
} }
});
});
return processedWorkflow; return processedWorkflow;
}; }
/** /**
* Logs information about recordings API. * Logs information about recordings API.
@@ -88,7 +96,7 @@ router.get('/recordings/:id', requireSignIn, async (req, res) => {
); );
if (data?.recording?.workflow) { if (data?.recording?.workflow) {
data.recording.workflow = await decryptWorkflowActions( data.recording.workflow = await processWorkflowActions(
data.recording.workflow, data.recording.workflow,
); );
} }