spee.ch/server/utils/getMediaDimensions.js
2018-07-27 10:43:43 -07:00

31 lines
853 B
JavaScript

const logger = require('winston');
const { getImageHeightAndWidth } = require('./imageProcessing');
const { getVideoHeightAndWidth } = require('./videoProcessing');
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:
logger.error('unable to create File data for unspported file type:', fileType);
break;
}
return {
height,
width,
};
}
module.exports = getMediaDimensions;