import {Column, Entity, ManyToOne, PrimaryGeneratedColumn} from "typeorm"; import {DirectoryDTO} from "../../../../common/entities/DirectoryDTO"; import { CameraMetadata, GPSMetadata, ImageSize, PhotoDTO, PhotoMetadata, PositionMetaData } from "../../../../common/entities/PhotoDTO"; import {DirectoryEntity} from "./DirectoryEntity"; @Entity() export class PhotoEntity implements PhotoDTO { @PrimaryGeneratedColumn() id: number; @Column("text") name: string; @ManyToOne(type => DirectoryEntity, directory => directory.photos, {onDelete: "CASCADE"}) directory: DirectoryDTO; @Column(type => PhotoMetadataEntity) metadata: PhotoMetadataEntity; readyThumbnails: Array = []; readyIcon: boolean = false; } @Entity() export class PhotoMetadataEntity implements PhotoMetadata { @Column("simple-array") keywords: Array; @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 = JSON.parse(m.keywords); m.cameraData = JSON.parse(m.cameraData); m.positionData = JSON.parse(m.positionData); m.size = JSON.parse(m.size); } //TODO: fixit after typeorm update public static close(m: PhotoMetadataEntity) { m.keywords = JSON.stringify(m.keywords); m.cameraData = JSON.stringify(m.cameraData); m.positionData = JSON.stringify(m.positionData); m.size = JSON.stringify(m.size); }*/ } @Entity() export class CameraMetadataEntity implements CameraMetadata { @Column("text", {nullable: true}) ISO: number; @Column("text", {nullable: true}) model: string; @Column("text", {nullable: true}) maker: string; @Column("int", {nullable: true}) fStop: number; @Column("int", {nullable: true}) exposure: number; @Column("int", {nullable: true}) focalLength: number; @Column("text", {nullable: true}) lens: string; } @Entity() export class PositionMetaDataEntity implements PositionMetaData { @Column(type => GPSMetadataEntity) GPSData: GPSMetadataEntity; @Column("text", {nullable: true}) country: string; @Column("text", {nullable: true}) state: string; @Column("text", {nullable: true}) city: string; } @Entity() export class GPSMetadataEntity implements GPSMetadata { @Column("int", {nullable: true}) latitude: number; @Column("int", {nullable: true}) longitude: number; @Column("int", {nullable: true}) altitude: number; } @Entity() export class ImageSizeEntity implements ImageSize { @Column("int") width: number; @Column("int") height: number; }