2023-02-06 17:24:58 +01:00
|
|
|
import {
|
|
|
|
Column,
|
2023-02-19 17:44:53 +01:00
|
|
|
CreateDateColumn,
|
2023-02-06 17:24:58 +01:00
|
|
|
Entity,
|
|
|
|
Index,
|
2023-02-19 17:44:53 +01:00
|
|
|
JoinColumn,
|
2023-02-06 17:24:58 +01:00
|
|
|
JoinTable,
|
|
|
|
ManyToMany,
|
2023-02-19 17:44:53 +01:00
|
|
|
ManyToOne,
|
2023-02-06 17:24:58 +01:00
|
|
|
OneToOne,
|
|
|
|
PrimaryGeneratedColumn,
|
|
|
|
Unique,
|
|
|
|
UpdateDateColumn,
|
|
|
|
} 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';
|
2023-02-19 17:44:53 +01:00
|
|
|
import { UserEntity } from './user.entity';
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Entity('assets')
|
2023-02-19 17:44:53 +01:00
|
|
|
@Unique('UQ_userid_checksum', ['owner', '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
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@ManyToOne(() => UserEntity, { eager: true, onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false })
|
|
|
|
owner!: UserEntity;
|
|
|
|
|
2022-02-03 17:06:44 +01:00
|
|
|
@Column()
|
2023-02-19 17:44:53 +01:00
|
|
|
ownerId!: 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
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@CreateDateColumn({ type: 'timestamptz' })
|
2022-06-25 19:53:06 +02:00
|
|
|
createdAt!: string;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2023-02-06 17:24:58 +01:00
|
|
|
@UpdateDateColumn({ type: 'timestamptz' })
|
|
|
|
updatedAt!: string;
|
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@Column({ type: 'timestamptz' })
|
|
|
|
fileCreatedAt!: string;
|
|
|
|
|
|
|
|
@Column({ type: 'timestamptz' })
|
|
|
|
fileModifiedAt!: 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;
|
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@OneToOne(() => AssetEntity, { nullable: true, onUpdate: 'CASCADE', onDelete: 'SET NULL' })
|
|
|
|
@JoinColumn()
|
|
|
|
livePhotoVideo!: AssetEntity | null;
|
|
|
|
|
|
|
|
@Column({ nullable: true })
|
2022-11-19 06:12:54 +01:00
|
|
|
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
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@ManyToMany(() => TagEntity, (tag) => tag.assets, { cascade: true, eager: true })
|
2022-12-05 18:56:44 +01:00
|
|
|
@JoinTable({ name: 'tag_asset' })
|
|
|
|
tags!: TagEntity[];
|
2023-01-09 21:16:08 +01:00
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@ManyToMany(() => SharedLinkEntity, (link) => link.assets, { cascade: true, eager: true })
|
2023-01-09 21:16:08 +01:00
|
|
|
@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',
|
|
|
|
}
|