2018-11-05 02:28:32 +08:00
|
|
|
import {DirectoryDTO} from './DirectoryDTO';
|
|
|
|
import {PhotoDTO} from './PhotoDTO';
|
|
|
|
import {OrientationTypes} from 'ts-exif-parser';
|
2018-11-18 02:32:31 +08:00
|
|
|
import {VideoDTO} from './VideoDTO';
|
2018-11-26 07:26:29 +08:00
|
|
|
import {FileDTO} from './FileDTO';
|
2018-11-05 02:28:32 +08:00
|
|
|
|
2018-12-06 00:29:33 +08:00
|
|
|
export interface MediaDTO extends FileDTO {
|
2018-11-05 02:28:32 +08:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
directory: DirectoryDTO;
|
|
|
|
metadata: MediaMetadata;
|
|
|
|
readyThumbnails: Array<number>;
|
|
|
|
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 => {
|
2018-11-18 02:32:31 +08:00
|
|
|
return !!(<PhotoDTO>media).metadata.positionData &&
|
|
|
|
!!((<PhotoDTO>media).metadata.positionData.city ||
|
|
|
|
(<PhotoDTO>media).metadata.positionData.state ||
|
|
|
|
(<PhotoDTO>media).metadata.positionData.country ||
|
|
|
|
((<PhotoDTO>media).metadata.positionData.GPSData &&
|
|
|
|
(<PhotoDTO>media).metadata.positionData.GPSData.altitude &&
|
|
|
|
(<PhotoDTO>media).metadata.positionData.GPSData.latitude &&
|
|
|
|
(<PhotoDTO>media).metadata.positionData.GPSData.longitude));
|
2018-11-05 02:28:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const isSideWay = (media: MediaDTO): boolean => {
|
|
|
|
if (!(<PhotoDTO>media).metadata.orientation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const photo = <PhotoDTO>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;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-11-18 02:32:31 +08:00
|
|
|
export const isPhoto = (media: MediaDTO): boolean => {
|
2018-12-06 00:29:33 +08:00
|
|
|
return !MediaDTO.isVideo(media);
|
2018-11-18 02:32:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const isVideo = (media: MediaDTO): boolean => {
|
2018-12-06 00:29:33 +08:00
|
|
|
const lower = media.name.toLowerCase();
|
|
|
|
return lower.endsWith('.mp4') || lower.endsWith('.webm') || lower.endsWith('.ogg') || lower.endsWith('.ogv');
|
2018-11-18 02:32:31 +08:00
|
|
|
};
|
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|