feat: save new worflow file

This commit is contained in:
karishmas6
2024-06-08 00:23:00 +05:30
parent 1e84773c3b
commit 1b42b903aa

View File

@@ -418,5 +418,34 @@ export class WorkflowGenerator {
this.workflowRecord = workflowFile;
}
/**
* Creates a recording metadata and stores the curren workflow
* with the metadata to the file system.
* @param fileName The name of the file.
* @returns {Promise<void>}
*/
public saveNewWorkflow = async (fileName: string) => {
const recording = this.optimizeWorkflow(this.workflowRecord);
try {
this.recordingMeta = {
name: fileName,
create_date: this.recordingMeta.create_date || new Date().toLocaleString(),
pairs: recording.workflow.length,
update_date: new Date().toLocaleString(),
params: this.getParams() || [],
}
fs.mkdirSync('../storage/recordings', { recursive: true })
await saveFile(
`../storage/recordings/${fileName}.waw.json`,
JSON.stringify({ recording_meta: this.recordingMeta, recording }, null, 2)
);
}
catch (e) {
const { message } = e as Error;
logger.log('warn', `Cannot save the file to the local file system`)
}
this.socket.emit('fileSaved');
}
}