Skip to content

Commit 7302510

Browse files
committed
delete all assets associated with stack on asset delete
1 parent 1ba622a commit 7302510

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

web/src/lib/components/asset-viewer/actions/delete-action.svelte

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { showDeleteModal } from '$lib/stores/preferences.store';
1212
import { featureFlags } from '$lib/stores/server-config.store';
1313
import { handleError } from '$lib/utils/handle-error';
14-
import { deleteAssets, type AssetResponseDto } from '@immich/sdk';
14+
import { deleteStack, getStack, deleteAssets, type AssetResponseDto } from '@immich/sdk';
1515
import { mdiDeleteForeverOutline, mdiDeleteOutline } from '@mdi/js';
1616
import { t } from 'svelte-i18n';
1717
import type { OnAction } from './action';
@@ -41,7 +41,16 @@
4141
4242
const trashAsset = async () => {
4343
try {
44-
await deleteAssets({ assetBulkDeleteDto: { ids: [asset.id] } });
44+
if (asset.stack) {
45+
const { assets } = await getStack({ id: asset.stack.id });
46+
const assetIds = assets.map((asset) => asset.id);
47+
48+
await deleteStack({ id: asset.stack.id });
49+
await deleteAssets({ assetBulkDeleteDto: { ids: assetIds } });
50+
} else {
51+
await deleteAssets({ assetBulkDeleteDto: { ids: [asset.id] } });
52+
}
53+
4554
onAction({ type: AssetAction.TRASH, asset });
4655
4756
notificationController.show({

web/src/lib/components/photos-page/actions/delete-assets.svelte

+33-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import { type OnDelete, deleteAssets } from '$lib/utils/actions';
88
import DeleteAssetDialog from '../delete-asset-dialog.svelte';
99
import { t } from 'svelte-i18n';
10+
import { deleteStacks, getStack } from '@immich/sdk';
11+
12+
import { handleError } from '$lib/utils/handle-error';
1013
1114
interface Props {
1215
onAssetDelete: OnDelete;
@@ -34,8 +37,36 @@
3437
3538
const handleDelete = async () => {
3639
loading = true;
37-
const ids = [...getOwnedAssets()].map((a) => a.id);
38-
await deleteAssets(force, onAssetDelete, ids);
40+
const ownedAssets = [...getOwnedAssets()];
41+
42+
try {
43+
const stackIds: string[] = [];
44+
const pendingAssetIds: Array<Promise<string[]>> = [];
45+
const assetIds: string[] = [];
46+
for (const asset of ownedAssets) {
47+
let stackId = asset.stack?.id;
48+
49+
if (stackId) {
50+
stackIds.push(stackId);
51+
52+
const assetIds = getStack({ id: stackId }).then((stack) => stack.assets.map((asset) => asset.id));
53+
pendingAssetIds.push(assetIds);
54+
} else {
55+
assetIds.push(asset.id);
56+
}
57+
}
58+
59+
let fetchedAssetIds = await Promise.all(pendingAssetIds);
60+
const ids = assetIds.concat(...fetchedAssetIds.flat());
61+
62+
if (stackIds.length > 0) {
63+
await deleteStacks({ bulkIdsDto: { ids: stackIds } });
64+
}
65+
await deleteAssets(force, onAssetDelete, ids);
66+
} catch (error) {
67+
handleError(error, $t('errors.unable_to_delete_assets'));
68+
}
69+
3970
clearSelect();
4071
isShowConfirmation = false;
4172
loading = false;

0 commit comments

Comments
 (0)