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

64 lines
1.6 KiB
TypeScript
Raw Normal View History

import {Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, Unique} from 'typeorm';
2018-03-31 03:30:30 +08:00
import {DirectoryDTO} from '../../../../common/entities/DirectoryDTO';
import {MediaEntity} from './MediaEntity';
2018-11-26 07:26:29 +08:00
import {FileEntity} from './FileEntity';
import {columnCharsetCS} from './EntityUtils';
2016-12-28 03:55:51 +08:00
2017-02-05 23:19:35 +08:00
@Entity()
@Unique(['name', 'path'])
export class DirectoryEntity implements DirectoryDTO {
2016-12-28 03:55:51 +08:00
@Index()
@PrimaryGeneratedColumn({unsigned: true})
2017-07-15 23:48:29 +08:00
id: number;
2016-12-28 03:55:51 +08:00
@Index()
@Column(columnCharsetCS)
2017-07-15 23:48:29 +08:00
name: string;
2016-12-28 03:55:51 +08:00
@Index()
2017-07-22 01:14:22 +08:00
@Column()
2017-07-15 23:48:29 +08:00
path: string;
2016-12-28 03:55:51 +08:00
2017-12-20 00:19:48 +08:00
/**
2018-11-05 02:28:32 +08:00
* last time the directory was modified (from outside, eg.: a new media was added)
2017-12-20 00:19:48 +08:00
*/
@Column('bigint', {
unsigned: true, transformer: {
from: v => parseInt(v, 10),
to: v => v
}
})
2017-07-20 02:47:09 +08:00
public lastModified: number;
2016-12-28 03:55:51 +08:00
2017-12-20 00:19:48 +08:00
/**
2018-11-05 02:28:32 +08:00
* Last time the directory was fully scanned, not only for a few media to create a preview
2017-12-20 00:19:48 +08:00
*/
@Column({
type: 'bigint', nullable: true, unsigned: true, transformer: {
from: v => parseInt(v, 10),
to: v => v
}
})
public lastScanned: number;
2016-12-28 22:35:27 +08:00
2017-07-22 01:14:22 +08:00
isPartial?: boolean;
@Column('smallint', {unsigned: true})
mediaCount: number;
@Index()
2018-03-31 03:30:30 +08:00
@ManyToOne(type => DirectoryEntity, directory => directory.directories, {onDelete: 'CASCADE'})
2017-07-15 23:48:29 +08:00
public parent: DirectoryEntity;
2016-12-28 03:55:51 +08:00
2017-07-15 23:48:29 +08:00
@OneToMany(type => DirectoryEntity, dir => dir.parent)
public directories: DirectoryEntity[];
2016-12-28 03:55:51 +08:00
@OneToMany(type => MediaEntity, media => media.directory)
public media: MediaEntity[];
2016-12-28 03:55:51 +08:00
2018-11-26 07:26:29 +08:00
@OneToMany(type => FileEntity, file => file.directory)
public metaFile: FileEntity[];
2017-07-15 23:48:29 +08:00
}