mirror of
https://github.com/immich-app/immich.git
synced 2025-11-18 04:23:19 -05:00
refactor: shared link service (#23775)
This commit is contained in:
parent
d5c5bdffcb
commit
0b487897a4
@ -1,9 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { getAssetControlContext } from '$lib/components/timeline/AssetSelectControlBar.svelte';
|
||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { removeSharedLinkAssets, type SharedLinkResponseDto } from '@immich/sdk';
|
||||
import { IconButton, modalManager, toastManager } from '@immich/ui';
|
||||
import { handleRemoveSharedLinkAssets } from '$lib/services/shared-link.service';
|
||||
import { type SharedLinkResponseDto } from '@immich/sdk';
|
||||
import { IconButton } from '@immich/ui';
|
||||
import { mdiDeleteOutline } from '@mdi/js';
|
||||
import { t } from 'svelte-i18n';
|
||||
|
||||
@ -15,39 +14,11 @@
|
||||
|
||||
const { getAssets, clearSelect } = getAssetControlContext();
|
||||
|
||||
const handleRemove = async () => {
|
||||
const isConfirmed = await modalManager.showDialog({
|
||||
title: $t('remove_assets_title'),
|
||||
prompt: $t('remove_assets_shared_link_confirmation', { values: { count: getAssets().length } }),
|
||||
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 } }));
|
||||
const handleSelect = async () => {
|
||||
const assetIds = getAssets().map(({ id }) => id);
|
||||
const success = await handleRemoveSharedLinkAssets(sharedLink, assetIds);
|
||||
if (success) {
|
||||
clearSelect();
|
||||
} catch (error) {
|
||||
handleError(error, $t('errors.unable_to_remove_assets_from_shared_link'));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@ -57,6 +28,6 @@
|
||||
color="secondary"
|
||||
variant="ghost"
|
||||
aria-label={$t('remove_from_shared_link')}
|
||||
onclick={handleRemove}
|
||||
onclick={handleSelect}
|
||||
icon={mdiDeleteOutline}
|
||||
/>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { AppRoute } from '$lib/constants';
|
||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||
import QrCodeModal from '$lib/modals/QrCodeModal.svelte';
|
||||
import { serverConfig } from '$lib/stores/server-config.store';
|
||||
@ -9,6 +10,7 @@ import { getFormatter } from '$lib/utils/i18n';
|
||||
import {
|
||||
createSharedLink,
|
||||
removeSharedLink,
|
||||
removeSharedLinkAssets,
|
||||
updateSharedLink,
|
||||
type SharedLinkCreateDto,
|
||||
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 $t = await getFormatter();
|
||||
await modalManager.show(QrCodeModal, { title: $t('view_link'), value: asUrl(sharedLink) });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user