2019-12-15 00:27:01 +08:00
|
|
|
import {MediaDimensionEntity} from '../../../../../src/backend/model/database/sql/enitites/MediaEntity';
|
2018-11-24 18:50:11 +08:00
|
|
|
import {
|
|
|
|
CameraMetadataEntity,
|
2019-01-14 00:38:39 +08:00
|
|
|
GPSMetadataEntity,
|
|
|
|
PhotoEntity,
|
2018-11-24 18:50:11 +08:00
|
|
|
PhotoMetadataEntity,
|
|
|
|
PositionMetaDataEntity
|
2019-12-15 00:27:01 +08:00
|
|
|
} from '../../../../../src/backend/model/database/sql/enitites/PhotoEntity';
|
2018-11-24 18:50:11 +08:00
|
|
|
import {OrientationTypes} from 'ts-exif-parser';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {DirectoryEntity} from '../../../../../src/backend/model/database/sql/enitites/DirectoryEntity';
|
|
|
|
import {VideoEntity, VideoMetadataEntity} from '../../../../../src/backend/model/database/sql/enitites/VideoEntity';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {MediaDimension} from '../../../../../src/common/entities/MediaDTO';
|
2021-01-06 03:35:13 +08:00
|
|
|
import {
|
|
|
|
CameraMetadata,
|
|
|
|
FaceRegion,
|
|
|
|
GPSMetadata,
|
|
|
|
PhotoDTO,
|
|
|
|
PhotoMetadata,
|
|
|
|
PositionMetaData
|
|
|
|
} from '../../../../../src/common/entities/PhotoDTO';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {DirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
|
|
|
import {FileDTO} from '../../../../../src/common/entities/FileDTO';
|
|
|
|
import {DiskMangerWorker} from '../../../../../src/backend/model/threading/DiskMangerWorker';
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
export class TestHelper {
|
|
|
|
|
|
|
|
public static getDirectoryEntry() {
|
|
|
|
|
|
|
|
const dir = new DirectoryEntity();
|
|
|
|
dir.name = 'wars dir';
|
|
|
|
dir.path = '.';
|
2019-01-07 06:15:52 +08:00
|
|
|
dir.mediaCount = 0;
|
2018-11-24 18:50:11 +08:00
|
|
|
dir.lastModified = Date.now();
|
|
|
|
dir.lastScanned = null;
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getPhotoEntry(dir: DirectoryEntity) {
|
|
|
|
const sd = new MediaDimensionEntity();
|
|
|
|
sd.height = 200;
|
|
|
|
sd.width = 200;
|
|
|
|
const gps = new GPSMetadataEntity();
|
|
|
|
gps.altitude = 1;
|
|
|
|
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;
|
|
|
|
m.creationDate = Date.now();
|
|
|
|
m.fileSize = 123456789;
|
|
|
|
m.orientation = OrientationTypes.TOP_LEFT;
|
2021-01-06 03:35:13 +08:00
|
|
|
m.rating = 2;
|
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';
|
|
|
|
d.directory = dir;
|
|
|
|
d.metadata = m;
|
2019-01-07 06:15:52 +08:00
|
|
|
dir.mediaCount++;
|
2018-11-24 18:50:11 +08:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2018-11-24 21:51:47 +08:00
|
|
|
public static getVideoEntry(dir: DirectoryEntity) {
|
|
|
|
const sd = new MediaDimensionEntity();
|
|
|
|
sd.height = 200;
|
|
|
|
sd.width = 200;
|
|
|
|
|
|
|
|
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;
|
|
|
|
m.creationDate = Date.now();
|
|
|
|
m.fileSize = 123456789;
|
|
|
|
|
|
|
|
m.duration = 10000;
|
|
|
|
m.bitRate = 4000;
|
|
|
|
|
|
|
|
|
|
|
|
const d = new VideoEntity();
|
|
|
|
d.name = 'test video.jpg';
|
|
|
|
d.directory = dir;
|
|
|
|
d.metadata = m;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
public static getPhotoEntry1(dir: DirectoryEntity) {
|
|
|
|
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';
|
|
|
|
p.name = 'sw1';
|
2019-01-27 07:03:40 +08:00
|
|
|
|
2019-03-11 04:59:45 +08:00
|
|
|
p.metadata.faces = [<FaceRegion>{
|
|
|
|
box: {height: 10, width: 10, left: 10, top: 10},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Boba Fett'
|
2019-03-11 04:59:45 +08:00
|
|
|
}, <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'
|
2019-03-11 04:59:45 +08:00
|
|
|
}, <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'
|
2019-03-11 04:59:45 +08:00
|
|
|
}, <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'
|
2020-01-02 06:24:22 +08:00
|
|
|
}, <FaceRegion>{
|
|
|
|
box: {height: 10, width: 10, left: 105, top: 105},
|
|
|
|
name: 'Arvíztűrő Tükörfúrógép'
|
2019-03-11 04:59:45 +08:00
|
|
|
}] as any[];
|
2018-11-24 18:50:11 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2018-11-24 21:51:47 +08:00
|
|
|
public static getVideoEntry1(dir: DirectoryEntity) {
|
|
|
|
const p = TestHelper.getVideoEntry(dir);
|
|
|
|
p.name = 'swVideo';
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
public static getPhotoEntry2(dir: DirectoryEntity) {
|
|
|
|
const p = TestHelper.getPhotoEntry(dir);
|
|
|
|
|
|
|
|
p.metadata.keywords = ['Padmé Amidala', 'star wars', 'Natalie Portman', 'death star'];
|
|
|
|
p.metadata.positionData.city = 'Derem City';
|
|
|
|
p.metadata.positionData.state = 'Research City';
|
|
|
|
p.metadata.positionData.country = 'Kamino';
|
|
|
|
p.name = 'sw2';
|
2019-03-15 05:29:09 +08:00
|
|
|
p.metadata.faces = [<FaceRegion>{
|
|
|
|
box: {height: 10, width: 10, left: 10, top: 10},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Padmé Amidala'
|
2019-03-15 05:29:09 +08:00
|
|
|
}, <FaceRegion>{
|
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Anakin Skywalker'
|
2019-03-15 05:29:09 +08:00
|
|
|
}, <FaceRegion>{
|
|
|
|
box: {height: 10, width: 10, left: 101, top: 101},
|
2019-01-27 07:03:40 +08:00
|
|
|
name: 'Obivan Kenobi'
|
2019-03-15 05:29:09 +08:00
|
|
|
}] as any[];
|
2018-11-24 18:50:11 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-18 07:05:12 +08:00
|
|
|
public static getRandomizedDirectoryEntry(parent: DirectoryDTO = null, forceStr: string = null) {
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2018-12-18 07:05:12 +08:00
|
|
|
const dir: DirectoryDTO = {
|
|
|
|
id: null,
|
2019-07-26 05:36:57 +08:00
|
|
|
name: DiskMangerWorker.dirName(forceStr || Math.random().toString(36).substring(7)),
|
|
|
|
path: DiskMangerWorker.pathFromParent({path: '', name: '.'}),
|
2019-01-07 06:15:52 +08:00
|
|
|
mediaCount: 0,
|
2018-12-18 07:05:12 +08:00
|
|
|
directories: [],
|
|
|
|
metaFile: [],
|
|
|
|
media: [],
|
|
|
|
lastModified: Date.now(),
|
|
|
|
lastScanned: null,
|
|
|
|
parent: null
|
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
if (parent !== null) {
|
2019-07-26 05:36:57 +08:00
|
|
|
dir.path = DiskMangerWorker.pathFromParent(parent);
|
2018-11-24 18:50:11 +08:00
|
|
|
parent.directories.push(dir);
|
|
|
|
}
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2018-11-26 07:26:29 +08:00
|
|
|
|
2018-12-18 07:05:12 +08:00
|
|
|
public static getRandomizedGPXEntry(dir: DirectoryDTO, forceStr: string = null): FileDTO {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
public static getRandomizedFace(media: PhotoDTO, forceStr: string = null) {
|
2018-11-24 18:50:11 +08:00
|
|
|
const rndStr = () => {
|
|
|
|
return forceStr + '_' + Math.random().toString(36).substring(7);
|
|
|
|
};
|
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
const rndInt = (max = 5000) => {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getRandomizedPhotoEntry(dir: DirectoryDTO, forceStr: string = null, faces: number = 2): PhotoDTO {
|
|
|
|
|
|
|
|
|
|
|
|
const rndStr = () => {
|
|
|
|
return forceStr + '_' + Math.random().toString(36).substring(7);
|
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
const rndInt = (max = 5000) => {
|
|
|
|
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 = {
|
|
|
|
altitude: rndInt(1000),
|
|
|
|
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,
|
|
|
|
creationDate: Date.now(),
|
|
|
|
fileSize: rndInt(10000),
|
|
|
|
orientation: OrientationTypes.TOP_LEFT,
|
2021-01-06 03:35:13 +08:00
|
|
|
caption: rndStr(),
|
|
|
|
rating: <any>rndInt(5),
|
2018-12-18 07:05:12 +08:00
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
|
|
|
|
2018-12-18 07:05:12 +08:00
|
|
|
const d: PhotoDTO = {
|
|
|
|
id: null,
|
|
|
|
name: rndStr() + '.jpg',
|
|
|
|
directory: dir,
|
|
|
|
metadata: m,
|
2019-01-28 03:36:42 +08:00
|
|
|
readyThumbnails: [],
|
2018-12-18 07:05:12 +08:00
|
|
|
readyIcon: false
|
|
|
|
};
|
2018-11-24 18:50:11 +08:00
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
for (let i = 0; i < faces; i++) {
|
|
|
|
this.getRandomizedFace(d, 'Person ' + i);
|
|
|
|
}
|
|
|
|
|
2018-11-24 18:50:11 +08:00
|
|
|
dir.media.push(d);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|