feat: check limit while processing workflow
This commit is contained in:
@@ -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) {
|
||||||
// Process each action in the step
|
const scrapeConfig = action.args[0];
|
||||||
for (const action of step.what) {
|
if (scrapeConfig && typeof scrapeConfig === 'object' && 'limit' in scrapeConfig) {
|
||||||
// Only process type and press actions
|
if (typeof scrapeConfig.limit === 'number' && scrapeConfig.limit > 5) {
|
||||||
if ((action.action === 'type' || action.action === 'press') && Array.isArray(action.args) && action.args.length > 1) {
|
scrapeConfig.limit = 5;
|
||||||
// The second argument contains the encrypted value
|
|
||||||
const encryptedValue = action.args[1];
|
|
||||||
if (typeof encryptedValue === 'string') {
|
|
||||||
try {
|
|
||||||
// Decrypt the value and update the args array
|
|
||||||
action.args[1] = await decrypt(encryptedValue);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to decrypt value:', error);
|
|
||||||
// Keep the encrypted value if decryption fails
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
// Handle decryption for type and press actions
|
||||||
|
if ((action.action === 'type' || action.action === 'press') && Array.isArray(action.args) && action.args.length > 1) {
|
||||||
|
try {
|
||||||
|
const encryptedValue = action.args[1];
|
||||||
|
if (typeof encryptedValue === 'string') {
|
||||||
|
const decryptedValue = decrypt(encryptedValue);
|
||||||
|
action.args[1] = decryptedValue;
|
||||||
|
} else {
|
||||||
|
logger.log('error', 'Encrypted value is not a string');
|
||||||
|
action.args[1] = '';
|
||||||
|
}
|
||||||
|
} 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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user