2022-01-05 20:50:44 +00:00
|
|
|
<script lang="ts">
|
2022-01-05 22:20:20 +00:00
|
|
|
import { fileTypeFromBuffer } from 'file-type';
|
2022-01-07 04:43:28 +00:00
|
|
|
import type Embedding from './Embedding.svelte';
|
2022-01-09 06:39:02 +00:00
|
|
|
import type Embeddings from './Embeddings.svelte';
|
2022-01-05 22:20:20 +00:00
|
|
|
|
2022-01-11 12:10:21 +00:00
|
|
|
import { EmbeddedFile, EMBED_TYPES } from './main';
|
2022-01-05 22:20:20 +00:00
|
|
|
|
2022-01-05 20:50:44 +00:00
|
|
|
import { settings } from './stores'
|
|
|
|
|
|
|
|
export let id = ''
|
2022-01-09 06:39:02 +00:00
|
|
|
export let files: EmbeddedFile[];
|
|
|
|
export let inst: Embedding | Embeddings;
|
2022-01-07 04:43:28 +00:00
|
|
|
|
|
|
|
let isVideo = false
|
|
|
|
|
|
|
|
inst.$on("fileinfo", (info) => {
|
2022-01-09 15:35:15 +00:00
|
|
|
isVideo = isVideo || info.detail.type.mime.startsWith('video/');
|
2022-01-07 04:43:28 +00:00
|
|
|
})
|
2022-01-05 22:20:20 +00:00
|
|
|
|
2022-01-05 20:50:44 +00:00
|
|
|
let visible = false
|
|
|
|
function reveal() {
|
|
|
|
visible = !visible
|
|
|
|
document.dispatchEvent(new CustomEvent('reveal', { detail: { id } }))
|
|
|
|
}
|
2022-01-07 04:43:28 +00:00
|
|
|
const isNotChrome = !navigator.userAgent.includes("Chrome/");
|
2022-01-05 22:20:20 +00:00
|
|
|
|
2022-01-09 06:39:02 +00:00
|
|
|
async function downloadFile(file: EmbeddedFile) {
|
2022-01-05 22:20:20 +00:00
|
|
|
const a = document.createElement("a") as HTMLAnchorElement;
|
|
|
|
document.body.appendChild(a);
|
|
|
|
a.style.display = 'none';
|
|
|
|
const thumb = Buffer.isBuffer(file.data) ? file.data : await file.data();
|
|
|
|
const type = await fileTypeFromBuffer(thumb);
|
|
|
|
const url = URL.createObjectURL(new Blob([thumb], { type: type?.mime }))
|
|
|
|
a.href = url;
|
|
|
|
a.download = file.filename;
|
|
|
|
a.click();
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
}
|
2022-01-05 20:50:44 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if $settings.eye}
|
|
|
|
<span
|
|
|
|
on:click={reveal}
|
|
|
|
class:fa-eye={!visible}
|
|
|
|
class:fa-eye-slash={visible}
|
|
|
|
class="fa clickable"
|
|
|
|
/>
|
|
|
|
{/if}
|
2022-01-09 06:39:02 +00:00
|
|
|
{#each files as file}
|
2022-01-07 04:43:28 +00:00
|
|
|
<span
|
|
|
|
title={file.filename}
|
2022-01-09 06:39:02 +00:00
|
|
|
on:click={() => downloadFile(file)}
|
2022-01-07 04:43:28 +00:00
|
|
|
class="fa fa-download clickable"
|
2022-01-11 13:57:12 +00:00
|
|
|
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
|
|
|
|
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
|
2022-01-11 12:10:21 +00:00
|
|
|
class:hasblack={file?.isBlacklisted === true}
|
|
|
|
/> <!-- hasblack is last for it to have greater weight than hasext, to override it -->
|
|
|
|
|
2022-01-08 07:29:19 +00:00
|
|
|
{#if file.source}
|
|
|
|
<!-- svelte-ignore a11y-missing-content -->
|
|
|
|
<a
|
|
|
|
href={file.source}
|
|
|
|
target="_blank"
|
|
|
|
class="clickable"
|
2022-01-11 13:57:12 +00:00
|
|
|
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
|
|
|
|
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
|
2022-01-11 13:36:00 +00:00
|
|
|
class:hasblack={file?.isBlacklisted === true}
|
2022-01-08 07:29:19 +00:00
|
|
|
>Source</a>
|
|
|
|
{/if}
|
|
|
|
{#if file.page}
|
|
|
|
<!-- svelte-ignore a11y-missing-content -->
|
|
|
|
<a
|
|
|
|
href={file.page.url}
|
|
|
|
target="_blank"
|
|
|
|
class="clickable"
|
2022-01-11 13:57:12 +00:00
|
|
|
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
|
|
|
|
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
|
2022-01-11 13:36:00 +00:00
|
|
|
class:hasblack={file?.isBlacklisted === true}
|
2022-01-08 07:29:19 +00:00
|
|
|
>{file.page.title}</a>
|
|
|
|
{/if}
|
2022-01-07 04:43:28 +00:00
|
|
|
{#if isNotChrome && isVideo}
|
|
|
|
<!-- svelte-ignore a11y-missing-attribute -->
|
|
|
|
<a on:click={(ev) => {
|
|
|
|
inst.bepis(ev);
|
|
|
|
}} alt="By clicking this you agree to stay hydrated"
|
|
|
|
class="clickable"
|
2022-01-11 13:57:12 +00:00
|
|
|
class:hasembed={file?.embed_type === EMBED_TYPES.MEDIA_EMBED}
|
|
|
|
class:hasext={file?.embed_type === EMBED_TYPES.THIRD_EYE}
|
2022-01-11 13:36:00 +00:00
|
|
|
class:hasblack={file?.isBlacklisted === true}
|
2022-01-07 04:43:28 +00:00
|
|
|
>[PEE contract]</a
|
|
|
|
>
|
|
|
|
{/if}
|
2022-01-09 06:39:02 +00:00
|
|
|
{/each}
|
2022-01-05 20:50:44 +00:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.clickable {
|
|
|
|
cursor: pointer;
|
2022-01-11 13:36:00 +00:00
|
|
|
/* margin-left: 5px; */
|
|
|
|
|
|
|
|
/* Custom */
|
|
|
|
margin-left: 2px;
|
|
|
|
margin-right: 2px;
|
2022-01-05 20:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.clickable:hover {
|
|
|
|
text-shadow: 0 0 4px palevioletred;
|
|
|
|
}
|
2022-01-11 12:10:21 +00:00
|
|
|
.clickable.hasembed {
|
|
|
|
color: deeppink;
|
|
|
|
}
|
|
|
|
.clickable.hasext {
|
|
|
|
color: goldenrod;
|
|
|
|
}
|
|
|
|
.clickable.hasblack {
|
|
|
|
color: black;
|
|
|
|
}
|
2022-01-11 13:36:00 +00:00
|
|
|
a.clickable.hasembed {
|
|
|
|
color: deeppink !important;
|
|
|
|
}
|
|
|
|
a.clickable.hasext {
|
|
|
|
color: goldenrod !important;
|
|
|
|
}
|
|
|
|
a.clickable.hasblack {
|
|
|
|
color: black !important;
|
|
|
|
}
|
2022-01-05 20:50:44 +00:00
|
|
|
</style>
|