1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/model/sql/enitites/PhotoEntity.ts

137 lines
2.9 KiB
TypeScript
Raw Normal View History

2017-10-20 00:08:07 +08:00
import {Column, Entity, ManyToOne, PrimaryGeneratedColumn} from "typeorm";
2016-12-28 03:55:51 +08:00
import {DirectoryDTO} from "../../../../common/entities/DirectoryDTO";
import {
CameraMetadata,
2017-10-20 00:08:07 +08:00
GPSMetadata,
ImageSize,
PhotoDTO,
PhotoMetadata,
PositionMetaData
2016-12-28 03:55:51 +08:00
} from "../../../../common/entities/PhotoDTO";
import {DirectoryEntity} from "./DirectoryEntity";
2016-12-28 03:55:51 +08:00
2017-07-25 22:14:35 +08:00
@Entity()
export class PhotoEntity implements PhotoDTO {
@PrimaryGeneratedColumn()
id: number;
2017-10-20 00:08:07 +08:00
@Column("text")
2017-07-25 22:14:35 +08:00
name: string;
@ManyToOne(type => DirectoryEntity, directory => directory.photos, {onDelete: "CASCADE"})
directory: DirectoryDTO;
2017-10-20 00:08:07 +08:00
@Column(type => PhotoMetadataEntity)
2017-07-25 22:14:35 +08:00
metadata: PhotoMetadataEntity;
readyThumbnails: Array<number> = [];
readyIcon: boolean = false;
}
2017-10-20 00:08:07 +08:00
@Entity()
export class PhotoMetadataEntity implements PhotoMetadata {
@Column("simple-array")
keywords: Array<string>;
@Column(type => CameraMetadataEntity)
cameraData: CameraMetadataEntity;
@Column(type => PositionMetaDataEntity)
positionData: PositionMetaDataEntity;
@Column(type => ImageSizeEntity)
size: ImageSizeEntity;
@Column("bigint")
creationDate: number;
@Column("int")
fileSize: number;
/*
//TODO: fixit after typeorm update
public static open(m: PhotoMetadataEntity) {
m.keywords = <any>JSON.parse(<any>m.keywords);
m.cameraData = <any>JSON.parse(<any>m.cameraData);
m.positionData = <any>JSON.parse(<any>m.positionData);
m.size = <any>JSON.parse(<any>m.size);
}
//TODO: fixit after typeorm update
public static close(m: PhotoMetadataEntity) {
m.keywords = <any>JSON.stringify(<any>m.keywords);
m.cameraData = <any>JSON.stringify(<any>m.cameraData);
m.positionData = <any>JSON.stringify(<any>m.positionData);
m.size = <any>JSON.stringify(<any>m.size);
}*/
}
@Entity()
export class CameraMetadataEntity implements CameraMetadata {
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
ISO: number;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
model: string;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
maker: string;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("int", {nullable: true})
fStop: number;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("int", {nullable: true})
exposure: number;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("int", {nullable: true})
focalLength: number;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
lens: string;
}
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Entity()
export class PositionMetaDataEntity implements PositionMetaData {
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column(type => GPSMetadataEntity)
GPSData: GPSMetadataEntity;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
country: string;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
state: string;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("text", {nullable: true})
city: string;
}
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Entity()
export class GPSMetadataEntity implements GPSMetadata {
@Column("int", {nullable: true})
latitude: number;
@Column("int", {nullable: true})
longitude: number;
@Column("int", {nullable: true})
altitude: number;
}
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Entity()
export class ImageSizeEntity implements ImageSize {
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("int")
width: number;
2016-12-28 03:55:51 +08:00
2017-10-20 00:08:07 +08:00
@Column("int")
height: number;
}