spee.ch/server/utils/getMediaDimensions.js
2019-01-14 01:27:23 -05:00

30 lines
863 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 dimension data for unspported file type:', fileType);
break;
}
return {
height,
width,
};
}
module.exports = getMediaDimensions;