From 1b42b903aa050f4350745cf6af70a4fabee90541 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 8 Jun 2024 00:23:00 +0530 Subject: [PATCH] feat: save new worflow file --- .../workflow-management/classes/Generator.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/src/workflow-management/classes/Generator.ts b/server/src/workflow-management/classes/Generator.ts index 0fc52fdf..da94fd90 100644 --- a/server/src/workflow-management/classes/Generator.ts +++ b/server/src/workflow-management/classes/Generator.ts @@ -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} + */ + 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'); + } + }