Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): library refresh go brrr #14456

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 193 additions & 4 deletions e2e/src/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
it('should require authentication', async () => {
const { status, body } = await request(app).get(`/libraries/${uuidDto.notFound}/statistics`);

expect(status).toBe(401);

Check failure on line 275 in e2e/src/api/specs/library.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests (Server & CLI)

src/api/specs/library.e2e-spec.ts > /libraries > GET /libraries/:id/statistics > should require authentication

AssertionError: expected 404 to be 401 // Object.is equality - Expected + Received - 401 + 404 ❯ src/api/specs/library.e2e-spec.ts:275:22
expect(body).toEqual(errorDto.unauthorized);
});
});
Expand Down Expand Up @@ -421,7 +421,7 @@
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ refreshModifiedFiles: true });
.send();
expect(status).toBe(204);

await utils.waitForQueueFinish(admin.accessToken, 'library');
Expand Down Expand Up @@ -453,7 +453,7 @@
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ refreshModifiedFiles: true });
.send();
expect(status).toBe(204);

await utils.waitForQueueFinish(admin.accessToken, 'library');
Expand All @@ -464,7 +464,7 @@
libraryId: library.id,
model: 'NIKON D750',
});
expect(assets.count).toBe(0);

Check failure on line 467 in e2e/src/api/specs/library.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests (Server & CLI)

src/api/specs/library.e2e-spec.ts > /libraries > POST /libraries/:id/scan > should not reimport unmodified files

AssertionError: expected 1 to be +0 // Object.is equality - Expected + Received - 0 + 1 ❯ src/api/specs/library.e2e-spec.ts:467:28
});

it('should set an asset offline if its file is missing', async () => {
Expand Down Expand Up @@ -499,7 +499,7 @@
expect(newAssets.items).toEqual([]);
});

it('should set an asset offline its file is not in any import path', async () => {
it('should set an asset offline if its file is not in any import path', async () => {
utils.createImageFile(`${testAssetDir}/temp/offline/offline.png`);

const library = await utils.createLibrary(admin.accessToken, {
Expand Down Expand Up @@ -564,7 +564,7 @@
await utils.waitForQueueFinish(admin.accessToken, 'library');

const trashedAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);
expect(trashedAsset.isTrashed).toBe(true);

Check failure on line 567 in e2e/src/api/specs/library.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests (Server & CLI)

src/api/specs/library.e2e-spec.ts > /libraries > POST /libraries/:id/scan > should set an asset offline if its file is covered by an exclusion pattern

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/api/specs/library.e2e-spec.ts:567:38
expect(trashedAsset.originalPath).toBe(`${testAssetDirInternal}/temp/directoryB/assetB.png`);
expect(trashedAsset.isOffline).toBe(true);

Expand All @@ -577,7 +577,7 @@
]);
});

it('should not trash an online asset', async () => {
it('should not set an asset offline if its file exists, is in an import path, and not covered by an exclusion pattern', async () => {
const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp`],
Expand All @@ -599,8 +599,197 @@

const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });

expect(assets).toEqual(assetsBefore);

Check failure on line 602 in e2e/src/api/specs/library.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests (Server & CLI)

src/api/specs/library.e2e-spec.ts > /libraries > POST /libraries/:id/scan > should not set an asset offline if its file exists, is in an import path, and not covered by an exclusion pattern

AssertionError: expected { total: 2, count: 2, …(3) } to deeply equal { total: 2, count: 2, …(3) } - Expected + Received Object { "count": 2, "facets": Array [], "items": Array [ Object { "checksum": "M2FwQNSs1Ni7hYZDAvy1Fl9YXKs=", "deviceAssetId": "assetB.png", "deviceId": "Library Import", "duplicateId": null, "duration": "0:00:00.00000", "fileCreatedAt": "1900-01-01T00:00:00.000Z", "fileModifiedAt": "1900-01-01T00:00:00.000Z", "hasMetadata": true, "id": "c8f84a36-6091-4046-a8a8-0947afdc1f13", "isArchived": false, "isFavorite": false, "isOffline": false, "isTrashed": false, "libraryId": "85346036-6e72-4291-a32f-f4e1038780af", "livePhotoVideoId": null, "localDateTime": "1900-01-01T00:00:00.000Z", "originalFileName": "assetB.png", "originalMimeType": "image/png", "originalPath": "/test-assets/temp/directoryB/assetB.png", "ownerId": "1f0621bf-b2a5-459a-8ca4-c082388bdc97", "people": Array [], "resized": true, "thumbhash": null, "type": "IMAGE", - "updatedAt": "2024-12-18T10:39:48.633Z", + "updatedAt": "2024-12-18T10:39:48.861Z", }, Object { "checksum": "hNpZqb2K/xOq4imfDL1cjDcsFUc=", "deviceAssetId": "assetA.png", "deviceId": "Library Import", "duplicateId": null, "duration": "0:00:00.00000", "fileCreatedAt": "1900-01-01T00:00:00.000Z", "fileModifiedAt": "1900-01-01T00:00:00.000Z", "hasMetadata": true, "id": "92268eaa-9c48-43d2-b7a9-ec2b07aaa348", "isArchived": false, "isFavorite": false, "isOffline": false, "isTrashed": false, "libraryId": "85346036-6e72-4291-a32f-f4e1038780af", "livePhotoVideoId": null, "localDateTime": "1900-01-01T00:00:00.000Z", "originalFileName": "assetA.png", "originalMimeType": "image/png", "originalPath": "/test-assets/temp/directoryA/assetA.png", "ownerId": "1f0621bf-b2a5-459a-8ca4-c082388bdc97", "people": Array [], "resized": true, "thumbhash": null, "type": "IMAGE", - "updatedAt": "2024-12-18T10:39:48.633Z", + "updatedAt": "2024-12-18T10:39:48.859Z", }, ], "nextPage": null, "total": 2, } ❯ src/api/specs/library.e2e-spec.ts:602:22
});

it('should set an offline asset to online if its file exists, is in an import path, and not covered by an exclusion pattern', async () => {
utils.createImageFile(`${testAssetDir}/temp/offline/offline.png`);

const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp/offline`],
});

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');

const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });

utils.renameImageFile(`${testAssetDir}/temp/offline/offline.png`, `${testAssetDir}/temp/offline.png`);

{
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);
}

await utils.waitForQueueFinish(admin.accessToken, 'library');

const offlineAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);
expect(offlineAsset.isTrashed).toBe(true);
expect(offlineAsset.originalPath).toBe(`${testAssetDirInternal}/temp/offline/offline.png`);
expect(offlineAsset.isOffline).toBe(true);

{
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id, withDeleted: true });
expect(assets.count).toBe(1);
}

utils.renameImageFile(`${testAssetDir}/temp/offline.png`, `${testAssetDir}/temp/offline/offline.png`);

{
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);
}

await utils.waitForQueueFinish(admin.accessToken, 'library');

const backOnlineAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(backOnlineAsset.isTrashed).toBe(false);
expect(backOnlineAsset.originalPath).toBe(`${testAssetDirInternal}/temp/offline/offline.png`);
expect(backOnlineAsset.isOffline).toBe(false);

{
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });
expect(assets.count).toBe(1);
}
});

it('should not set an offline asset to online if its file exists, is not covered by an exclusion pattern, but is outside of all import paths', async () => {
utils.createImageFile(`${testAssetDir}/temp/offline/offline.png`);

const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp/offline`],
});

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');

const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });

utils.renameImageFile(`${testAssetDir}/temp/offline/offline.png`, `${testAssetDir}/temp/offline.png`);

{
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);
}

await utils.waitForQueueFinish(admin.accessToken, 'library');

{
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id, withDeleted: true });
expect(assets.count).toBe(1);
}

const offlineAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(offlineAsset.isTrashed).toBe(true);
expect(offlineAsset.originalPath).toBe(`${testAssetDirInternal}/temp/offline/offline.png`);
expect(offlineAsset.isOffline).toBe(true);

utils.renameImageFile(`${testAssetDir}/temp/offline.png`, `${testAssetDir}/temp/offline/offline.png`);

utils.createDirectory(`${testAssetDir}/temp/another-path/`);

await utils.updateLibrary(admin.accessToken, library.id, {
importPaths: [`${testAssetDirInternal}/temp/another-path`],
});

{
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);
}

await utils.waitForQueueFinish(admin.accessToken, 'library');

const stillOfflineAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(stillOfflineAsset.isTrashed).toBe(true);

Check failure on line 720 in e2e/src/api/specs/library.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests (Server & CLI)

src/api/specs/library.e2e-spec.ts > /libraries > POST /libraries/:id/scan > should not set an offline asset to online if its file exists, is not covered by an exclusion pattern, but is outside of all import paths

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/api/specs/library.e2e-spec.ts:720:43
expect(stillOfflineAsset.originalPath).toBe(`${testAssetDirInternal}/temp/offline/offline.png`);
expect(stillOfflineAsset.isOffline).toBe(true);

{
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id, withDeleted: true });
expect(assets.count).toBe(1);
}

utils.removeDirectory(`${testAssetDir}/temp/another-path/`);
});

it('should not set an offline asset to online if its file exists, is in an import path, but is covered by an exclusion pattern', async () => {
utils.createImageFile(`${testAssetDir}/temp/offline/offline.png`);

const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp/offline`],
});

await scan(admin.accessToken, library.id);
await utils.waitForQueueFinish(admin.accessToken, 'library');

const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });

utils.renameImageFile(`${testAssetDir}/temp/offline/offline.png`, `${testAssetDir}/temp/offline.png`);

{
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);
}

await utils.waitForQueueFinish(admin.accessToken, 'library');

{
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id, withDeleted: true });
expect(assets.count).toBe(1);
}

const offlineAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(offlineAsset.isTrashed).toBe(true);
expect(offlineAsset.originalPath).toBe(`${testAssetDirInternal}/temp/offline/offline.png`);
expect(offlineAsset.isOffline).toBe(true);

utils.renameImageFile(`${testAssetDir}/temp/offline.png`, `${testAssetDir}/temp/offline/offline.png`);

await utils.updateLibrary(admin.accessToken, library.id, { exclusionPatterns: ['**/offline/**'] });

{
const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);
}

await utils.waitForQueueFinish(admin.accessToken, 'library');

const stillOfflineAsset = await utils.getAssetInfo(admin.accessToken, assets.items[0].id);

expect(stillOfflineAsset.isTrashed).toBe(true);

Check failure on line 784 in e2e/src/api/specs/library.e2e-spec.ts

View workflow job for this annotation

GitHub Actions / End-to-End Tests (Server & CLI)

src/api/specs/library.e2e-spec.ts > /libraries > POST /libraries/:id/scan > should not set an offline asset to online if its file exists, is in an import path, but is covered by an exclusion pattern

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ src/api/specs/library.e2e-spec.ts:784:43
expect(stillOfflineAsset.originalPath).toBe(`${testAssetDirInternal}/temp/offline/offline.png`);
expect(stillOfflineAsset.isOffline).toBe(true);

{
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id, withDeleted: true });
expect(assets.count).toBe(1);
}
});
});

describe('POST /libraries/:id/validate', () => {
Expand Down
15 changes: 14 additions & 1 deletion e2e/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Permission,
PersonCreateDto,
SharedLinkCreateDto,
UpdateLibraryDto,
UserAdminCreateDto,
UserPreferencesUpdateDto,
ValidateLibraryDto,
Expand All @@ -35,14 +36,15 @@ import {
updateAlbumUser,
updateAssets,
updateConfig,
updateLibrary,
updateMyPreferences,
upsertTags,
validate,
} from '@immich/sdk';
import { BrowserContext } from '@playwright/test';
import { exec, spawn } from 'node:child_process';
import { createHash } from 'node:crypto';
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path, { dirname } from 'node:path';
import { setTimeout as setAsyncTimeout } from 'node:timers/promises';
Expand Down Expand Up @@ -392,6 +394,14 @@ export const utils = {
rmSync(path);
},

renameImageFile: (oldPath: string, newPath: string) => {
if (!existsSync(oldPath)) {
return;
}

renameSync(oldPath, newPath);
},

removeDirectory: (path: string) => {
if (!existsSync(path)) {
return;
Expand Down Expand Up @@ -444,6 +454,9 @@ export const utils = {
createLibrary: (accessToken: string, dto: CreateLibraryDto) =>
createLibrary({ createLibraryDto: dto }, { headers: asBearerAuth(accessToken) }),

updateLibrary: (accessToken: string, id: string, dto: UpdateLibraryDto) =>
updateLibrary({ id, updateLibraryDto: dto }, { headers: asBearerAuth(accessToken) }),

validateLibrary: (accessToken: string, id: string, dto: ValidateLibraryDto) =>
validate({ id, validateLibraryDto: dto }, { headers: asBearerAuth(accessToken) }),

Expand Down
2 changes: 1 addition & 1 deletion e2e/test-assets
Submodule test-assets updated 0 files
3 changes: 1 addition & 2 deletions mobile/openapi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion mobile/openapi/lib/api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions mobile/openapi/lib/api/libraries_api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions mobile/openapi/lib/api_client.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading