feat(metadata): implement MetadataRequest and supporting classes for file metadata extraction and response formatting
This commit is contained in:
parent
72769a3ef4
commit
74fb118aa4
4 changed files with 126 additions and 0 deletions
35
scripts/file-management/analyze.js
Normal file
35
scripts/file-management/analyze.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const MetadataExtractor = class {
|
||||
/*
|
||||
* MetadataExtractor class
|
||||
* This class is used to extract metadata from a BLOB object.
|
||||
*/
|
||||
constructor(BLOB) {
|
||||
this.blob = BLOB;
|
||||
|
||||
this.extract([`fieldname`, `encoding`, `originalname`, `mimetype`, `size`]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract data from the blob.
|
||||
*/
|
||||
extract(FIELDS) {
|
||||
// Verify the validity of the blob.
|
||||
if (!this.blob) {
|
||||
throw new Error("Invalid BLOB object");
|
||||
};
|
||||
|
||||
// Extract the relevant fields.
|
||||
let RESPONSE = {};
|
||||
FIELDS.forEach((FIELD) => {
|
||||
if (!(this.blob[FIELD] === undefined)) {
|
||||
this[FIELD] = this.blob[FIELD];
|
||||
RESPONSE[FIELD] = this.blob[FIELD];
|
||||
}
|
||||
});
|
||||
|
||||
// Return the response.
|
||||
return (RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MetadataExtractor;
|
Loading…
Add table
Add a link
Reference in a new issue