2018-07-27 18:58:00 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
const { getImageHeightAndWidth } = require('./imageProcessing');
|
2018-07-27 19:43:43 +02:00
|
|
|
const { getVideoHeightAndWidth } = require('./videoProcessing');
|
2018-07-27 18:58:00 +02:00
|
|
|
|
|
|
|
async function getMediaDimensions (fileType, filePath) {
|
|
|
|
let height = 0;
|
|
|
|
let width = 0;
|
|
|
|
switch (fileType) {
|
|
|
|
case 'image/jpeg':
|
|
|
|
case 'image/jpg':
|
|
|
|
case 'image/png':
|
|
|
|
case 'image/gif':
|
|
|
|
logger.debug('creating File data for an image');
|
|
|
|
[ height, width ] = await getImageHeightAndWidth(filePath);
|
|
|
|
break;
|
|
|
|
case 'video/mp4':
|
|
|
|
logger.debug('creating File data for a video');
|
|
|
|
[ height, width ] = await getVideoHeightAndWidth(filePath);
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-14 07:27:23 +01:00
|
|
|
logger.error('unable to create File dimension data for unspported file type:', fileType);
|
2018-07-27 18:58:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getMediaDimensions;
|