Skip to content

Commit

Permalink
Heic image converter lambda (#109)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CEBergin-Vivid authored Apr 26, 2024
1 parent c72a9d8 commit 8d09580
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion wfdm-image-converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -97,7 +123,7 @@ exports.handler = async (event) => {
"fileType": "DOCUMENT",
"filePath": fileName,
"security": [],
"metadata": [],
"metadata": metadata,
"fileCheckout": null,
"lockedInd": null,
"uploadedOnTimestamp": null
Expand Down

0 comments on commit 8d09580

Please sign in to comment.