1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 13:56:47 +01:00
immich/server/libs/infra/src/db/entities/asset.entity.ts

84 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-12-05 18:56:44 +01:00
import { Column, Entity, Index, JoinTable, ManyToMany, OneToOne, PrimaryGeneratedColumn, Unique } from 'typeorm';
import { ExifEntity } from './exif.entity';
import { SharedLinkEntity } from './shared-link.entity';
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')
@Unique('UQ_userid_checksum', ['userId', 'checksum'])
2022-02-03 17:06:44 +01:00
export class AssetEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
2022-02-03 17:06:44 +01:00
@Column()
deviceAssetId!: string;
2022-02-03 17:06:44 +01:00
@Column()
userId!: string;
2022-02-03 17:06:44 +01:00
@Column()
deviceId!: string;
2022-02-03 17:06:44 +01:00
@Column()
type!: AssetType;
2022-02-03 17:06:44 +01:00
@Column()
originalPath!: string;
2022-02-03 17:06:44 +01:00
@Column({ type: 'varchar', nullable: true })
resizePath!: string | null;
2022-02-03 17:06:44 +01:00
@Column({ type: 'varchar', nullable: true, default: '' })
webpPath!: string | null;
@Column({ type: 'varchar', nullable: true, default: '' })
encodedVideoPath!: string | null;
@Column({ type: 'timestamptz' })
createdAt!: string;
2022-02-03 17:06:44 +01:00
@Column({ type: 'timestamptz' })
modifiedAt!: string;
2022-02-03 17:06:44 +01:00
@Column({ type: 'boolean', default: false })
isFavorite!: boolean;
2022-02-03 17:06:44 +01:00
@Column({ type: 'varchar', nullable: true })
mimeType!: string | null;
2022-02-03 17:06:44 +01:00
@Column({ type: 'bytea', nullable: true, select: false })
@Index({ where: `'checksum' IS NOT NULL` }) // avoid null index
checksum?: Buffer | null; // sha1 checksum
@Column({ type: 'varchar', nullable: true })
duration!: string | null;
@Column({ type: 'boolean', default: true })
isVisible!: boolean;
@Column({ type: 'uuid', nullable: true })
livePhotoVideoId!: string | null;
@OneToOne(() => ExifEntity, (exifEntity) => exifEntity.asset)
exifInfo?: ExifEntity;
@OneToOne(() => SmartInfoEntity, (smartInfoEntity) => smartInfoEntity.asset)
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[];
@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',
}