Files
eranos/src/lib/imeta.ts
T
Alex Gleason b067b2da3e fix: render webxdc in compose preview by extracting shared NoteMedia component
The composer preview tab was missing webxdc embeds because it manually
rendered only videos and audio, while webxdc rendering lived exclusively
inside NoteCard. Extract NoteMedia into a shared component and
ImetaEntry/parseImetaMap into a shared utility, then wire them into the
ComposeBox preview with proper imeta tag generation on the mock event.
2026-03-03 11:28:19 -06:00

44 lines
1.3 KiB
TypeScript

/** Parsed imeta entry from NIP-94 tags. */
export interface ImetaEntry {
url: string;
thumbnail?: string;
mime?: string;
/** Summary text (used as webxdc app name for webxdc attachments). */
summary?: string;
/** Webxdc session UUID — present when the attachment is a stateful webxdc app. */
webxdc?: string;
/** Pixel dimensions from NIP-94 `dim` tag, e.g. "1280x720". */
dim?: string;
/** Blurhash placeholder from NIP-94 `blurhash` tag. */
blurhash?: string;
}
/** Parse all imeta tags into a map keyed by URL. Works for any event kind. */
export function parseImetaMap(tags: string[][]): Map<string, ImetaEntry> {
const map = new Map<string, ImetaEntry>();
for (const tag of tags) {
if (tag[0] !== 'imeta') continue;
const entry: Record<string, string> = {};
for (let i = 1; i < tag.length; i++) {
const part = tag[i];
const spaceIdx = part.indexOf(' ');
if (spaceIdx === -1) continue;
const key = part.slice(0, spaceIdx);
const value = part.slice(spaceIdx + 1);
entry[key] = value;
}
if (entry.url) {
map.set(entry.url, {
url: entry.url,
thumbnail: entry.image,
mime: entry.m,
summary: entry.summary,
webxdc: entry.webxdc,
dim: entry.dim,
blurhash: entry.blurhash,
});
}
}
return map;
}