refactor: shared link service (#23775)

This commit is contained in:
Jason Rasmussen
2025-11-10 16:17:18 -05:00
committed by GitHub
parent d5c5bdffcb
commit 0b487897a4
2 changed files with 47 additions and 37 deletions

View File

@@ -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}
/>