forked from vhaudiquet/rhema-claw
An attachment card lands inside the turn that produced it, and both passes that touch image cards scanned only the top-level rows. The pass that fetches bytes never saw the card, so it stayed a name and a size with no picture. The pass that stores the fetched object URL had the same blind spot, so even a fetch that ran dropped its result. Both now walk finished turns and the live one, through one helper that knows where cards live. Consents move to the same helper: a card whose turn already closed had the same problem. The download control was hidden for `media: "image"`, which left an image with no way out of the store when its bytes did not paint, as they never did. Every card offers it now. The anchor also joins the document for the click, which some browsers require before they follow a `download` on a blob URL.
112 lines
2.6 KiB
Vue
112 lines
2.6 KiB
Vue
<script setup lang="ts">
|
|
// The agent handing a file over: a head row naming it, the image (when
|
|
// there is one) under it, capped so a screenshot cannot take the
|
|
// stream. Every card downloads, images included: a picture the browser
|
|
// cannot paint, an SVG, or bytes that failed to fetch must still come
|
|
// out of the store.
|
|
import type { AttachmentCard } from '~/composables/useTranscript'
|
|
|
|
defineProps<{ attachment: AttachmentCard }>()
|
|
|
|
const emit = defineEmits<{
|
|
download: [id: string, name: string]
|
|
}>()
|
|
|
|
const MEDIA_GLYPHS: Record<AttachmentCard['media'], string> = {
|
|
image: '▣',
|
|
code: '⌗',
|
|
file: '▤',
|
|
}
|
|
|
|
/** B / KB / MB, one decimal past 1 KB — a card label, not precision. */
|
|
function formatBytes(size: number): string {
|
|
if (size < 1024) return `${size} B`
|
|
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`
|
|
return `${(size / (1024 * 1024)).toFixed(1)} MB`
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="attachment-card">
|
|
<div class="attachment-head">
|
|
<span
|
|
class="attachment-glyph"
|
|
aria-hidden="true"
|
|
:title="`${attachment.media} attachment`"
|
|
>{{ MEDIA_GLYPHS[attachment.media] }}</span>
|
|
<span class="attachment-name mono">{{ attachment.name }}</span>
|
|
<span class="attachment-size mono">{{ formatBytes(attachment.size) }}</span>
|
|
<button
|
|
class="ghost"
|
|
:title="`download ${attachment.name}`"
|
|
@click="emit('download', attachment.id, attachment.name)"
|
|
>
|
|
↓ download
|
|
</button>
|
|
</div>
|
|
<img
|
|
v-if="attachment.media === 'image' && attachment.url"
|
|
:src="attachment.url"
|
|
:alt="attachment.caption ?? attachment.name"
|
|
class="attachment-image"
|
|
/>
|
|
<p v-if="attachment.caption" class="attachment-caption">
|
|
{{ attachment.caption }}
|
|
</p>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.attachment-card {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
max-width: 480px;
|
|
padding: 10px 12px;
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
}
|
|
|
|
.attachment-head {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.attachment-glyph {
|
|
flex: none;
|
|
color: var(--text3);
|
|
}
|
|
|
|
.attachment-name {
|
|
flex: 1;
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
color: var(--text);
|
|
}
|
|
|
|
.attachment-size {
|
|
flex: none;
|
|
color: var(--text3);
|
|
font-size: 11px;
|
|
}
|
|
|
|
.attachment-image {
|
|
max-width: 100%;
|
|
max-height: 240px;
|
|
align-self: flex-start;
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.attachment-caption {
|
|
margin: 0;
|
|
color: var(--text3);
|
|
font-size: 12.5px;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
</style>
|