2022-05-27 14:02:06 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { fade } from 'svelte/transition';
|
2023-02-13 16:27:15 -06:00
|
|
|
|
|
|
|
|
import { onMount } from 'svelte';
|
2022-07-16 23:52:00 -05:00
|
|
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
2022-07-10 21:41:45 -05:00
|
|
|
import { api, AssetResponseDto } from '@api';
|
2023-02-13 16:27:15 -06:00
|
|
|
import Keydown from 'svelte-keydown';
|
2022-11-16 22:04:37 +01:00
|
|
|
import {
|
|
|
|
|
notificationController,
|
|
|
|
|
NotificationType
|
|
|
|
|
} from '../shared-components/notification/notification';
|
2022-05-27 14:02:06 -05:00
|
|
|
|
2023-02-15 18:56:19 +01:00
|
|
|
export let asset: AssetResponseDto;
|
2023-01-09 14:16:08 -06:00
|
|
|
export let publicSharedKey = '';
|
2022-06-03 11:04:30 -05:00
|
|
|
|
2022-10-29 00:18:28 +02:00
|
|
|
let assetData: string;
|
|
|
|
|
|
2023-02-13 16:27:15 -06:00
|
|
|
let copyImageToClipboard: (src: string) => Promise<Blob>;
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
//Import hack :( see https://github.com/vadimkorr/svelte-carousel/issues/27#issuecomment-851022295
|
|
|
|
|
const module = await import('copy-image-clipboard');
|
|
|
|
|
copyImageToClipboard = module.copyImageToClipboard;
|
|
|
|
|
});
|
|
|
|
|
|
2022-05-27 14:02:06 -05:00
|
|
|
const loadAssetData = async () => {
|
2022-07-26 12:28:07 -05:00
|
|
|
try {
|
2023-02-15 18:56:19 +01:00
|
|
|
const { data } = await api.assetApi.serveFile(asset.id, false, true, {
|
2023-01-09 14:16:08 -06:00
|
|
|
params: {
|
|
|
|
|
key: publicSharedKey
|
|
|
|
|
},
|
2022-11-16 00:11:16 -06:00
|
|
|
responseType: 'blob'
|
|
|
|
|
});
|
2022-07-26 12:28:07 -05:00
|
|
|
|
|
|
|
|
if (!(data instanceof Blob)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-10 21:41:45 -05:00
|
|
|
|
2022-10-29 00:18:28 +02:00
|
|
|
assetData = URL.createObjectURL(data);
|
2022-07-26 12:28:07 -05:00
|
|
|
return assetData;
|
2022-09-08 17:30:49 +02:00
|
|
|
} catch {
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
2022-05-27 14:02:06 -05:00
|
|
|
};
|
2022-10-29 00:18:28 +02:00
|
|
|
|
2023-02-13 16:27:15 -06:00
|
|
|
const handleKeypress = async (keyEvent: CustomEvent<string>) => {
|
|
|
|
|
if (keyEvent.detail == 'Control-c' || keyEvent.detail == 'Meta-c') {
|
2022-11-16 22:04:37 +01:00
|
|
|
await doCopy();
|
2022-10-29 00:18:28 +02:00
|
|
|
}
|
|
|
|
|
};
|
2022-11-16 22:04:37 +01:00
|
|
|
|
|
|
|
|
export const doCopy = async () => {
|
2023-02-13 16:27:15 -06:00
|
|
|
await copyImageToClipboard(assetData);
|
|
|
|
|
notificationController.show({
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
message: 'Copied image to clipboard.',
|
|
|
|
|
timeout: 3000
|
|
|
|
|
});
|
2022-11-16 22:04:37 +01:00
|
|
|
};
|
2022-05-27 14:02:06 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-02-13 16:27:15 -06:00
|
|
|
<Keydown on:combo={handleKeypress} />
|
|
|
|
|
|
|
|
|
|
<svelte:window on:copyImage={async () => await doCopy()} />
|
2022-10-29 00:18:28 +02:00
|
|
|
|
2022-07-16 23:52:00 -05:00
|
|
|
<div
|
|
|
|
|
transition:fade={{ duration: 150 }}
|
|
|
|
|
class="flex place-items-center place-content-center h-full select-none"
|
|
|
|
|
>
|
2023-02-15 18:56:19 +01:00
|
|
|
{#await loadAssetData()}
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
{:then assetData}
|
|
|
|
|
<img
|
|
|
|
|
transition:fade={{ duration: 150 }}
|
|
|
|
|
src={assetData}
|
|
|
|
|
alt={asset.id}
|
|
|
|
|
class="object-contain h-full transition-all"
|
|
|
|
|
draggable="false"
|
|
|
|
|
/>
|
|
|
|
|
{/await}
|
2022-05-27 14:02:06 -05:00
|
|
|
</div>
|