feat: add flag generation logic
This commit is contained in:
@@ -11,6 +11,8 @@ import Run from "../../models/Run";
|
|||||||
import { getDecryptedProxyConfig } from "../../routes/proxy";
|
import { getDecryptedProxyConfig } from "../../routes/proxy";
|
||||||
import { BinaryOutputService } from "../../storage/mino";
|
import { BinaryOutputService } from "../../storage/mino";
|
||||||
import { capture } from "../../utils/analytics";
|
import { capture } from "../../utils/analytics";
|
||||||
|
import { WorkflowFile } from "maxun-core";
|
||||||
|
import { Page } from "playwright";
|
||||||
chromium.use(stealthPlugin());
|
chromium.use(stealthPlugin());
|
||||||
|
|
||||||
async function createWorkflowAndStoreMetadata(id: string, userId: string) {
|
async function createWorkflowAndStoreMetadata(id: string, userId: string) {
|
||||||
@@ -79,6 +81,17 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AddGeneratedFlags(workflow: WorkflowFile) {
|
||||||
|
const copy = JSON.parse(JSON.stringify(workflow));
|
||||||
|
for (let i = 0; i < workflow.workflow.length; i++) {
|
||||||
|
copy.workflow[i].what.unshift({
|
||||||
|
action: 'flag',
|
||||||
|
args: ['generated'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
};
|
||||||
|
|
||||||
async function executeRun(id: string) {
|
async function executeRun(id: string) {
|
||||||
try {
|
try {
|
||||||
const run = await Run.findOne({ where: { runId: id } });
|
const run = await Run.findOne({ where: { runId: id } });
|
||||||
@@ -106,13 +119,15 @@ async function executeRun(id: string) {
|
|||||||
throw new Error('Could not access browser');
|
throw new Error('Could not access browser');
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentPage = await browser.getCurrentPage();
|
let currentPage = await browser.getCurrentPage();
|
||||||
if (!currentPage) {
|
if (!currentPage) {
|
||||||
throw new Error('Could not create a new page');
|
throw new Error('Could not create a new page');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const workflow = AddGeneratedFlags(recording.recording);
|
||||||
const interpretationInfo = await browser.interpreter.InterpretRecording(
|
const interpretationInfo = await browser.interpreter.InterpretRecording(
|
||||||
recording.recording, currentPage, plainRun.interpreterSettings);
|
workflow, currentPage, (newPage: Page) => currentPage = newPage, plainRun.interpreterSettings
|
||||||
|
);
|
||||||
|
|
||||||
const binaryOutputService = new BinaryOutputService('maxun-run-screenshots');
|
const binaryOutputService = new BinaryOutputService('maxun-run-screenshots');
|
||||||
const uploadedBinaryOutput = await binaryOutputService.uploadAndStoreBinaryOutput(run, interpretationInfo.binaryOutput);
|
const uploadedBinaryOutput = await binaryOutputService.uploadAndStoreBinaryOutput(run, interpretationInfo.binaryOutput);
|
||||||
|
|||||||
Reference in New Issue
Block a user