refactor: shared link service (#23775)
parent
d5c5bdffcb
commit
0b487897a4
|
|
@ -1,9 +1,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getAssetControlContext } from '$lib/components/timeline/AssetSelectControlBar.svelte';
|
import { getAssetControlContext } from '$lib/components/timeline/AssetSelectControlBar.svelte';
|
||||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
import { handleRemoveSharedLinkAssets } from '$lib/services/shared-link.service';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { type SharedLinkResponseDto } from '@immich/sdk';
|
||||||
import { removeSharedLinkAssets, type SharedLinkResponseDto } from '@immich/sdk';
|
import { IconButton } from '@immich/ui';
|
||||||
import { IconButton, modalManager, toastManager } from '@immich/ui';
|
|
||||||
import { mdiDeleteOutline } from '@mdi/js';
|
import { mdiDeleteOutline } from '@mdi/js';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
|
||||||
|
|
@ -15,39 +14,11 @@
|
||||||
|
|
||||||
const { getAssets, clearSelect } = getAssetControlContext();
|
const { getAssets, clearSelect } = getAssetControlContext();
|
||||||
|
|
||||||
const handleRemove = async () => {
|
const handleSelect = async () => {
|
||||||
const isConfirmed = await modalManager.showDialog({
|
const assetIds = getAssets().map(({ id }) => id);
|
||||||
title: $t('remove_assets_title'),
|
const success = await handleRemoveSharedLinkAssets(sharedLink, assetIds);
|
||||||
prompt: $t('remove_assets_shared_link_confirmation', { values: { count: getAssets().length } }),
|
if (success) {
|
||||||
confirmText: $t('remove'),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isConfirmed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const results = await removeSharedLinkAssets({
|
|
||||||
...authManager.params,
|
|
||||||
id: sharedLink.id,
|
|
||||||
assetIdsDto: {
|
|
||||||
assetIds: [...getAssets()].map((asset) => asset.id),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const result of results) {
|
|
||||||
if (!result.success) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sharedLink.assets = sharedLink.assets.filter((asset) => asset.id !== result.assetId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const count = results.filter((item) => item.success).length;
|
|
||||||
toastManager.success($t('assets_removed_count', { values: { count } }));
|
|
||||||
clearSelect();
|
clearSelect();
|
||||||
} catch (error) {
|
|
||||||
handleError(error, $t('errors.unable_to_remove_assets_from_shared_link'));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -57,6 +28,6 @@
|
||||||
color="secondary"
|
color="secondary"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
aria-label={$t('remove_from_shared_link')}
|
aria-label={$t('remove_from_shared_link')}
|
||||||
onclick={handleRemove}
|
onclick={handleSelect}
|
||||||
icon={mdiDeleteOutline}
|
icon={mdiDeleteOutline}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { AppRoute } from '$lib/constants';
|
import { AppRoute } from '$lib/constants';
|
||||||
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
import QrCodeModal from '$lib/modals/QrCodeModal.svelte';
|
import QrCodeModal from '$lib/modals/QrCodeModal.svelte';
|
||||||
import { serverConfig } from '$lib/stores/server-config.store';
|
import { serverConfig } from '$lib/stores/server-config.store';
|
||||||
|
|
@ -9,6 +10,7 @@ import { getFormatter } from '$lib/utils/i18n';
|
||||||
import {
|
import {
|
||||||
createSharedLink,
|
createSharedLink,
|
||||||
removeSharedLink,
|
removeSharedLink,
|
||||||
|
removeSharedLinkAssets,
|
||||||
updateSharedLink,
|
updateSharedLink,
|
||||||
type SharedLinkCreateDto,
|
type SharedLinkCreateDto,
|
||||||
type SharedLinkEditDto,
|
type SharedLinkEditDto,
|
||||||
|
|
@ -126,6 +128,43 @@ export const handleDeleteSharedLink = async (sharedLink: SharedLinkResponseDto):
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const handleRemoveSharedLinkAssets = async (sharedLink: SharedLinkResponseDto, assetIds: string[]) => {
|
||||||
|
const $t = await getFormatter();
|
||||||
|
|
||||||
|
const success = await modalManager.showDialog({
|
||||||
|
title: $t('remove_assets_title'),
|
||||||
|
prompt: $t('remove_assets_shared_link_confirmation', { values: { count: assetIds.length } }),
|
||||||
|
confirmText: $t('remove'),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const results = await removeSharedLinkAssets({
|
||||||
|
...authManager.params,
|
||||||
|
id: sharedLink.id,
|
||||||
|
assetIdsDto: { assetIds },
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const result of results) {
|
||||||
|
if (!result.success) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sharedLink.assets = sharedLink.assets.filter((asset) => asset.id !== result.assetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const count = results.filter((item) => item.success).length;
|
||||||
|
toastManager.success($t('assets_removed_count', { values: { count } }));
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, $t('errors.unable_to_remove_assets_from_shared_link'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleShowSharedLinkQrCode = async (sharedLink: SharedLinkResponseDto) => {
|
const handleShowSharedLinkQrCode = async (sharedLink: SharedLinkResponseDto) => {
|
||||||
const $t = await getFormatter();
|
const $t = await getFormatter();
|
||||||
await modalManager.show(QrCodeModal, { title: $t('view_link'), value: asUrl(sharedLink) });
|
await modalManager.show(QrCodeModal, { title: $t('view_link'), value: asUrl(sharedLink) });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue