import type { IActivityHandler } from "@vertigis/workflow"; /** An interface that defines the inputs of the activity. */ interface Base64ToFileInputs { /** * @displayName base64 * @description Base4 string content. * @required */ base64: string; } /** An interface that defines the outputs of the activity. */ interface Base64ToFileOutputs { /** * @description the result Blob */ blob: Blob; } function base64toFile(base64String: string) { const binaryData = atob(base64String.replace(/-/g, "+").replace(/_/g, "/")); // Create a new array buffer to hold the binary data const arrayBuffer = new ArrayBuffer(binaryData.length); // Create a new unit8 array to view the array buffer const uint8Array = new Uint8Array(arrayBuffer); // Fill the uint8 array with the binary data for (let i = 0; i < binaryData.length; i++) { uint8Array[i] = binaryData.charCodeAt(i); } // Create a Blob object from the array buffer const blob = new Blob([uint8Array], { type: 'application/octet-stream' }); return blob } /** * @displayName Base64 To File * @category EBTA Utilities * @description Convert Base64 To File Ver02 */ export default class Base64ToFileActivity implements IActivityHandler { /** Perform the execution logic of the activity. */ execute(inputs: Base64ToFileInputs): Base64ToFileOutputs { return { blob: base64toFile(inputs.base64) }; } }