2021-04-02 03:48:38 +08:00
|
|
|
import {DirectoryBaseDTO, DirectoryDTO} from './DirectoryDTO';
|
2018-11-05 02:28:32 +08:00
|
|
|
import {PhotoDTO} from './PhotoDTO';
|
2021-04-02 03:48:38 +08:00
|
|
|
import {FileBaseDTO, FileDTO} from './FileDTO';
|
2019-12-10 00:19:28 +08:00
|
|
|
import {SupportedFormats} from '../SupportedFormats';
|
2018-11-05 02:28:32 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
export interface MediaBaseDTO extends FileBaseDTO {
|
|
|
|
name: string;
|
|
|
|
directory: DirectoryBaseDTO;
|
|
|
|
metadata: MediaMetadata;
|
|
|
|
readyThumbnails: number[];
|
|
|
|
readyIcon: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface MediaDTO extends FileDTO, MediaBaseDTO {
|
2018-11-05 02:28:32 +08:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
directory: DirectoryDTO;
|
|
|
|
metadata: MediaMetadata;
|
2021-04-02 03:48:38 +08:00
|
|
|
readyThumbnails: number[];
|
2018-11-05 02:28:32 +08:00
|
|
|
readyIcon: boolean;
|
2019-12-10 19:50:02 +08:00
|
|
|
|
2018-11-05 02:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface MediaMetadata {
|
|
|
|
size: MediaDimension;
|
|
|
|
creationDate: number;
|
|
|
|
fileSize: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface MediaDimension {
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
export const MediaDTOUtils = {
|
|
|
|
hasPositionData: (media: MediaBaseDTO): boolean => {
|
|
|
|
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.altitude &&
|
|
|
|
(media as PhotoDTO).metadata.positionData.GPSData.latitude &&
|
|
|
|
(media as PhotoDTO).metadata.positionData.GPSData.longitude));
|
|
|
|
},
|
|
|
|
isPhoto: (media: FileBaseDTO): boolean => {
|
|
|
|
return !MediaDTOUtils.isVideo(media);
|
|
|
|
},
|
2018-11-05 02:28:32 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
isVideo: (media: FileBaseDTO): boolean => {
|
2018-12-06 00:29:33 +08:00
|
|
|
const lower = media.name.toLowerCase();
|
2019-12-10 00:19:28 +08:00
|
|
|
for (const ext of SupportedFormats.WithDots.Videos) {
|
|
|
|
if (lower.endsWith(ext)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-18 21:48:35 +08:00
|
|
|
},
|
2018-11-18 02:32:31 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
isVideoPath: (path: string): boolean => {
|
2019-12-31 00:52:58 +08:00
|
|
|
const lower = path.toLowerCase();
|
|
|
|
for (const ext of SupportedFormats.WithDots.Videos) {
|
|
|
|
if (lower.endsWith(ext)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-04-18 21:48:35 +08:00
|
|
|
},
|
2019-12-31 00:52:58 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
isVideoTranscodingNeeded: (media: FileBaseDTO): boolean => {
|
2019-12-10 19:50:02 +08: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 21:48:35 +08:00
|
|
|
},
|
2019-12-10 19:50:02 +08:00
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
calcAspectRatio: (photo: MediaBaseDTO): number => {
|
2020-09-06 16:11:30 +08:00
|
|
|
return photo.metadata.size.width / photo.metadata.size.height;
|
2021-04-18 21:48:35 +08:00
|
|
|
}
|
|
|
|
};
|