Skip to content

Commit

Permalink
fixed not deleting assets if album isn't specified
Browse files Browse the repository at this point in the history
  • Loading branch information
mertalev committed Feb 19, 2024
1 parent 7c99763 commit f2704a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cli/src/commands/upload.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class UploadCommand extends BaseCommand {

const assetsToCheck = files.map((path) => new Asset(path));

const { newAssets, duplicateAssets, rejectedAssets } = await this.checkAssets(
const { newAssets, duplicateAssets } = await this.checkAssets(
assetsToCheck,
options.concurrency ?? 4,
);
Expand All @@ -147,17 +147,15 @@ export class UploadCommand extends BaseCommand {
console.log(`${messageStart} uploaded ${newAssets.length} assets (${byteSize(totalSizeUploaded)})`);
}

if (!options.album && !options.albumName) {
return;
if (options.album || options.albumName) {
const { createdAlbumCount, updatedAssetCount } = await this.updateAlbums(
[...newAssets, ...duplicateAssets],
options,
);
console.log(`${messageStart} created ${createdAlbumCount} new albums`);
console.log(`${messageStart} updated ${updatedAssetCount} assets`);
}

const { createdAlbumCount, updatedAssetCount } = await this.updateAlbums(
[...newAssets, ...duplicateAssets, ...rejectedAssets],
options,
);
console.log(`${messageStart} created ${createdAlbumCount} new albums`);
console.log(`${messageStart} updated ${updatedAssetCount} assets`);

if (!options.delete) {
return;
}
Expand Down Expand Up @@ -390,12 +388,12 @@ export class UploadCommand extends BaseCommand {
asset.id = check.assetId;
}

if (check.action === 'reject') {
responses.push({ asset, status: CheckResponseStatus.REJECT });
if (check.action === 'accept') {
responses.push({ asset, status: CheckResponseStatus.ACCEPT });
} else if (check.reason === 'duplicate') {
responses.push({ asset, status: CheckResponseStatus.DUPLICATE });
} else {
responses.push({ asset, status: CheckResponseStatus.ACCEPT });
responses.push({ asset, status: CheckResponseStatus.REJECT });
}
}

Expand Down
17 changes: 17 additions & 0 deletions cli/test/e2e/upload.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IMMICH_TEST_ASSET_PATH, restoreTempFolder, testApp } from '@test-utils';
import { mkdir, readdir, rm, symlink } from 'node:fs/promises';
import { ImmichApi } from 'src/services/api.service';
import { CLI_BASE_OPTIONS, setup, spyOnConsole } from 'test/cli-test-utils';
import { UploadCommand } from '../../src/commands/upload.command';
Expand Down Expand Up @@ -76,4 +77,20 @@ describe(`upload (e2e)`, () => {
const testAlbum = albums[0];
expect(testAlbum.albumName).toEqual('testAlbum');
});

it('should delete local files if specified', async () => {
await mkdir(`/tmp/albums/nature`, { recursive: true })
const filesToLink = await readdir(`${IMMICH_TEST_ASSET_PATH}/albums/nature`);
for (const file of filesToLink) {
await symlink(`${IMMICH_TEST_ASSET_PATH}/albums/nature/${file}`, `/tmp/albums/nature/${file}`);
}

await new UploadCommand(CLI_BASE_OPTIONS).run(['/tmp/albums/nature'], { delete: true });

const files = await readdir(`/tmp/albums/nature`);
await rm(`/tmp/albums/nature`, { recursive: true });
const assets = await api.getAllAssets();
expect(files).toEqual([]);
expect(assets.length).toBeGreaterThan(4);
});
});

0 comments on commit f2704a9

Please sign in to comment.