2018-11-24 18:50:11 +08:00
|
|
|
import {
|
|
|
|
CameraMetadataEntity,
|
2019-01-14 00:38:39 +08:00
|
|
|
GPSMetadataEntity,
|
2021-06-19 17:20:40 +08:00
|
|
|
MediaDimensionEntity,
|
2018-11-24 18:50:11 +08:00
|
|
|
PositionMetaDataEntity
|
2023-01-06 06:11:58 +08:00
|
|
|
} from '../src/backend/model/database/enitites/MediaEntity';
|
|
|
|
import {PhotoEntity, PhotoMetadataEntity} from '../src/backend/model/database/enitites/PhotoEntity';
|
|
|
|
import {DirectoryEntity} from '../src/backend/model/database/enitites/DirectoryEntity';
|
|
|
|
import {VideoEntity, VideoMetadataEntity} from '../src/backend/model/database/enitites/VideoEntity';
|
2022-06-25 00:05:45 +08:00
|
|
|
import {MediaDimension, MediaDTO} from '../src/common/entities/MediaDTO';
|
2021-01-06 03:35:13 +08:00
|
|
|
import {
|
|
|
|
CameraMetadata,
|
2023-09-11 19:19:51 +08:00
|
|
|
CoverPhotoDTO,
|
2021-01-06 03:35:13 +08:00
|
|
|
FaceRegion,
|
|
|
|
GPSMetadata,
|
|
|
|
PhotoDTO,
|
|
|
|
PhotoMetadata,
|
2023-09-11 19:19:51 +08:00
|
|
|
PositionMetaData
|
2022-06-25 00:05:45 +08:00
|
|
|
} from '../src/common/entities/PhotoDTO';
|
|
|
|
import {DirectoryBaseDTO, DirectoryPathDTO} from '../src/common/entities/DirectoryDTO';
|
|
|
|
import {FileDTO} from '../src/common/entities/FileDTO';
|
2023-10-14 23:54:21 +08:00
|
|
|
import {DiskManager} from '../src/backend/model/fileaccess/DiskManager';
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
export class TestHelper {
|
|
|
|
|
2021-03-28 18:43:13 +08:00
|
|
|
static creationCounter = 0;
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public static getDirectoryEntry(parent: DirectoryBaseDTO = null, name = 'wars dir'): DirectoryEntity {
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const dir = new DirectoryEntity();
|
2021-01-16 23:59:59 +08:00
|
|
|
dir.name = name;
|
2023-10-14 23:54:21 +08:00
|
|
|
dir.path = DiskManager.pathFromParent({path: '', name: '.'});
|
2019-01-07 06:15:52 +08:00
|
|
|
dir.mediaCount = 0;
|
2023-09-11 19:19:51 +08:00
|
|
|
dir.youngestMedia = 10;
|
|
|
|
dir.oldestMedia = 1000;
|
2021-01-16 23:59:59 +08:00
|
|
|
dir.directories = [];
|
|
|
|
dir.metaFile = [];
|
|
|
|
dir.media = [];
|
2022-06-25 00:05:45 +08:00
|
|
|
dir.lastModified = 1656069687773;
|
|
|
|
dir.lastScanned = 1656069687773;
|
2021-01-16 23:59:59 +08:00
|
|
|
// dir.parent = null;
|
|
|
|
if (parent !== null) {
|
2023-10-14 23:54:21 +08:00
|
|
|
dir.path = DiskManager.pathFromParent(parent);
|
2021-01-16 23:59:59 +08:00
|
|
|
parent.directories.push(dir);
|
|
|
|
}
|
2018-11-24 18:50:11 +08:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2023-10-11 06:04:53 +08:00
|
|
|
|
|
|
|
public static getBasePhotoEntry(dir: DirectoryPathDTO, name = 'base media.jpg'): PhotoEntity {
|
|
|
|
const sd = new MediaDimensionEntity();
|
|
|
|
sd.height = 400;
|
|
|
|
sd.width = 200;
|
|
|
|
const m = new PhotoMetadataEntity();
|
|
|
|
m.caption = null;
|
|
|
|
m.size = sd;
|
|
|
|
m.creationDate = 1656069387772;
|
|
|
|
m.fileSize = 123456789;
|
|
|
|
// m.rating = 0; no rating by default
|
|
|
|
|
|
|
|
// TODO: remove when typeorm is fixed
|
|
|
|
m.duration = null;
|
|
|
|
m.bitRate = null;
|
|
|
|
|
|
|
|
|
|
|
|
const d = new PhotoEntity();
|
|
|
|
d.name = name;
|
|
|
|
d.directory = (dir as any);
|
|
|
|
if ((dir as DirectoryBaseDTO).media) {
|
|
|
|
(dir as DirectoryBaseDTO).media.push(d);
|
|
|
|
(dir as DirectoryBaseDTO).mediaCount++;
|
|
|
|
}
|
|
|
|
d.metadata = m;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getPhotoEntry(dir: DirectoryPathDTO): PhotoEntity {
|
2018-11-24 18:50:11 +08:00
|
|
|
const sd = new MediaDimensionEntity();
|
2022-06-25 00:05:45 +08:00
|
|
|
sd.height = 400;
|
2018-11-24 18:50:11 +08:00
|
|
|
sd.width = 200;
|
|
|
|
const gps = new GPSMetadataEntity();
|
|
|
|
gps.latitude = 1;
|
|
|
|
gps.longitude = 1;
|
|
|
|
const pd = new PositionMetaDataEntity();
|
|
|
|
pd.city = 'New York';
|
|
|
|
pd.country = 'Alderan';
|
|
|
|
pd.state = 'Kamino';
|
|
|
|
pd.GPSData = gps;
|
|
|
|
const cd = new CameraMetadataEntity();
|
|
|
|
cd.ISO = 100;
|
|
|
|
cd.model = '60D';
|
2018-12-18 07:05:12 +08:00
|
|
|
cd.make = 'Canon';
|
2018-11-24 18:50:11 +08:00
|
|
|
cd.fStop = 1;
|
|
|
|
cd.exposure = 1;
|
|
|
|
cd.focalLength = 1;
|
|
|
|
cd.lens = 'Lens';
|
|
|
|
const m = new PhotoMetadataEntity();
|
2018-12-06 00:29:33 +08:00
|
|
|
m.caption = null;
|
2018-11-24 18:50:11 +08:00
|
|
|
m.keywords = ['apple'];
|
|
|
|
m.cameraData = cd;
|
|
|
|
m.positionData = pd;
|
|
|
|
m.size = sd;
|
2022-06-25 00:05:45 +08:00
|
|
|
m.creationDate = 1656069387772;
|
2018-11-24 18:50:11 +08:00
|
|
|
m.fileSize = 123456789;
|
2021-01-17 17:56:33 +08:00
|
|
|
// m.rating = 0; no rating by default
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
// TODO: remove when typeorm is fixed
|
|
|
|
m.duration = null;
|
|
|
|
m.bitRate = null;
|
|
|
|
|
|
|
|
|
|
|
|
const d = new PhotoEntity();
|
|
|
|
d.name = 'test media.jpg';
|
2021-04-18 21:48:35 +08:00
|
|
|
d.directory = (dir as any);
|
2022-06-25 00:05:45 +08:00
|
|
|
if ((dir as DirectoryBaseDTO).media) {
|
|
|
|
(dir as DirectoryBaseDTO).media.push(d);
|
|
|
|
(dir as DirectoryBaseDTO).mediaCount++;
|
|
|
|
}
|
2018-11-24 18:50:11 +08:00
|
|
|
d.metadata = m;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getVideoEntry(dir: DirectoryPathDTO): VideoEntity {
|
2018-11-24 21:51:47 +08:00
|
|
|
const sd = new MediaDimensionEntity();
|
|
|
|
sd.height = 200;
|
2022-06-25 00:05:45 +08:00
|
|
|
sd.width = 300;
|
2018-11-24 21:51:47 +08:00
|
|
|
|
|
|
|
const m = new VideoMetadataEntity();
|
2018-12-06 00:29:33 +08:00
|
|
|
m.caption = null;
|
2018-11-24 21:51:47 +08:00
|
|
|
m.keywords = null;
|
2021-01-06 03:35:13 +08:00
|
|
|
m.rating = null;
|
2018-11-24 21:51:47 +08:00
|
|
|
m.size = sd;
|
2022-06-25 00:05:45 +08:00
|
|
|
m.creationDate = 1656069387771;
|
2018-11-24 21:51:47 +08:00
|
|
|
m.fileSize = 123456789;
|
|
|
|
|
|
|
|
m.duration = 10000;
|
|
|
|
m.bitRate = 4000;
|
|
|
|
|
|
|
|
|
|
|
|
const d = new VideoEntity();
|
2021-01-16 23:59:59 +08:00
|
|
|
d.name = 'test video.mp4';
|
2022-06-25 00:05:45 +08:00
|
|
|
d.directory = (dir as any);
|
|
|
|
if ((dir as DirectoryBaseDTO).media) {
|
|
|
|
(dir as DirectoryBaseDTO).media.push(d);
|
|
|
|
(dir as DirectoryBaseDTO).mediaCount++;
|
|
|
|
}
|
2018-11-24 21:51:47 +08:00
|
|
|
d.metadata = m;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getGPXEntry(dir: DirectoryPathDTO): FileDTO {
|
|
|
|
const d: FileDTO = {
|
|
|
|
id: null,
|
|
|
|
name: 'saturdayRun.gpx',
|
|
|
|
directory: dir
|
|
|
|
};
|
|
|
|
if ((dir as DirectoryBaseDTO).metaFile) {
|
|
|
|
(dir as DirectoryBaseDTO).metaFile.push(d);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public static getVideoEntry1(dir: DirectoryBaseDTO): VideoEntity {
|
2021-01-16 23:59:59 +08:00
|
|
|
const p = TestHelper.getVideoEntry(dir);
|
|
|
|
p.name = 'swVideo.mp4';
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getPhotoEntry1(dir: DirectoryPathDTO): PhotoEntity {
|
2018-11-24 18:50:11 +08:00
|
|
|
const p = TestHelper.getPhotoEntry(dir);
|
|
|
|
|
2018-12-06 02:15:24 +08:00
|
|
|
p.metadata.caption = 'Han Solo\'s dice';
|
2018-11-24 18:50:11 +08:00
|
|
|
p.metadata.keywords = ['Boba Fett', 'star wars', 'Anakin', 'death star'];
|
|
|
|
p.metadata.positionData.city = 'Mos Eisley';
|
|
|
|
p.metadata.positionData.country = 'Tatooine';
|
2021-01-16 23:59:59 +08:00
|
|
|
p.name = 'sw1.jpg';
|
|
|
|
p.metadata.positionData.GPSData.latitude = 10;
|
|
|
|
p.metadata.positionData.GPSData.longitude = 10;
|
2022-06-25 00:05:45 +08:00
|
|
|
p.metadata.creationDate = 1656069387772 - 1000;
|
2021-01-16 23:59:59 +08:00
|
|
|
p.metadata.rating = 1;
|
|
|
|
p.metadata.size.height = 1000;
|
|
|
|
p.metadata.size.width = 1000;
|
2019-01-27 07:03:40 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
p.metadata.faces = [{
|
2019-03-11 04:59:45 +08:00
|
|
|
box: {height: 10, width: 10, left: 10, top: 10},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Boba Fett'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2020-01-02 06:24:22 +08:00
|
|
|
box: {height: 10, width: 10, left: 102, top: 102},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Luke Skywalker'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2020-01-02 06:24:22 +08:00
|
|
|
box: {height: 10, width: 10, left: 103, top: 103},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Han Solo'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2020-01-02 06:24:22 +08:00
|
|
|
box: {height: 10, width: 10, left: 104, top: 104},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Unkle Ben'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2020-01-02 06:24:22 +08:00
|
|
|
box: {height: 10, width: 10, left: 105, top: 105},
|
|
|
|
name: 'Arvíztűrő Tükörfúrógép'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-17 06:37:14 +08:00
|
|
|
box: {height: 10, width: 10, left: 201, top: 201},
|
|
|
|
name: 'R2-D2'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion] as any[];
|
2018-11-24 18:50:11 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getPhotoEntry2(dir: DirectoryPathDTO): PhotoEntity {
|
2018-11-24 18:50:11 +08:00
|
|
|
const p = TestHelper.getPhotoEntry(dir);
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
p.metadata.caption = 'Light saber';
|
|
|
|
p.metadata.keywords = ['Padmé Amidala', 'star wars', 'Natalie Portman', 'death star', 'wookiee'];
|
2018-11-24 18:50:11 +08:00
|
|
|
p.metadata.positionData.city = 'Derem City';
|
|
|
|
p.metadata.positionData.state = 'Research City';
|
|
|
|
p.metadata.positionData.country = 'Kamino';
|
2021-01-16 23:59:59 +08:00
|
|
|
p.name = 'sw2.jpg';
|
|
|
|
p.metadata.positionData.GPSData.latitude = -10;
|
|
|
|
p.metadata.positionData.GPSData.longitude = -10;
|
2022-06-25 00:05:45 +08:00
|
|
|
p.metadata.creationDate = 1656069387772 - 2000;
|
2021-01-16 23:59:59 +08:00
|
|
|
p.metadata.rating = 2;
|
|
|
|
p.metadata.size.height = 2000;
|
|
|
|
p.metadata.size.width = 1000;
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
p.metadata.faces = [{
|
2019-03-15 05:29:09 +08:00
|
|
|
box: {height: 10, width: 10, left: 10, top: 10},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Padmé Amidala'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2019-03-15 05:29:09 +08:00
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Anakin Skywalker'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2019-03-15 05:29:09 +08:00
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
2021-01-16 23:59:59 +08:00
|
|
|
name: 'Obivan Kenobi'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-17 06:37:14 +08:00
|
|
|
box: {height: 10, width: 10, left: 201, top: 201},
|
|
|
|
name: 'R2-D2'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion] as any[];
|
2021-01-16 23:59:59 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getPhotoEntry3(dir: DirectoryPathDTO): PhotoEntity {
|
2021-01-16 23:59:59 +08:00
|
|
|
const p = TestHelper.getPhotoEntry(dir);
|
|
|
|
|
|
|
|
p.metadata.caption = 'Amber stone';
|
|
|
|
p.metadata.keywords = ['star wars', 'wookiees'];
|
|
|
|
p.metadata.positionData.city = 'Castilon';
|
|
|
|
p.metadata.positionData.state = 'Devaron';
|
|
|
|
p.metadata.positionData.country = 'Ajan Kloss';
|
|
|
|
p.name = 'sw3.jpg';
|
|
|
|
p.metadata.positionData.GPSData.latitude = 10;
|
|
|
|
p.metadata.positionData.GPSData.longitude = 15;
|
2022-06-25 00:05:45 +08:00
|
|
|
p.metadata.creationDate = 1656069387772 - 3000;
|
2021-01-16 23:59:59 +08:00
|
|
|
p.metadata.rating = 3;
|
|
|
|
p.metadata.size.height = 1000;
|
|
|
|
p.metadata.size.width = 2000;
|
2021-04-18 21:48:35 +08:00
|
|
|
p.metadata.faces = [{
|
2021-01-16 23:59:59 +08:00
|
|
|
box: {height: 10, width: 10, left: 10, top: 10},
|
|
|
|
name: 'Kylo Ren'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-16 23:59:59 +08:00
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
|
|
|
name: 'Leia Organa'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-16 23:59:59 +08:00
|
|
|
box: {height: 10, width: 10, left: 103, top: 103},
|
|
|
|
name: 'Han Solo'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion] as any[];
|
2021-01-16 23:59:59 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getPhotoEntry4(dir: DirectoryPathDTO): PhotoEntity {
|
2021-01-16 23:59:59 +08:00
|
|
|
const p = TestHelper.getPhotoEntry(dir);
|
|
|
|
|
|
|
|
p.metadata.caption = 'Millennium falcon';
|
|
|
|
p.metadata.keywords = ['star wars', 'ewoks'];
|
|
|
|
p.metadata.positionData.city = 'Tipoca City';
|
|
|
|
p.metadata.positionData.state = 'Exegol';
|
|
|
|
p.metadata.positionData.country = 'Jedha';
|
|
|
|
p.name = 'sw4.jpg';
|
|
|
|
p.metadata.positionData.GPSData.latitude = 15;
|
|
|
|
p.metadata.positionData.GPSData.longitude = 10;
|
2022-06-25 00:05:45 +08:00
|
|
|
p.metadata.creationDate = 1656069387772 - 4000;
|
2021-01-16 23:59:59 +08:00
|
|
|
p.metadata.size.height = 3000;
|
|
|
|
p.metadata.size.width = 2000;
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
p.metadata.faces = [{
|
2021-01-16 23:59:59 +08:00
|
|
|
box: {height: 10, width: 10, left: 10, top: 10},
|
|
|
|
name: 'Kylo Ren'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-16 23:59:59 +08:00
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
|
|
|
name: 'Anakin Skywalker'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-16 23:59:59 +08:00
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Obivan Kenobi'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion, {
|
2021-01-17 06:37:14 +08:00
|
|
|
box: {height: 10, width: 10, left: 201, top: 201},
|
|
|
|
name: 'R2-D2'
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FaceRegion] as any[];
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public static getRandomizedDirectoryEntry(parent: DirectoryBaseDTO = null, forceStr: string = null): DirectoryBaseDTO<MediaDTO> {
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
const dir: DirectoryBaseDTO = {
|
2018-12-18 07:05:12 +08:00
|
|
|
id: null,
|
2023-10-14 23:54:21 +08:00
|
|
|
name: DiskManager.dirName(forceStr || Math.random().toString(36).substring(7)),
|
|
|
|
path: DiskManager.pathFromParent({path: '', name: '.'}),
|
2019-01-07 06:15:52 +08:00
|
|
|
mediaCount: 0,
|
2023-09-11 19:19:51 +08:00
|
|
|
youngestMedia: 10,
|
|
|
|
oldestMedia: 1000,
|
2018-12-18 07:05:12 +08:00
|
|
|
directories: [],
|
|
|
|
metaFile: [],
|
2023-08-26 03:24:05 +08:00
|
|
|
cover: null,
|
|
|
|
validCover: false,
|
2018-12-18 07:05:12 +08:00
|
|
|
media: [],
|
|
|
|
lastModified: Date.now(),
|
|
|
|
lastScanned: null,
|
2021-04-18 21:48:35 +08:00
|
|
|
parent
|
2018-12-18 07:05:12 +08:00
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
if (parent !== null) {
|
2023-10-14 23:54:21 +08:00
|
|
|
dir.path = DiskManager.pathFromParent(parent);
|
2018-11-24 18:50:11 +08:00
|
|
|
parent.directories.push(dir);
|
|
|
|
}
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public static getRandomizedGPXEntry(dir: DirectoryBaseDTO, forceStr: string = null): FileDTO {
|
2018-12-18 07:05:12 +08:00
|
|
|
const d: FileDTO = {
|
|
|
|
id: null,
|
|
|
|
name: forceStr + '_' + Math.random().toString(36).substring(7) + '.gpx',
|
|
|
|
directory: dir
|
|
|
|
};
|
2018-11-26 07:26:29 +08:00
|
|
|
dir.metaFile.push(d);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static getRandomizedFace(media: PhotoDTO, forceStr: string = null): FaceRegion {
|
|
|
|
const rndStr = (): string => {
|
2018-11-24 18:50:11 +08:00
|
|
|
return forceStr + '_' + Math.random().toString(36).substring(7);
|
|
|
|
};
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
const rndInt = (max = 5000): number => {
|
2019-01-14 00:38:39 +08:00
|
|
|
return Math.floor(Math.random() * max);
|
|
|
|
};
|
|
|
|
|
|
|
|
const f: FaceRegion = {
|
|
|
|
name: rndStr() + '.jpg',
|
|
|
|
box: {
|
2019-03-11 03:57:27 +08:00
|
|
|
left: rndInt(),
|
|
|
|
top: rndInt(),
|
2019-01-14 00:38:39 +08:00
|
|
|
width: rndInt(),
|
|
|
|
height: rndInt()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
media.metadata.faces = (media.metadata.faces || []);
|
|
|
|
media.metadata.faces.push(f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2022-06-25 00:05:45 +08:00
|
|
|
public static getRandomizedPhotoEntry(dir: DirectoryBaseDTO, forceStr: string = null, faces = 2): PhotoDTO {
|
2019-01-14 00:38:39 +08:00
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
const rndStr = (): string => {
|
2019-01-14 00:38:39 +08:00
|
|
|
return forceStr + '_' + Math.random().toString(36).substring(7);
|
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
const rndInt = (max = 5000): number => {
|
2018-11-24 18:50:11 +08:00
|
|
|
return Math.floor(Math.random() * max);
|
|
|
|
};
|
|
|
|
|
2018-12-18 07:05:12 +08:00
|
|
|
const sd: MediaDimension = {
|
|
|
|
height: rndInt(),
|
|
|
|
width: rndInt(),
|
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2018-12-18 07:05:12 +08:00
|
|
|
const gps: GPSMetadata = {
|
|
|
|
latitude: rndInt(1000),
|
|
|
|
longitude: rndInt(1000)
|
|
|
|
};
|
|
|
|
const pd: PositionMetaData = {
|
|
|
|
city: rndStr(),
|
|
|
|
country: rndStr(),
|
|
|
|
state: rndStr(),
|
|
|
|
GPSData: gps
|
|
|
|
};
|
|
|
|
const cd: CameraMetadata = {
|
|
|
|
ISO: rndInt(500),
|
|
|
|
model: rndStr(),
|
|
|
|
make: rndStr(),
|
|
|
|
fStop: rndInt(10),
|
|
|
|
exposure: rndInt(10),
|
|
|
|
focalLength: rndInt(10),
|
|
|
|
lens: rndStr()
|
|
|
|
};
|
|
|
|
const m: PhotoMetadata = {
|
|
|
|
keywords: [rndStr(), rndStr()],
|
|
|
|
cameraData: cd,
|
|
|
|
positionData: pd,
|
|
|
|
size: sd,
|
2021-03-28 18:43:13 +08:00
|
|
|
creationDate: Date.now() + ++TestHelper.creationCounter,
|
2018-12-18 07:05:12 +08:00
|
|
|
fileSize: rndInt(10000),
|
2021-01-06 03:35:13 +08:00
|
|
|
caption: rndStr(),
|
2021-04-18 21:48:35 +08:00
|
|
|
rating: rndInt(5) as any,
|
2018-12-18 07:05:12 +08:00
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
|
2021-03-28 18:43:13 +08:00
|
|
|
const p: PhotoDTO = {
|
2018-12-18 07:05:12 +08:00
|
|
|
id: null,
|
|
|
|
name: rndStr() + '.jpg',
|
|
|
|
directory: dir,
|
2022-03-26 18:55:15 +08:00
|
|
|
metadata: m
|
2018-12-18 07:05:12 +08:00
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
for (let i = 0; i < faces; i++) {
|
2021-03-28 18:43:13 +08:00
|
|
|
this.getRandomizedFace(p, 'Person ' + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
dir.media.push(p);
|
2023-08-26 03:24:05 +08:00
|
|
|
TestHelper.updateCover(dir);
|
2021-03-28 18:43:13 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2023-08-26 03:24:05 +08:00
|
|
|
static updateCover(dir: DirectoryBaseDTO): void {
|
2021-03-28 18:43:13 +08:00
|
|
|
if (dir.media.length > 0) {
|
2023-08-26 03:24:05 +08:00
|
|
|
dir.cover = dir.media.sort((a, b): number => b.metadata.creationDate - a.metadata.creationDate)[0];
|
2021-03-28 18:43:13 +08:00
|
|
|
} else {
|
2023-08-26 03:24:05 +08:00
|
|
|
const filtered = dir.directories.filter((d): CoverPhotoDTO => d.cover).map((d): CoverPhotoDTO => d.cover);
|
2021-03-28 18:43:13 +08:00
|
|
|
if (filtered.length > 0) {
|
2023-08-26 03:24:05 +08:00
|
|
|
dir.cover = filtered.sort((a, b): number => b.metadata.creationDate - a.metadata.creationDate)[0];
|
2021-03-28 18:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dir.parent) {
|
2023-08-26 03:24:05 +08:00
|
|
|
TestHelper.updateCover(dir.parent);
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|