1
0
forked from Cutlery/immich

only check for offline when using checkForOffline

This commit is contained in:
Jonathan Jogenfors 2024-03-14 00:47:25 +01:00
parent 8bb73d6f3d
commit 247429c3e4
2 changed files with 83 additions and 18 deletions

View File

@ -145,7 +145,7 @@ describe(`${LibraryController.name} (e2e)`, () => {
);
});
it('should offline missing files', async () => {
it('should offline a missing files when called with checkForOffline', async () => {
await fs.promises.cp(`${IMMICH_TEST_ASSET_PATH}/albums/nature`, `${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature`, {
recursive: true,
});
@ -160,7 +160,42 @@ describe(`${LibraryController.name} (e2e)`, () => {
const onlineAssets = await api.assetApi.getAllAssets(server, admin.accessToken);
expect(onlineAssets.length).toBeGreaterThan(1);
await restoreTempFolder();
await fs.promises.rm(`${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature/silver_fir.jpg`);
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id, { checkForOffline: true });
const assets = await api.assetApi.getAllAssets(server, admin.accessToken);
expect(assets).toEqual(
expect.arrayContaining([
expect.objectContaining({
isOffline: true,
originalFileName: 'silver_fir',
}),
expect.objectContaining({
isOffline: false,
originalFileName: 'tanners_ridge',
}),
]),
);
});
it('should not offline a missing files when performing regular scan', async () => {
await fs.promises.cp(`${IMMICH_TEST_ASSET_PATH}/albums/nature`, `${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature`, {
recursive: true,
});
const library = await api.libraryApi.create(server, admin.accessToken, {
type: LibraryType.EXTERNAL,
importPaths: [`${IMMICH_TEST_ASSET_TEMP_PATH}`],
});
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id);
const onlineAssets = await api.assetApi.getAllAssets(server, admin.accessToken);
expect(onlineAssets.length).toBeGreaterThan(1);
await fs.promises.rm(`${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature/silver_fir.jpg`);
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id);
@ -169,11 +204,52 @@ describe(`${LibraryController.name} (e2e)`, () => {
expect(assets).toEqual(
expect.arrayContaining([
expect.objectContaining({
isOffline: true,
originalFileName: 'el_torcal_rocks',
isOffline: false,
originalFileName: 'silver_fir',
}),
expect.objectContaining({
isOffline: true,
isOffline: false,
originalFileName: 'tanners_ridge',
}),
]),
);
});
it('should mark a rediscovered file as back online', async () => {
await fs.promises.cp(`${IMMICH_TEST_ASSET_PATH}/albums/nature`, `${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature`, {
recursive: true,
});
const library = await api.libraryApi.create(server, admin.accessToken, {
type: LibraryType.EXTERNAL,
importPaths: [`${IMMICH_TEST_ASSET_TEMP_PATH}`],
});
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id);
const onlineAssets = await api.assetApi.getAllAssets(server, admin.accessToken);
expect(onlineAssets.length).toBeGreaterThan(1);
await fs.promises.rm(`${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature/silver_fir.jpg`);
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id, { checkForOffline: true });
await fs.promises.cp(`${IMMICH_TEST_ASSET_PATH}/albums/nature`, `${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature`, {
recursive: true,
});
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id);
const assets = await api.assetApi.getAllAssets(server, admin.accessToken);
expect(assets).toEqual(
expect.arrayContaining([
expect.objectContaining({
isOffline: false,
originalFileName: 'silver_fir',
}),
expect.objectContaining({
isOffline: false,
originalFileName: 'tanners_ridge',
}),
]),
@ -385,7 +461,7 @@ describe(`${LibraryController.name} (e2e)`, () => {
await restoreTempFolder();
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id);
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id, { checkForOffline: true });
const { status } = await request(server)
.post(`/library/${library.id}/removeOffline`)

View File

@ -699,7 +699,6 @@ export class LibraryService extends EventEmitter {
this.logger.debug(`Found ${crawledAssetPaths.size} asset(s) when crawling import paths ${library.importPaths}`);
const assetIdsToMarkOffline = [];
const assetIdsToMarkOnline = [];
const pagination = usePagination(5000, (pagination) =>
this.assetRepository.getLibraryAssetPaths(pagination, library.id),
@ -707,12 +706,7 @@ export class LibraryService extends EventEmitter {
for await (const page of pagination) {
for (const asset of page) {
const isOffline = !crawledAssetPaths.has(asset.originalPath);
if (isOffline && !asset.isOffline) {
assetIdsToMarkOffline.push(asset.id);
}
if (!isOffline && asset.isOffline) {
if (asset.isOffline) {
assetIdsToMarkOnline.push(asset.id);
}
@ -720,11 +714,6 @@ export class LibraryService extends EventEmitter {
}
}
if (assetIdsToMarkOffline.length > 0) {
this.logger.debug(`Found ${assetIdsToMarkOffline.length} offline asset(s) previously marked as online`);
await this.assetRepository.updateAll(assetIdsToMarkOffline, { isOffline: true });
}
if (assetIdsToMarkOnline.length > 0) {
this.logger.debug(`Found ${assetIdsToMarkOnline.length} online asset(s) previously marked as offline`);
await this.assetRepository.updateAll(assetIdsToMarkOnline, { isOffline: false });