2021-06-27 19:33:37 +02:00
|
|
|
import {DirectoryPathDTO} from './DirectoryDTO';
|
2018-11-04 19:28:32 +01:00
|
|
|
import {PhotoDTO} from './PhotoDTO';
|
2021-06-27 19:33:37 +02:00
|
|
|
import {FileDTO} from './FileDTO';
|
2019-12-09 17:19:28 +01:00
|
|
|
import {SupportedFormats} from '../SupportedFormats';
|
2018-11-04 19:28:32 +01:00
|
|
|
|
2021-04-01 21:48:38 +02:00
|
|
|
|
2021-06-27 19:33:37 +02:00
|
|
|
export interface MediaDTO extends FileDTO {
|
2018-11-04 19:28:32 +01:00
|
|
|
id: number;
|
|
|
|
name: string;
|
2021-06-27 19:33:37 +02:00
|
|
|
directory: DirectoryPathDTO;
|
2018-11-04 19:28:32 +01:00
|
|
|
metadata: MediaMetadata;
|
2022-03-26 11:55:15 +01:00
|
|
|
missingThumbnails?: number;
|
2018-11-04 19:28:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface MediaMetadata {
|
|
|
|
size: MediaDimension;
|
|
|
|
creationDate: number;
|
|
|
|
fileSize: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface MediaDimension {
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
export const MediaDTOUtils = {
|
2021-06-27 19:33:37 +02:00
|
|
|
hasPositionData: (media: MediaDTO): boolean => {
|
2021-04-18 15:48:35 +02:00
|
|
|
return !!(media as PhotoDTO).metadata.positionData &&
|
|
|
|
!!((media as PhotoDTO).metadata.positionData.city ||
|
|
|
|
(media as PhotoDTO).metadata.positionData.state ||
|
|
|
|
(media as PhotoDTO).metadata.positionData.country ||
|
|
|
|
((media as PhotoDTO).metadata.positionData.GPSData &&
|
|
|
|
(media as PhotoDTO).metadata.positionData.GPSData.latitude &&
|
|
|
|
(media as PhotoDTO).metadata.positionData.GPSData.longitude));
|
|
|
|
},
|
2021-06-27 19:33:37 +02:00
|
|
|
isPhoto: (media: FileDTO): boolean => {
|
2021-04-18 15:48:35 +02:00
|
|
|
return !MediaDTOUtils.isVideo(media);
|
|
|
|
},
|
2018-11-04 19:28:32 +01:00
|
|
|
|
2021-06-27 19:33:37 +02:00
|
|
|
isVideo: (media: FileDTO): boolean => {
|
2018-12-05 17:29:33 +01:00
|
|
|
const lower = media.name.toLowerCase();
|
2019-12-09 17:19:28 +01:00
|
|
|
for (const ext of SupportedFormats.WithDots.Videos) {
|
|
|
|
if (lower.endsWith(ext)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-18 15:48:35 +02:00
|
|
|
},
|
2018-11-17 19:32:31 +01:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
isVideoPath: (path: string): boolean => {
|
2019-12-30 17:52:58 +01:00
|
|
|
const lower = path.toLowerCase();
|
|
|
|
for (const ext of SupportedFormats.WithDots.Videos) {
|
|
|
|
if (lower.endsWith(ext)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-18 15:48:35 +02:00
|
|
|
},
|
2019-12-30 17:52:58 +01:00
|
|
|
|
2021-06-27 19:33:37 +02:00
|
|
|
isVideoTranscodingNeeded: (media: FileDTO): boolean => {
|
2019-12-10 12:50:02 +01:00
|
|
|
const lower = media.name.toLowerCase();
|
|
|
|
for (const ext of SupportedFormats.WithDots.TranscodeNeed.Videos) {
|
|
|
|
if (lower.endsWith(ext)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-18 15:48:35 +02:00
|
|
|
},
|
2019-12-10 12:50:02 +01:00
|
|
|
|
|
|
|
|
2021-06-27 19:33:37 +02:00
|
|
|
calcAspectRatio: (photo: MediaDTO): number => {
|
2020-09-06 10:11:30 +02:00
|
|
|
return photo.metadata.size.width / photo.metadata.size.height;
|
2021-04-18 15:48:35 +02:00
|
|
|
}
|
|
|
|
};
|