flotilla/src/app/components/ContentLinkBlockImage.svelte

40 lines
1.1 KiB
Svelte
Raw Normal View History

2025-04-28 22:46:48 +00:00
<script lang="ts">
2025-06-03 17:41:38 +00:00
import {onMount, onDestroy} from "svelte"
2025-06-02 23:33:55 +00:00
import {getTags, getTagValue, tagsFromIMeta} from "@welshman/util"
2025-06-03 17:41:38 +00:00
import {decryptFile} from "@welshman/editor"
2025-04-28 22:46:48 +00:00
import {imgproxy} from "@app/state"
const {value, event, ...props} = $props()
2025-04-28 22:46:48 +00:00
const url = value.url.toString()
2025-06-03 17:41:38 +00:00
const meta =
getTags("imeta", event.tags)
.map(tagsFromIMeta)
.find(meta => getTagValue("url", meta) === url) || []
const key = getTagValue("decryption-key", meta)
const nonce = getTagValue("decryption-nonce", meta)
const encryptionAlgorithm = getTagValue("encryption-algorithm", meta)
let src = $state(imgproxy(url))
onMount(async () => {
if (encryptionAlgorithm === "aes-gcm" && key && nonce) {
const response = await fetch(url)
if (response.ok) {
const ciphertext = new Uint8Array(await response.arrayBuffer())
const decryptedData = decryptFile({ciphertext, key, nonce, encryptionAlgorithm})
src = URL.createObjectURL(new Blob([new Uint8Array(decryptedData)]))
}
}
})
onDestroy(() => {
URL.revokeObjectURL(src)
})
2025-04-28 22:46:48 +00:00
</script>
2025-06-02 23:33:55 +00:00
<img alt="" {src} {...props} />