mirror of
https://github.com/immich-app/immich.git
synced 2025-06-02 21:24:28 -04:00
* add job to check for offline files * fix lint * only check for offline when using checkForOffline * improve tests * remove old test * wip * remove trie * refactor batches * also check offline status * fix spelling * don't do offline scan * rename scan to check * fix job statuses * fix lint * cleanup * add test * open-api * fix test * fix spinner * reset text * don't double batch * fix comments from mert * remove tries * fix tests * fix e2e * fix test * fix test * add tests * fix lint * fix e2e * interweave scans * fix errors * fix messages * fix test * add mock * fix sql * fix e2e * use library batch size * save -> update * add file extensions * update specs * test for import paths * check import paths when testing offline * fix lint * normalize import path * remove console logs * decrease batch size to 1000 * add test for import path * add test for already-online assets * fix merge * fix lint * add library job back * add offline job to correct queue * library spec compiles now * move one test to new e2e * fix comments * fix comments * fix lint * refactor path validation * fix loop bug * remove logging * expect responses * fix asset mock * take the straightforward approach * use generator correctly * fix vitest on file edit * bump vitest to 1.6.0 * test for offline check * add e2e tests for offlining assets depending on import path * cleanup e2e test after finish * cleanup library service * paginate the walk generator * fix tests * fix typo * refactoring handleOfflineCheck * better testing of handleOfflineCheck * fix lint * handle large library deletions * dont check if library is deleted * fix mock * add a 100k page size to library * fix loading animation * better log messages * Better logging for offline asset removal * fix sql and tests * fix number format * Remove submodule * fix format * chore: cleanup * chore: fix tests --------- Co-authored-by: Alex <alex.tran1502@gmail.com> Co-authored-by: Jason Rasmussen <jason@rasm.me>
200 lines
6.8 KiB
TypeScript
200 lines
6.8 KiB
TypeScript
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<AssetType, number>;
|
|
|
|
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;
|
|
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<AssetEntity>;
|
|
|
|
export type AssetWithoutRelations = Omit<
|
|
AssetEntity,
|
|
| 'livePhotoVideo'
|
|
| 'stack'
|
|
| 'albums'
|
|
| 'faces'
|
|
| 'owner'
|
|
| 'library'
|
|
| 'exifInfo'
|
|
| 'sharedLinks'
|
|
| 'smartInfo'
|
|
| 'smartSearch'
|
|
| 'tags'
|
|
>;
|
|
|
|
type AssetUpdateWithoutRelations = Pick<AssetWithoutRelations, 'id'> & Partial<AssetWithoutRelations>;
|
|
type AssetUpdateWithLivePhotoRelation = Pick<AssetWithoutRelations, 'id'> & Pick<AssetEntity, 'livePhotoVideo'>;
|
|
|
|
export type AssetUpdateOptions = AssetUpdateWithoutRelations | AssetUpdateWithLivePhotoRelation;
|
|
|
|
export type AssetUpdateAllOptions = Omit<Partial<AssetWithoutRelations>, '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<AssetEntity, 'id' | 'originalPath' | 'isOffline'>;
|
|
|
|
export const IAssetRepository = 'IAssetRepository';
|
|
|
|
export interface IAssetRepository {
|
|
getAssetsByOriginalPath(userId: string, partialPath: string): Promise<AssetEntity[]>;
|
|
getUniqueOriginalPaths(userId: string): Promise<string[]>;
|
|
create(asset: AssetCreate): Promise<AssetEntity>;
|
|
getByIds(
|
|
ids: string[],
|
|
relations?: FindOptionsRelations<AssetEntity>,
|
|
select?: FindOptionsSelect<AssetEntity>,
|
|
): Promise<AssetEntity[]>;
|
|
getByIdsWithAllRelations(ids: string[]): Promise<AssetEntity[]>;
|
|
getByDayOfYear(ownerIds: string[], monthDay: MonthDay): Promise<AssetEntity[]>;
|
|
getByChecksum(options: { ownerId: string; checksum: Buffer; libraryId?: string }): Promise<AssetEntity | null>;
|
|
getByChecksums(userId: string, checksums: Buffer[]): Promise<AssetEntity[]>;
|
|
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
|
|
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
|
|
getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]>;
|
|
getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated<AssetEntity>;
|
|
getById(
|
|
id: string,
|
|
relations?: FindOptionsRelations<AssetEntity>,
|
|
order?: FindOptionsOrder<AssetEntity>,
|
|
): Promise<AssetEntity | null>;
|
|
getWithout(pagination: PaginationOptions, property: WithoutProperty): Paginated<AssetEntity>;
|
|
getWith(pagination: PaginationOptions, property: WithProperty, libraryId?: string): Paginated<AssetEntity>;
|
|
getRandom(userId: string, count: number): Promise<AssetEntity[]>;
|
|
getFirstAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
|
|
getLastUpdatedAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
|
|
getExternalLibraryAssetPaths(pagination: PaginationOptions, libraryId: string): Paginated<AssetPathEntity>;
|
|
getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise<AssetEntity | null>;
|
|
deleteAll(ownerId: string): Promise<void>;
|
|
getAll(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated<AssetEntity>;
|
|
getAllByDeviceId(userId: string, deviceId: string): Promise<string[]>;
|
|
getLivePhotoCount(motionId: string): Promise<number>;
|
|
updateAll(ids: string[], options: Partial<AssetUpdateAllOptions>): Promise<void>;
|
|
updateDuplicates(options: AssetUpdateDuplicateOptions): Promise<void>;
|
|
update(asset: AssetUpdateOptions): Promise<void>;
|
|
remove(asset: AssetEntity): Promise<void>;
|
|
softDeleteAll(ids: string[]): Promise<void>;
|
|
restoreAll(ids: string[]): Promise<void>;
|
|
findLivePhotoMatch(options: LivePhotoSearchOptions): Promise<AssetEntity | null>;
|
|
getStatistics(ownerId: string, options: AssetStatsOptions): Promise<AssetStats>;
|
|
getTimeBuckets(options: TimeBucketOptions): Promise<TimeBucketItem[]>;
|
|
getTimeBucket(timeBucket: string, options: TimeBucketOptions): Promise<AssetEntity[]>;
|
|
upsertExif(exif: Partial<ExifEntity>): Promise<void>;
|
|
upsertJobStatus(...jobStatus: Partial<AssetJobStatusEntity>[]): Promise<void>;
|
|
getAssetIdByCity(userId: string, options: AssetExploreFieldOptions): Promise<SearchExploreItem<string>>;
|
|
getAssetIdByTag(userId: string, options: AssetExploreFieldOptions): Promise<SearchExploreItem<string>>;
|
|
getDuplicates(options: AssetBuilderOptions): Promise<AssetEntity[]>;
|
|
getAllForUserFullSync(options: AssetFullSyncOptions): Promise<AssetEntity[]>;
|
|
getChangedDeltaSync(options: AssetDeltaSyncOptions): Promise<AssetEntity[]>;
|
|
upsertFile(options: { assetId: string; type: AssetFileType; path: string }): Promise<void>;
|
|
}
|