2019-01-28 03:36:42 +08:00
|
|
|
import {Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance, Unique} from 'typeorm';
|
2018-11-18 02:32:31 +08:00
|
|
|
import {DirectoryEntity} from './DirectoryEntity';
|
|
|
|
import {MediaDimension, MediaDTO, MediaMetadata} from '../../../../common/entities/MediaDTO';
|
|
|
|
import {OrientationTypes} from 'ts-exif-parser';
|
|
|
|
import {CameraMetadataEntity, PositionMetaDataEntity} from './PhotoEntity';
|
2019-01-12 23:41:45 +08:00
|
|
|
import {FaceRegionEntry} from './FaceRegionEntry';
|
2019-02-07 23:21:23 +08:00
|
|
|
import {Config} from '../../../../common/config/private/Config';
|
|
|
|
import {DatabaseType} from '../../../../common/config/private/IPrivateConfig';
|
|
|
|
import {columnCharsetCS} from './EntityUtils';
|
2018-11-18 02:32:31 +08:00
|
|
|
|
|
|
|
export class MediaDimensionEntity implements MediaDimension {
|
|
|
|
|
|
|
|
@Column('int')
|
|
|
|
width: number;
|
|
|
|
|
|
|
|
@Column('int')
|
|
|
|
height: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class MediaMetadataEntity implements MediaMetadata {
|
2018-12-06 00:29:33 +08:00
|
|
|
@Column('text')
|
|
|
|
caption: string;
|
2018-11-18 02:32:31 +08:00
|
|
|
|
|
|
|
@Column(type => MediaDimensionEntity)
|
|
|
|
size: MediaDimensionEntity;
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
@Column('bigint', {
|
|
|
|
unsigned: true, transformer: {
|
|
|
|
from: v => parseInt(v, 10),
|
|
|
|
to: v => v
|
|
|
|
}
|
|
|
|
})
|
2018-11-18 02:32:31 +08:00
|
|
|
creationDate: number;
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
@Column('int', {unsigned: true})
|
2018-11-18 02:32:31 +08:00
|
|
|
fileSize: number;
|
|
|
|
|
|
|
|
@Column('simple-array')
|
|
|
|
keywords: string[];
|
|
|
|
|
|
|
|
@Column(type => CameraMetadataEntity)
|
|
|
|
cameraData: CameraMetadataEntity;
|
|
|
|
|
|
|
|
@Column(type => PositionMetaDataEntity)
|
|
|
|
positionData: PositionMetaDataEntity;
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
@Column('tinyint', {unsigned: true, default: OrientationTypes.TOP_LEFT})
|
2018-11-18 02:32:31 +08:00
|
|
|
orientation: OrientationTypes;
|
|
|
|
|
2019-01-12 23:41:45 +08:00
|
|
|
@OneToMany(type => FaceRegionEntry, faceRegion => faceRegion.media)
|
|
|
|
faces: FaceRegionEntry[];
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
@Column('int', {unsigned: true})
|
2018-11-18 02:32:31 +08:00
|
|
|
bitRate: number;
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
@Column('int', {unsigned: true})
|
2018-11-18 02:32:31 +08:00
|
|
|
duration: number;
|
|
|
|
}
|
|
|
|
|
2019-02-07 23:21:23 +08:00
|
|
|
|
|
|
|
|
2018-11-18 02:32:31 +08:00
|
|
|
// TODO: fix inheritance once its working in typeorm
|
|
|
|
@Entity()
|
2018-12-09 18:37:12 +08:00
|
|
|
@Unique(['name', 'directory'])
|
2019-01-28 03:36:42 +08:00
|
|
|
@TableInheritance({column: {type: 'varchar', name: 'type', length: 32}})
|
2018-12-06 00:29:33 +08:00
|
|
|
export abstract class MediaEntity implements MediaDTO {
|
2018-11-18 02:32:31 +08:00
|
|
|
|
2019-01-07 06:15:52 +08:00
|
|
|
@Index()
|
2019-01-28 03:36:42 +08:00
|
|
|
@PrimaryGeneratedColumn({unsigned: true})
|
2018-11-18 02:32:31 +08:00
|
|
|
id: number;
|
|
|
|
|
2019-02-07 23:21:23 +08:00
|
|
|
@Column(columnCharsetCS)
|
2018-11-18 02:32:31 +08:00
|
|
|
name: string;
|
|
|
|
|
2019-01-07 06:15:52 +08:00
|
|
|
@Index()
|
2018-11-18 02:32:31 +08:00
|
|
|
@ManyToOne(type => DirectoryEntity, directory => directory.media, {onDelete: 'CASCADE'})
|
|
|
|
directory: DirectoryEntity;
|
|
|
|
|
|
|
|
@Column(type => MediaMetadataEntity)
|
|
|
|
metadata: MediaMetadataEntity;
|
|
|
|
|
|
|
|
readyThumbnails: number[] = [];
|
|
|
|
|
|
|
|
readyIcon = false;
|
|
|
|
|
|
|
|
}
|