forked from Cutlery/immich
only check for offline when using checkForOffline
This commit is contained in:
parent
8bb73d6f3d
commit
247429c3e4
@ -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`, {
|
await fs.promises.cp(`${IMMICH_TEST_ASSET_PATH}/albums/nature`, `${IMMICH_TEST_ASSET_TEMP_PATH}/albums/nature`, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
@ -160,7 +160,42 @@ describe(`${LibraryController.name} (e2e)`, () => {
|
|||||||
const onlineAssets = await api.assetApi.getAllAssets(server, admin.accessToken);
|
const onlineAssets = await api.assetApi.getAllAssets(server, admin.accessToken);
|
||||||
expect(onlineAssets.length).toBeGreaterThan(1);
|
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);
|
await api.libraryApi.scanLibrary(server, admin.accessToken, library.id);
|
||||||
|
|
||||||
@ -169,11 +204,52 @@ describe(`${LibraryController.name} (e2e)`, () => {
|
|||||||
expect(assets).toEqual(
|
expect(assets).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
isOffline: true,
|
isOffline: false,
|
||||||
originalFileName: 'el_torcal_rocks',
|
originalFileName: 'silver_fir',
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
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',
|
originalFileName: 'tanners_ridge',
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
@ -385,7 +461,7 @@ describe(`${LibraryController.name} (e2e)`, () => {
|
|||||||
|
|
||||||
await restoreTempFolder();
|
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)
|
const { status } = await request(server)
|
||||||
.post(`/library/${library.id}/removeOffline`)
|
.post(`/library/${library.id}/removeOffline`)
|
||||||
|
@ -699,7 +699,6 @@ export class LibraryService extends EventEmitter {
|
|||||||
|
|
||||||
this.logger.debug(`Found ${crawledAssetPaths.size} asset(s) when crawling import paths ${library.importPaths}`);
|
this.logger.debug(`Found ${crawledAssetPaths.size} asset(s) when crawling import paths ${library.importPaths}`);
|
||||||
|
|
||||||
const assetIdsToMarkOffline = [];
|
|
||||||
const assetIdsToMarkOnline = [];
|
const assetIdsToMarkOnline = [];
|
||||||
const pagination = usePagination(5000, (pagination) =>
|
const pagination = usePagination(5000, (pagination) =>
|
||||||
this.assetRepository.getLibraryAssetPaths(pagination, library.id),
|
this.assetRepository.getLibraryAssetPaths(pagination, library.id),
|
||||||
@ -707,12 +706,7 @@ export class LibraryService extends EventEmitter {
|
|||||||
|
|
||||||
for await (const page of pagination) {
|
for await (const page of pagination) {
|
||||||
for (const asset of page) {
|
for (const asset of page) {
|
||||||
const isOffline = !crawledAssetPaths.has(asset.originalPath);
|
if (asset.isOffline) {
|
||||||
if (isOffline && !asset.isOffline) {
|
|
||||||
assetIdsToMarkOffline.push(asset.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isOffline && asset.isOffline) {
|
|
||||||
assetIdsToMarkOnline.push(asset.id);
|
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) {
|
if (assetIdsToMarkOnline.length > 0) {
|
||||||
this.logger.debug(`Found ${assetIdsToMarkOnline.length} online asset(s) previously marked as offline`);
|
this.logger.debug(`Found ${assetIdsToMarkOnline.length} online asset(s) previously marked as offline`);
|
||||||
await this.assetRepository.updateAll(assetIdsToMarkOnline, { isOffline: false });
|
await this.assetRepository.updateAll(assetIdsToMarkOnline, { isOffline: false });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user