2024-03-20 19:32:04 +01:00
|
|
|
import { AlbumEntity } from 'src/infra/entities/album.entity';
|
|
|
|
import { AssetFaceEntity } from 'src/infra/entities/asset-face.entity';
|
|
|
|
import { AssetJobStatusEntity } from 'src/infra/entities/asset-job-status.entity';
|
|
|
|
import { AssetStackEntity } from 'src/infra/entities/asset-stack.entity';
|
|
|
|
import { ExifEntity } from 'src/infra/entities/exif.entity';
|
|
|
|
import { LibraryEntity } from 'src/infra/entities/library.entity';
|
|
|
|
import { SharedLinkEntity } from 'src/infra/entities/shared-link.entity';
|
|
|
|
import { SmartInfoEntity } from 'src/infra/entities/smart-info.entity';
|
|
|
|
import { SmartSearchEntity } from 'src/infra/entities/smart-search.entity';
|
|
|
|
import { TagEntity } from 'src/infra/entities/tag.entity';
|
|
|
|
import { UserEntity } from 'src/infra/entities/user.entity';
|
2023-02-06 17:24:58 +01:00
|
|
|
import {
|
|
|
|
Column,
|
2023-02-19 17:44:53 +01:00
|
|
|
CreateDateColumn,
|
2023-10-06 09:01:14 +02:00
|
|
|
DeleteDateColumn,
|
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-05-17 19:07:17 +02:00
|
|
|
OneToMany,
|
2023-02-06 17:24:58 +01:00
|
|
|
OneToOne,
|
|
|
|
PrimaryGeneratedColumn,
|
|
|
|
UpdateDateColumn,
|
|
|
|
} from 'typeorm';
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2023-09-20 13:16:33 +02:00
|
|
|
export const ASSET_CHECKSUM_CONSTRAINT = 'UQ_assets_owner_library_checksum';
|
|
|
|
|
2022-02-03 17:06:44 +01:00
|
|
|
@Entity('assets')
|
2023-09-20 13:16:33 +02:00
|
|
|
// Checksums must be unique per user and library
|
|
|
|
@Index(ASSET_CHECKSUM_CONSTRAINT, ['owner', 'library', 'checksum'], {
|
|
|
|
unique: true,
|
|
|
|
})
|
2023-10-05 00:11:11 +02:00
|
|
|
@Index('IDX_day_of_month', { synchronize: false })
|
|
|
|
@Index('IDX_month', { synchronize: false })
|
2023-10-10 15:38:26 +02:00
|
|
|
@Index('IDX_originalPath_libraryId', ['originalPath', 'libraryId'])
|
2024-03-14 06:58:09 +01:00
|
|
|
@Index('IDX_asset_id_stackId', ['id', 'stackId'])
|
2024-03-07 04:36:08 +01:00
|
|
|
@Index('idx_originalFileName_trigram', { synchronize: false })
|
2023-09-20 13:16:33 +02:00
|
|
|
// For all assets, each originalpath must be unique per user and library
|
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-28 01:28:45 +01:00
|
|
|
@ManyToOne(() => UserEntity, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false })
|
2023-02-19 17:44:53 +01:00
|
|
|
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
|
|
|
|
2023-09-20 13:16:33 +02:00
|
|
|
@ManyToOne(() => LibraryEntity, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false })
|
|
|
|
library!: LibraryEntity;
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
libraryId!: 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
|
|
|
|
2023-09-20 13:16:33 +02: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
|
|
|
|
2023-06-18 05:22:31 +02:00
|
|
|
@Column({ type: 'bytea', nullable: true })
|
|
|
|
thumbhash!: Buffer | null;
|
|
|
|
|
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' })
|
2023-05-29 16:05:14 +02:00
|
|
|
createdAt!: Date;
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2023-02-06 17:24:58 +01:00
|
|
|
@UpdateDateColumn({ type: 'timestamptz' })
|
2023-05-29 16:05:14 +02:00
|
|
|
updatedAt!: Date;
|
2023-02-06 17:24:58 +01:00
|
|
|
|
2023-10-06 09:01:14 +02:00
|
|
|
@DeleteDateColumn({ type: 'timestamptz', nullable: true })
|
|
|
|
deletedAt!: Date | null;
|
|
|
|
|
2024-02-18 19:22:25 +01:00
|
|
|
@Index('idx_asset_file_created_at')
|
2023-02-19 17:44:53 +01:00
|
|
|
@Column({ type: 'timestamptz' })
|
2023-05-29 16:05:14 +02:00
|
|
|
fileCreatedAt!: Date;
|
2023-02-19 17:44:53 +01:00
|
|
|
|
2023-10-06 14:12:09 +02:00
|
|
|
@Column({ type: 'timestamptz' })
|
2023-10-05 00:11:11 +02:00
|
|
|
localDateTime!: Date;
|
|
|
|
|
2023-02-19 17:44:53 +01:00
|
|
|
@Column({ type: 'timestamptz' })
|
2023-05-29 16:05:14 +02:00
|
|
|
fileModifiedAt!: Date;
|
2023-02-19 17:44:53 +01:00
|
|
|
|
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
|
|
|
|
2023-04-12 17:37:52 +02:00
|
|
|
@Column({ type: 'boolean', default: false })
|
|
|
|
isArchived!: boolean;
|
|
|
|
|
2023-09-20 13:16:33 +02:00
|
|
|
@Column({ type: 'boolean', default: false })
|
|
|
|
isExternal!: boolean;
|
|
|
|
|
feat(server): support for read-only assets and importing existing items in the filesystem (#2715)
* Added read-only flag for assets, endpoint to trigger file import vs upload
* updated fixtures with new property
* if upload is 'read-only', ensure there is no existing asset at the designated originalPath
* added test for file import as well as detecting existing image at read-only destination location
* Added storage service test for a case where it should not move read-only assets
* upload doesn't need the read-only flag available, just importing
* default isReadOnly on import endpoint to true
* formatting fixes
* create-asset dto needs isReadOnly, so set it to false by default on create, updated api generation
* updated code to reflect changes in MR
* fixed read stream promise return type
* new index for originalPath, check for existing path on import, reglardless of user, to prevent duplicates
* refactor: import asset
* chore: open api
* chore: tests
* Added externalPath support for individual users, updated UI to allow this to be set by admin
* added missing var for externalPath in ui
* chore: open api
* fix: compilation issues
* fix: server test
* built api, fixed user-response dto to include externalPath
* reverted accidental commit
* bad commit of duplicate externalPath in user response dto
* fixed tests to include externalPath on expected result
* fix: unit tests
* centralized supported filetypes, perform file type checking of asset and sidecar during file import process
* centralized supported filetype check method to keep regex DRY
* fixed typo
* combined migrations into one
* update api
* Removed externalPath from shared-link code, added column to admin user page whether external paths / import is enabled or not
* update mimetype
* Fixed detect correct mimetype
* revert asset-upload config
* reverted domain.constant
* refactor
* fix mime-type issue
* fix format
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-06-22 04:33:20 +02:00
|
|
|
@Column({ type: 'boolean', default: false })
|
|
|
|
isReadOnly!: boolean;
|
|
|
|
|
2023-09-20 13:16:33 +02:00
|
|
|
@Column({ type: 'boolean', default: false })
|
|
|
|
isOffline!: boolean;
|
|
|
|
|
2023-05-24 23:08:21 +02:00
|
|
|
@Column({ type: 'bytea' })
|
|
|
|
@Index()
|
|
|
|
checksum!: Buffer; // sha1 checksum
|
2022-08-31 16:27:17 +02:00
|
|
|
|
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;
|
|
|
|
|
2023-04-11 12:23:39 +02:00
|
|
|
@Column({ type: 'varchar' })
|
fix(server): add filename search (#6394)
Fixes https://github.com/immich-app/immich/issues/5982.
There are basically three options:
1. Search `originalFileName` by dropping a file extension from the query
(if present). Lower fidelity but very easy - just a standard index &
equality.
2. Search `originalPath` by adding an index on `reverse(originalPath)`
and using `starts_with(reverse(query) + "/", reverse(originalPath)`. A
weird index & query but high fidelity.
3. Add a new generated column called `originalFileNameWithExtension` or
something. More storage, kinda jank.
TBH, I think (1) is good enough and easy to make better in the future.
For example, if I search "DSC_4242.jpg", I don't really think it matters
if "DSC_4242.mov" also shows up.
edit: There's a fourth approach that we discussed a bit in Discord and
decided we could switch to it in the future: using a GIN. The minor
issue is that Postgres doesn't tokenize paths in a useful (they're a
single token and it won't match against partial components). We can
solve that by tokenizing it ourselves. For example:
```
immich=# with vecs as (select to_tsvector('simple', array_to_string(string_to_array('upload/library/sushain/2015/2015-08-09/IMG_275.JPG', '/'), ' ')) as vec) select * from vecs where vec @@ phraseto_tsquery('simple', array_to_string(string_to_array('library/sushain', '/'), ' '));
vec
-------------------------------------------------------------------------------
'-08':6 '-09':7 '2015':4,5 'img_275.jpg':8 'library':2 'sushain':3 'upload':1
(1 row)
```
The query is also tokenized with the 'split-by-slash-join-with-space'
strategy. This strategy results in `IMG_275.JPG`, `2015`, `sushain` and
`library/sushain` matching. But, `08` and `IMG_275` do not match. The
former is because the token is `-08` and the latter because the
`img_275.jpg` token is matched against exactly.
2024-01-15 21:40:28 +01:00
|
|
|
@Index()
|
2023-04-11 12:23:39 +02:00
|
|
|
originalFileName!: string;
|
|
|
|
|
feat(server): xmp sidecar metadata (#2466)
* initial commit for XMP sidecar support
* Added support for 'missing' metadata files to include those without sidecar files, now detects sidecar files in the filesystem for media already ingested but the sidecar was created afterwards
* didn't mean to commit default log level during testing
* new sidecar logic for video metadata as well
* Added xml mimetype for sidecars only
* don't need capture group for this regex
* wrong default value reverted
* simplified the move here - keep it in the same try catch since the outcome is to move the media back anyway
* simplified setter logic
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
* simplified logic per suggestions
* sidecar is now its own queue with a discover and sync, updated UI for the new job queueing
* queue a sidecar job for every asset based on discovery or sync, though the logic is almost identical aside from linking the sidecar
* now queue sidecar jobs for each assset, though logic is mostly the same between discovery and sync
* simplified logic of filename extraction and asset instantiation
* not sure how that got deleted..
* updated code per suggestions and comments in the PR
* stat was not being used, removed the variable set
* better type checking, using in-scope variables for exif getter instead of passing in every time
* removed commented out test
* ran and resolved all lints, formats, checks, and tests
* resolved suggested change in PR
* made getExifProperty more dynamic with multiple possible args for fallbacks, fixed typo, used generic in function for better type checking
* better error handling and moving files back to positions on move or save failure
* regenerated api
* format fixes
* Added XMP documentation
* documentation typo
* Merged in main
* missed merge conflict
* more changes due to a merge
* Resolving conflicts
* added icon for sidecar jobs
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-05-25 03:59:30 +02:00
|
|
|
@Column({ type: 'varchar', nullable: true })
|
|
|
|
sidecarPath!: 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-12-08 17:15:46 +01:00
|
|
|
@OneToOne(() => SmartSearchEntity, (smartSearchEntity) => smartSearchEntity.asset)
|
|
|
|
smartSearch?: SmartSearchEntity;
|
|
|
|
|
2023-02-28 01:28:45 +01:00
|
|
|
@ManyToMany(() => TagEntity, (tag) => tag.assets, { cascade: true })
|
2024-03-14 06:58:09 +01:00
|
|
|
@JoinTable({ name: 'tag_asset', synchronize: false })
|
2022-12-05 18:56:44 +01:00
|
|
|
tags!: TagEntity[];
|
2023-01-09 21:16:08 +01:00
|
|
|
|
2023-02-28 01:28:45 +01:00
|
|
|
@ManyToMany(() => SharedLinkEntity, (link) => link.assets, { cascade: true })
|
2023-01-09 21:16:08 +01:00
|
|
|
@JoinTable({ name: 'shared_link__asset' })
|
|
|
|
sharedLinks!: SharedLinkEntity[];
|
2023-03-26 04:46:48 +02:00
|
|
|
|
2023-04-10 04:48:01 +02:00
|
|
|
@ManyToMany(() => AlbumEntity, (album) => album.assets, { onDelete: 'CASCADE', onUpdate: 'CASCADE' })
|
2023-03-26 04:46:48 +02:00
|
|
|
albums?: AlbumEntity[];
|
2023-05-17 19:07:17 +02:00
|
|
|
|
|
|
|
@OneToMany(() => AssetFaceEntity, (assetFace) => assetFace.asset)
|
|
|
|
faces!: AssetFaceEntity[];
|
2023-10-22 04:38:07 +02:00
|
|
|
|
|
|
|
@Column({ nullable: true })
|
2024-01-27 19:52:14 +01:00
|
|
|
stackId?: string | null;
|
2023-10-22 04:38:07 +02:00
|
|
|
|
2024-01-27 19:52:14 +01:00
|
|
|
@ManyToOne(() => AssetStackEntity, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE' })
|
|
|
|
@JoinColumn()
|
|
|
|
stack?: AssetStackEntity | null;
|
2023-11-10 02:55:00 +01:00
|
|
|
|
|
|
|
@OneToOne(() => AssetJobStatusEntity, (jobStatus) => jobStatus.asset, { nullable: true })
|
|
|
|
jobStatus?: AssetJobStatusEntity;
|
2022-02-03 17:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum AssetType {
|
|
|
|
IMAGE = 'IMAGE',
|
|
|
|
VIDEO = 'VIDEO',
|
|
|
|
AUDIO = 'AUDIO',
|
|
|
|
OTHER = 'OTHER',
|
|
|
|
}
|