2022-12-05 18:56:44 +01:00
|
|
|
import { Column, Entity, Index, JoinTable, ManyToMany, OneToOne, PrimaryGeneratedColumn, Unique } from 'typeorm';
|
2022-02-11 03:40:11 +01:00
|
|
|
import { ExifEntity } from './exif.entity';
|
2023-01-09 21:16:08 +01:00
|
|
|
import { SharedLinkEntity } from './shared-link.entity';
|
2022-02-20 05:42:10 +01:00
|
|
|
import { SmartInfoEntity } from './smart-info.entity';
|
2022-12-05 18:56:44 +01:00
|
|
|
import { TagEntity } from './tag.entity';
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Entity('assets')
|
2022-09-05 21:45:38 +02:00
|
|
|
@Unique('UQ_userid_checksum', ['userId', 'checksum'])
|
2022-02-03 17:06:44 +01:00
|
|
|
export class AssetEntity {
|
|
|
|
@PrimaryGeneratedColumn('uuid')
|
2022-06-25 19:53:06 +02:00
|
|
|
id!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Column()
|
2022-06-25 19:53:06 +02:00
|
|
|
deviceAssetId!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Column()
|
2022-06-25 19:53:06 +02:00
|
|
|
userId!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Column()
|
2022-06-25 19:53:06 +02:00
|
|
|
deviceId!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Column()
|
2022-06-25 19:53:06 +02:00
|
|
|
type!: AssetType;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Column()
|
2022-06-25 19:53:06 +02:00
|
|
|
originalPath!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2022-06-25 19:53:06 +02:00
|
|
|
@Column({ type: 'varchar', nullable: true })
|
|
|
|
resizePath!: string | null;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2022-07-04 21:20:43 +02:00
|
|
|
@Column({ type: 'varchar', nullable: true, default: '' })
|
2022-06-25 19:53:06 +02:00
|
|
|
webpPath!: string | null;
|
2022-05-22 13:56:36 +02:00
|
|
|
|
2022-07-04 21:20:43 +02:00
|
|
|
@Column({ type: 'varchar', nullable: true, default: '' })
|
2023-01-30 17:14:13 +01:00
|
|
|
encodedVideoPath!: string | null;
|
2022-06-05 01:34:11 +02:00
|
|
|
|
2022-09-06 03:51:01 +02:00
|
|
|
@Column({ type: 'timestamptz' })
|
2022-06-25 19:53:06 +02:00
|
|
|
createdAt!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2022-09-06 03:51:01 +02:00
|
|
|
@Column({ type: 'timestamptz' })
|
2022-06-25 19:53:06 +02:00
|
|
|
modifiedAt!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Column({ type: 'boolean', default: false })
|
2022-06-25 19:53:06 +02:00
|
|
|
isFavorite!: boolean;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2022-06-25 19:53:06 +02:00
|
|
|
@Column({ type: 'varchar', nullable: true })
|
|
|
|
mimeType!: string | null;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2022-08-31 16:27:17 +02:00
|
|
|
@Column({ type: 'bytea', nullable: true, select: false })
|
|
|
|
@Index({ where: `'checksum' IS NOT NULL` }) // avoid null index
|
|
|
|
checksum?: Buffer | null; // sha1 checksum
|
|
|
|
|
2022-06-25 19:53:06 +02:00
|
|
|
@Column({ type: 'varchar', nullable: true })
|
|
|
|
duration!: string | null;
|
2022-02-11 03:40:11 +01:00
|
|
|
|
2022-11-19 06:12:54 +01:00
|
|
|
@Column({ type: 'boolean', default: true })
|
|
|
|
isVisible!: boolean;
|
|
|
|
|
|
|
|
@Column({ type: 'uuid', nullable: true })
|
|
|
|
livePhotoVideoId!: string | null;
|
|
|
|
|
2022-02-11 03:40:11 +01:00
|
|
|
@OneToOne(() => ExifEntity, (exifEntity) => exifEntity.asset)
|
2022-06-25 19:53:06 +02:00
|
|
|
exifInfo?: ExifEntity;
|
2022-02-20 05:42:10 +01:00
|
|
|
|
|
|
|
@OneToOne(() => SmartInfoEntity, (smartInfoEntity) => smartInfoEntity.asset)
|
2022-06-25 19:53:06 +02:00
|
|
|
smartInfo?: SmartInfoEntity;
|
2022-12-05 18:56:44 +01:00
|
|
|
|
|
|
|
// https://github.com/typeorm/typeorm/blob/master/docs/many-to-many-relations.md
|
|
|
|
@ManyToMany(() => TagEntity, (tag) => tag.assets, { cascade: true })
|
|
|
|
@JoinTable({ name: 'tag_asset' })
|
|
|
|
tags!: TagEntity[];
|
2023-01-09 21:16:08 +01:00
|
|
|
|
|
|
|
@ManyToMany(() => SharedLinkEntity, (link) => link.assets, { cascade: true })
|
|
|
|
@JoinTable({ name: 'shared_link__asset' })
|
|
|
|
sharedLinks!: SharedLinkEntity[];
|
2022-02-03 17:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum AssetType {
|
|
|
|
IMAGE = 'IMAGE',
|
|
|
|
VIDEO = 'VIDEO',
|
|
|
|
AUDIO = 'AUDIO',
|
|
|
|
OTHER = 'OTHER',
|
|
|
|
}
|