|
7 | 7 | import { type OnDelete, deleteAssets } from '$lib/utils/actions';
|
8 | 8 | import DeleteAssetDialog from '../delete-asset-dialog.svelte';
|
9 | 9 | import { t } from 'svelte-i18n';
|
| 10 | + import { deleteStacks, getStack } from '@immich/sdk'; |
| 11 | +
|
| 12 | + import { handleError } from '$lib/utils/handle-error'; |
10 | 13 |
|
11 | 14 | interface Props {
|
12 | 15 | onAssetDelete: OnDelete;
|
|
34 | 37 |
|
35 | 38 | const handleDelete = async () => {
|
36 | 39 | 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 | +
|
39 | 70 | clearSelect();
|
40 | 71 | isShowConfirmation = false;
|
41 | 72 | loading = false;
|
|
0 commit comments