From 8d09580b00935d6a5120cdc39ea69c8fb68d95b9 Mon Sep 17 00:00:00 2001 From: CEBergin-Vivid <64930243+CEBergin-Vivid@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:43:52 -0700 Subject: [PATCH] Heic image converter lambda (#109) * Add image converter lambda js file * Update to add delete of original file, some checks for file responses, and comments * add image converter lambda name to main.tf script for the wfdm file index initializer, add a call to the file index initializer to call the image conversion lambda for heic files * Remove commented out code * Change access of fileId from event since the lambda is no longer pulling from a queue * remove delete from file conversion lambda as the file will now be replacing itself as a version update once the API is updated * Adding notifier if image conversion is attempted or aborterd due to file size * Update to ensure file conversion field is only set when conversion is attempted * Ensure metadata conversion status is sent to API, along with any previous metadata that may have already been updated --- wfdm-image-converter/index.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/wfdm-image-converter/index.js b/wfdm-image-converter/index.js index 4553102..299b4e7 100644 --- a/wfdm-image-converter/index.js +++ b/wfdm-image-converter/index.js @@ -83,6 +83,32 @@ exports.handler = async (event) => { let stats = fs.statSync("/tmp/" + fileName); let fileSizeInBytes = stats.size; + + let metadata = []; + let metadataConversionStatusName = 'WFDMConversionStatus-' + fileInfo.data.versionNumber; + let metadataConversionStatusValue = 'Image conversion successful'; + let fileConversionStatusMetadata = { + '@type': 'http://resources.wfdm.nrs.gov.bc.ca/fileMetadataResource', + 'metadataName': metadataConversionStatusName, + 'metadataType': 'STRING', + 'metadataValue' : metadataConversionStatusValue + } + if (fileInfo.data.metadata.length != 0) { + let imageConversionMetaUpdated = false; + metadata = fileInfo.data.metadata; + for (let i = 0; i < fileInfo.data.metadata.length; i++){ + if (fileInfo.data.metadata[i].metadataName == metadataConversionStatusName) { + fileInfo.data.metadata[i].metadataValue = metadataConversionStatusValue + imageConversionMetaUpdated = true; + break; + } + } + if (!imageConversionMetaUpdated) { + metadata.push(fileConversionStatusMetadata); + } + } else { + metadata.push(fileConversionStatusMetadata); + } // create the json data that a file is created with let jsonData = { @@ -97,7 +123,7 @@ exports.handler = async (event) => { "fileType": "DOCUMENT", "filePath": fileName, "security": [], - "metadata": [], + "metadata": metadata, "fileCheckout": null, "lockedInd": null, "uploadedOnTimestamp": null