2023-05-16 16:13:20 +02:00
|
|
|
<script lang="ts">
|
2025-05-17 22:57:08 -04:00
|
|
|
import { shortcut } from '$lib/actions/shortcut';
|
|
|
|
|
|
2025-09-16 13:37:01 -04:00
|
|
|
import { getAssetControlContext } from '$lib/components/timeline/AssetSelectControlBar.svelte';
|
2025-05-17 22:57:08 -04:00
|
|
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { downloadArchive, downloadFile } from '$lib/utils/asset-utils';
|
2025-05-17 22:57:08 -04:00
|
|
|
import { getAssetInfo } from '@immich/sdk';
|
2025-07-28 14:16:55 -04:00
|
|
|
import { IconButton } from '@immich/ui';
|
2025-08-10 22:23:21 -04:00
|
|
|
import { mdiDownload } from '@mdi/js';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2025-05-17 22:57:08 -04:00
|
|
|
import MenuOption from '../../shared-components/context-menu/menu-option.svelte';
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
filename?: string;
|
|
|
|
|
menuItem?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { filename = 'immich.zip', menuItem = false }: Props = $props();
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const { getAssets, clearSelect } = getAssetControlContext();
|
2023-05-16 16:13:20 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleDownloadFiles = async () => {
|
2024-02-02 04:18:00 +01:00
|
|
|
const assets = [...getAssets()];
|
2023-07-01 00:50:47 -04:00
|
|
|
if (assets.length === 1) {
|
|
|
|
|
clearSelect();
|
2025-07-28 14:16:55 -04:00
|
|
|
let asset = await getAssetInfo({ ...authManager.params, id: assets[0].id });
|
2025-05-17 22:57:08 -04:00
|
|
|
await downloadFile(asset);
|
2023-07-01 00:50:47 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2023-06-30 12:24:28 -04:00
|
|
|
|
2023-07-14 21:25:13 -04:00
|
|
|
clearSelect();
|
2023-08-25 00:03:28 -04:00
|
|
|
await downloadArchive(filename, { assetIds: assets.map((asset) => asset.id) });
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2023-05-16 16:13:20 +02:00
|
|
|
</script>
|
|
|
|
|
|
2025-05-21 18:12:00 +02:00
|
|
|
<svelte:document use:shortcut={{ shortcut: { key: 'd', shift: true }, onShortcut: handleDownloadFiles }} />
|
2024-09-06 06:26:58 -07:00
|
|
|
|
2023-05-26 09:11:10 -04:00
|
|
|
{#if menuItem}
|
2025-08-10 22:23:21 -04:00
|
|
|
<MenuOption text={$t('download')} icon={mdiDownload} onClick={handleDownloadFiles} />
|
2023-05-26 09:11:10 -04:00
|
|
|
{:else}
|
2025-06-02 09:47:23 -05:00
|
|
|
<IconButton
|
|
|
|
|
shape="round"
|
|
|
|
|
color="secondary"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
aria-label={$t('download')}
|
2025-08-10 22:23:21 -04:00
|
|
|
icon={mdiDownload}
|
2025-06-02 09:47:23 -05:00
|
|
|
onclick={handleDownloadFiles}
|
|
|
|
|
/>
|
2023-05-26 09:11:10 -04:00
|
|
|
{/if}
|