Can embed any file in a PNG/WebM/GIF/JPEG and upload it to a third-party host through 4chan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3 KiB

2 years ago
<script lang="ts">
import { fileTypeFromBuffer } from 'file-type'
import { Buffer } from 'buffer'
import type Embedding from './Embedding.svelte'
import type Embeddings from './Embeddings.svelte'
import type { EmbeddedFile } from '../main'
import { settings } from '../stores'
2 years ago
export let id = ''
export let files: EmbeddedFile[]
export let inst: Embedding | Embeddings
let isVideo = false
inst.$on('fileinfo', (info) => {
isVideo = isVideo || info.detail.type.mime.startsWith('video/')
})
2 years ago
let visible = false
function reveal() {
visible = !visible
document.dispatchEvent(new CustomEvent('reveal', { detail: { id } }))
}
const isNotChrome = !navigator.userAgent.includes('Chrome/')
async function downloadFile(file: EmbeddedFile) {
const a = document.createElement('a') as HTMLAnchorElement
document.body.appendChild(a)
a.style.display = 'none'
let url: string
if (typeof file.data != "string") {
const thumb = (Buffer.isBuffer(file.data) ? file.data : await file.data())
const type = await fileTypeFromBuffer(thumb)
url = URL.createObjectURL(new Blob([thumb], { type: type?.mime }))
} else
url = file.data;
a.href = url
a.download = file.filename
a.click()
window.URL.revokeObjectURL(url)
}
2 years ago
</script>
{#if $settings.eye}
<span
on:click={reveal}
class:fa-eye={!visible}
class:fa-eye-slash={visible}
class="fa clickable"
/>
{/if}
{#each files as file}
<span
title={file.filename}
on:click={() => downloadFile(file)}
class="fa fa-download clickable"
/>
{#if file.source}
<!-- svelte-ignore a11y-missing-content -->
<a href={file.source} target="_blank" class="clickable">Source</a>
{/if}
{#if file.page}
<!-- svelte-ignore a11y-missing-content -->
<a href={file.page.url} target="_blank" class="clickable"
>{file.page.title}</a
>
{/if}
{#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">[PEE contract]</a
>
{/if}
{/each}
2 years ago
<style scoped>
.clickable {
cursor: pointer;
2 years ago
margin-left: 5px;
2 years ago
}
.clickable:hover {
text-shadow: 0 0 4px palevioletred;
}
</style>