Files
immich/web/src/lib/modals/SharedLinkCreateModal.svelte

106 lines
3.2 KiB
Svelte
Raw Normal View History

2025-05-09 18:59:29 +02:00
<script lang="ts">
2025-11-12 12:57:53 +01:00
import SharedLinkExpiration from '$lib/components/SharedLinkExpiration.svelte';
import { handleCreateSharedLink } from '$lib/services/shared-link.service';
import { SharedLinkType } from '@immich/sdk';
import { Button, Field, HStack, Input, Modal, ModalBody, ModalFooter, PasswordInput, Switch, Text } from '@immich/ui';
2025-05-09 18:59:29 +02:00
import { mdiLink } from '@mdi/js';
2025-11-12 12:57:53 +01:00
import { DateTime } from 'luxon';
2025-05-09 18:59:29 +02:00
import { t } from 'svelte-i18n';
interface Props {
2025-11-10 13:40:58 -05:00
onClose: (success?: boolean) => void;
2025-11-12 12:57:53 +01:00
albumId?: string;
2025-05-09 18:59:29 +02:00
assetIds?: string[];
}
2025-11-12 12:57:53 +01:00
let { onClose, albumId = $bindable(), assetIds = $bindable([]) }: Props = $props();
2025-05-09 18:59:29 +02:00
let description = $state('');
let allowDownload = $state(true);
let allowUpload = $state(false);
let showMetadata = $state(true);
let expirationOption: number = $state(0);
let password = $state('');
let slug = $state('');
2025-11-12 12:57:53 +01:00
let expiresAt = $state<string | null>(null);
2025-05-09 18:59:29 +02:00
let shareType = $derived(albumId ? SharedLinkType.Album : SharedLinkType.Individual);
$effect(() => {
if (!showMetadata) {
allowDownload = false;
}
});
2025-11-10 13:40:58 -05:00
const onCreate = async () => {
const success = await handleCreateSharedLink({
type: shareType,
albumId,
assetIds,
expiresAt: expirationOption > 0 ? DateTime.now().plus(expirationOption).toISO() : undefined,
allowUpload,
description,
password,
allowDownload,
showMetadata,
slug,
});
if (success) {
onClose(true);
2025-05-09 18:59:29 +02:00
}
};
</script>
2025-11-12 12:57:53 +01:00
<Modal title={$t('create_link_to_share')} icon={mdiLink} size="small" {onClose}>
2025-05-09 18:59:29 +02:00
<ModalBody>
{#if shareType === SharedLinkType.Album}
2025-11-12 12:57:53 +01:00
<div>{$t('album_with_link_access')}</div>
2025-05-09 18:59:29 +02:00
{/if}
{#if shareType === SharedLinkType.Individual}
2025-11-12 12:57:53 +01:00
<div>{$t('create_link_to_share_description')}</div>
2025-05-09 18:59:29 +02:00
{/if}
<div class="flex flex-col gap-4 mt-4">
<div>
<Field label={$t('custom_url')} description={$t('shared_link_custom_url_description')}>
<Input bind:value={slug} autocomplete="off" />
</Field>
{#if slug}
<Text size="tiny" color="muted" class="pt-2">/s/{encodeURIComponent(slug)}</Text>
{/if}
</div>
2025-05-09 18:59:29 +02:00
<Field label={$t('password')} description={$t('shared_link_password_description')}>
<PasswordInput bind:value={password} autocomplete="new-password" />
</Field>
<Field label={$t('description')}>
<Input bind:value={description} autocomplete="off" />
</Field>
2025-11-12 12:57:53 +01:00
<SharedLinkExpiration bind:expiresAt />
2025-05-09 18:59:29 +02:00
<Field label={$t('show_metadata')}>
<Switch bind:checked={showMetadata} />
</Field>
2025-05-09 18:59:29 +02:00
<Field label={$t('allow_public_user_to_download')} disabled={!showMetadata}>
<Switch bind:checked={allowDownload} />
</Field>
2025-05-09 18:59:29 +02:00
<Field label={$t('allow_public_user_to_upload')}>
<Switch bind:checked={allowUpload} />
</Field>
2025-05-09 18:59:29 +02:00
</div>
</ModalBody>
<ModalFooter>
2025-11-12 12:57:53 +01:00
<HStack fullWidth>
<Button color="secondary" shape="round" fullWidth onclick={() => onClose()}>{$t('cancel')}</Button>
<Button fullWidth shape="round" onclick={onCreate}>{$t('create_link')}</Button>
</HStack>
2025-05-09 18:59:29 +02:00
</ModalFooter>
</Modal>