feat(metadata): implement MetadataRequest and supporting classes for file metadata extraction and response formatting

This commit is contained in:
buzz-lightsnack-2007 2025-04-21 21:34:08 +08:00
parent 72769a3ef4
commit 74fb118aa4
4 changed files with 126 additions and 0 deletions

View 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;