import { AssetJobStatusEntity } from 'src/entities/asset-job-status.entity'; import { AssetEntity } from 'src/entities/asset.entity'; import { ExifEntity } from 'src/entities/exif.entity'; import { AssetFileType, AssetOrder, AssetType } from 'src/enum'; import { AssetSearchOptions, SearchExploreItem } from 'src/interfaces/search.interface'; import { Paginated, PaginationOptions } from 'src/utils/pagination'; import { FindOptionsOrder, FindOptionsRelations, FindOptionsSelect } from 'typeorm'; export type AssetStats = Record; export interface AssetStatsOptions { isFavorite?: boolean; isArchived?: boolean; isTrashed?: boolean; } export interface LivePhotoSearchOptions { ownerId: string; libraryId?: string | null; livePhotoCID: string; otherAssetId: string; type: AssetType; } export enum WithoutProperty { THUMBNAIL = 'thumbnail', ENCODED_VIDEO = 'encoded-video', EXIF = 'exif', SMART_SEARCH = 'smart-search', DUPLICATE = 'duplicate', OBJECT_TAGS = 'object-tags', FACES = 'faces', PERSON = 'person', SIDECAR = 'sidecar', } export enum WithProperty { SIDECAR = 'sidecar', IS_ONLINE = 'isOnline', IS_OFFLINE = 'isOffline', } export enum TimeBucketSize { DAY = 'DAY', MONTH = 'MONTH', } export interface AssetBuilderOptions { isArchived?: boolean; isFavorite?: boolean; isTrashed?: boolean; isDuplicate?: boolean; albumId?: string; tagId?: string; personId?: string; userIds?: string[]; withStacked?: boolean; exifInfo?: boolean; assetType?: AssetType; } export interface TimeBucketOptions extends AssetBuilderOptions { size: TimeBucketSize; order?: AssetOrder; } export interface TimeBucketItem { timeBucket: string; count: number; } export type AssetCreate = Pick< AssetEntity, | 'deviceAssetId' | 'ownerId' | 'libraryId' | 'deviceId' | 'type' | 'originalPath' | 'fileCreatedAt' | 'localDateTime' | 'fileModifiedAt' | 'checksum' | 'originalFileName' > & Partial; export type AssetWithoutRelations = Omit< AssetEntity, | 'livePhotoVideo' | 'stack' | 'albums' | 'faces' | 'owner' | 'library' | 'exifInfo' | 'sharedLinks' | 'smartInfo' | 'smartSearch' | 'tags' >; type AssetUpdateWithoutRelations = Pick & Partial; type AssetUpdateWithLivePhotoRelation = Pick & Pick; export type AssetUpdateOptions = AssetUpdateWithoutRelations | AssetUpdateWithLivePhotoRelation; export type AssetUpdateAllOptions = Omit, 'id'>; export interface MonthDay { day: number; month: number; } export interface AssetExploreFieldOptions { maxFields: number; minAssetsPerField: number; } export interface AssetExploreOptions extends AssetExploreFieldOptions { relation: keyof AssetEntity; relatedField: string; unnest?: boolean; } export interface AssetFullSyncOptions { ownerId: string; lastId?: string; updatedUntil: Date; limit: number; } export interface AssetDeltaSyncOptions { userIds: string[]; updatedAfter: Date; limit: number; } export interface AssetUpdateDuplicateOptions { targetDuplicateId: string | null; assetIds: string[]; duplicateIds: string[]; } export type AssetPathEntity = Pick; export const IAssetRepository = 'IAssetRepository'; export interface IAssetRepository { getAssetsByOriginalPath(userId: string, partialPath: string): Promise; getUniqueOriginalPaths(userId: string): Promise; create(asset: AssetCreate): Promise; getByIds( ids: string[], relations?: FindOptionsRelations, select?: FindOptionsSelect, ): Promise; getByIdsWithAllRelations(ids: string[]): Promise; getByDayOfYear(ownerIds: string[], monthDay: MonthDay): Promise; getByChecksum(options: { ownerId: string; checksum: Buffer; libraryId?: string }): Promise; getByChecksums(userId: string, checksums: Buffer[]): Promise; getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise; getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated; getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise; getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated; getById( id: string, relations?: FindOptionsRelations, order?: FindOptionsOrder, ): Promise; getWithout(pagination: PaginationOptions, property: WithoutProperty): Paginated; getWith( pagination: PaginationOptions, property: WithProperty, libraryId?: string, withDeleted?: boolean, ): Paginated; getRandom(userId: string, count: number): Promise; getFirstAssetForAlbumId(albumId: string): Promise; getLastUpdatedAssetForAlbumId(albumId: string): Promise; getExternalLibraryAssetPaths(pagination: PaginationOptions, libraryId: string): Paginated; getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise; deleteAll(ownerId: string): Promise; getAll(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; getAllByDeviceId(userId: string, deviceId: string): Promise; getLivePhotoCount(motionId: string): Promise; updateAll(ids: string[], options: Partial): Promise; updateDuplicates(options: AssetUpdateDuplicateOptions): Promise; update(asset: AssetUpdateOptions): Promise; remove(asset: AssetEntity): Promise; softDeleteAll(ids: string[]): Promise; restoreAll(ids: string[]): Promise; findLivePhotoMatch(options: LivePhotoSearchOptions): Promise; getStatistics(ownerId: string, options: AssetStatsOptions): Promise; getTimeBuckets(options: TimeBucketOptions): Promise; getTimeBucket(timeBucket: string, options: TimeBucketOptions): Promise; upsertExif(exif: Partial): Promise; upsertJobStatus(...jobStatus: Partial[]): Promise; getAssetIdByCity(userId: string, options: AssetExploreFieldOptions): Promise>; getAssetIdByTag(userId: string, options: AssetExploreFieldOptions): Promise>; getDuplicates(options: AssetBuilderOptions): Promise; getAllForUserFullSync(options: AssetFullSyncOptions): Promise; getChangedDeltaSync(options: AssetDeltaSyncOptions): Promise; upsertFile(options: { assetId: string; type: AssetFileType; path: string }): Promise; }