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
				
			
		
							
								
								
									
										24
									
								
								scripts/API/actions/metadata.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								scripts/API/actions/metadata.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| const CustomErrors = require(`../../utilities/errors`); | ||||
| const Messaging = require(`../../utilities/messaging`); | ||||
| 
 | ||||
| const MetadataExtractor = require(`../../file-management/analyze`); | ||||
| const Cleaner = require(`../response/simple-data`); | ||||
| 
 | ||||
| const MetadataRequest = class Request { | ||||
| 	static analyze (REQUEST, RESPONSE) { | ||||
| 		// Check if the file is valid.
 | ||||
| 		if (REQUEST.file) { | ||||
| 			// Get the file information.
 | ||||
| 			const fileInfo = new MetadataExtractor(REQUEST.file).extract([ `originalname`, `mimetype`, `size`]); | ||||
| 			 | ||||
| 			const cleanedData = (new Cleaner(fileInfo)).format(); | ||||
| 			RESPONSE.status(200).json(cleanedData); | ||||
| 		} else { | ||||
| 			// If the file is not valid, return an error.
 | ||||
| 			const ERROR = new CustomErrors.Data.Missing(REQUEST.file); | ||||
| 			Messaging.exception(RESPONSE, ERROR); | ||||
| 		}; | ||||
| 	}; | ||||
| } | ||||
| 
 | ||||
| module.exports = MetadataRequest; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue