import {DirectoryDTO} from './DirectoryDTO'; import {PhotoDTO} from './PhotoDTO'; import {OrientationTypes} from 'ts-exif-parser'; import {VideoDTO} from './VideoDTO'; import {FileDTO} from './FileDTO'; export interface MediaDTO extends FileDTO { id: number; name: string; directory: DirectoryDTO; metadata: MediaMetadata; readyThumbnails: Array; readyIcon: boolean; } export interface MediaMetadata { size: MediaDimension; creationDate: number; fileSize: number; } export interface MediaDimension { width: number; height: number; } export module MediaDTO { export const hasPositionData = (media: MediaDTO): boolean => { return !!(media).metadata.positionData && !!((media).metadata.positionData.city || (media).metadata.positionData.state || (media).metadata.positionData.country || ((media).metadata.positionData.GPSData && (media).metadata.positionData.GPSData.altitude && (media).metadata.positionData.GPSData.latitude && (media).metadata.positionData.GPSData.longitude)); }; export const isSideWay = (media: MediaDTO): boolean => { if (!(media).metadata.orientation) { return false; } const photo = media; return photo.metadata.orientation === OrientationTypes.LEFT_TOP || photo.metadata.orientation === OrientationTypes.RIGHT_TOP || photo.metadata.orientation === OrientationTypes.LEFT_BOTTOM || photo.metadata.orientation === OrientationTypes.RIGHT_BOTTOM; }; export const isPhoto = (media: MediaDTO): boolean => { return !MediaDTO.isVideo(media); }; export const isVideo = (media: MediaDTO): boolean => { const lower = media.name.toLowerCase(); return lower.endsWith('.mp4') || lower.endsWith('.webm') || lower.endsWith('.ogg') || lower.endsWith('.ogv'); }; export const getRotatedSize = (photo: MediaDTO): MediaDimension => { if (isSideWay(photo)) { // noinspection JSSuspiciousNameCombination return {width: photo.metadata.size.height, height: photo.metadata.size.width}; } return photo.metadata.size; }; export const calcRotatedAspectRatio = (photo: MediaDTO): number => { const size = getRotatedSize(photo); return size.width / size.height; }; }