refactor(server, web): create shared link (#2879)

* refactor: shared links

* chore: open api

* fix: tsc error
This commit is contained in:
Jason Rasmussen 2023-06-20 21:08:43 -04:00 committed by GitHub
parent 746ca5d5ed
commit 868f629f32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 2150 additions and 2642 deletions

View file

@ -1,34 +1,65 @@
<script lang="ts">
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
import { AssetResponseDto, SharedLinkResponseDto, api } from '@api';
import { SharedLinkResponseDto, api } from '@api';
import DeleteOutline from 'svelte-material-icons/DeleteOutline.svelte';
import ConfirmDialogue from '../../shared-components/confirm-dialogue.svelte';
import { getAssetControlContext } from '../asset-select-control-bar.svelte';
import {
NotificationType,
notificationController
} from '../../shared-components/notification/notification';
import { handleError } from '../../../utils/handle-error';
export let sharedLink: SharedLinkResponseDto;
export let allAssets: AssetResponseDto[];
let removing = false;
const { getAssets, clearSelect } = getAssetControlContext();
const handleRemoveAssetsFromSharedLink = async () => {
if (window.confirm('Do you want to remove selected assets from the shared link?')) {
// TODO: Rename API method or change functionality. The assetIds passed
// in are kept instead of removed.
const assetsToKeep = allAssets.filter((a) => !getAssets().has(a));
await api.assetApi.removeAssetsFromSharedLink({
removeAssetsDto: {
assetIds: assetsToKeep.map((a) => a.id)
const handleRemove = async () => {
try {
const { data: results } = await api.sharedLinkApi.removeSharedLinkAssets({
id: sharedLink.id,
assetIdsDto: {
assetIds: Array.from(getAssets()).map((asset) => asset.id)
},
key: sharedLink?.key
key: sharedLink.key
});
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;
notificationController.show({
type: NotificationType.Info,
message: `Removed ${count} assets`
});
sharedLink.assets = assetsToKeep;
clearSelect();
} catch (error) {
handleError(error, 'Unable to remove assets from shared link');
}
};
</script>
<CircleIconButton
title="Remove from album"
on:click={handleRemoveAssetsFromSharedLink}
title="Remove from shared link"
on:click={() => (removing = true)}
logo={DeleteOutline}
/>
{#if removing}
<ConfirmDialogue
title="Remove Assets?"
prompt="Are you sure you want to remove {getAssets().size} asset(s) from this shared link?"
confirmText="Remove"
on:confirm={() => handleRemove()}
on:cancel={() => (removing = false)}
/>
{/if}