feat: update currently generated workflow file from the storage one

This commit is contained in:
karishmas6
2024-06-09 00:46:45 +05:30
parent 5ad8d3ab4d
commit c14eb7995e

View File

@@ -98,3 +98,26 @@ router.put('/pair/:index', (req, res) => {
return res.send(null);
});
/**
* PUT endpoint for updating the currently generated workflow file from the one in the storage.
*/
router.put('/:browserId/:fileName', async (req, res) => {
try {
const browser = browserPool.getRemoteBrowser(req.params.browserId);
logger.log('debug', `Updating workflow file`);
if (browser && browser.generator) {
const recording = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`)
const parsedRecording = JSON.parse(recording);
if (parsedRecording.recording) {
browser.generator?.updateWorkflowFile(parsedRecording.recording, parsedRecording.recording_meta);
const workflowFile = browser.generator?.getWorkflowFile();
return res.send(workflowFile);
}
}
return res.send(null);
} catch (e) {
const {message} = e as Error;
logger.log('info', `Error while reading a recording with name: ${req.params.fileName}.waw.json`);
return res.send(null);
}
});