From 1da59fb3223fe4525e14111169c4af8a1e85d33a Mon Sep 17 00:00:00 2001 From: Coracle-Bot Date: Tue, 8 Sep 2026 21:38:50 +0000 Subject: [PATCH] Resolve a link content type per url rather than per event --- src/app/components/ContentLinkBlock.svelte | 11 +++++--- .../components/ContentLinkBlockImage.svelte | 16 +++-------- src/app/components/ContentLinkInline.svelte | 5 ++-- src/app/content.ts | 27 ++++++++++++++++++- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/app/components/ContentLinkBlock.svelte b/src/app/components/ContentLinkBlock.svelte index ced41f7b..9bbf7e4a 100644 --- a/src/app/components/ContentLinkBlock.svelte +++ b/src/app/components/ContentLinkBlock.svelte @@ -16,7 +16,7 @@ diff --git a/src/app/content.ts b/src/app/content.ts index 092689db..e5f84a81 100644 --- a/src/app/content.ts +++ b/src/app/content.ts @@ -15,8 +15,11 @@ import { THREAD, ZAP_GOAL, ZAP_RECEIPT, + matchTags, + tagSpec, + tagValue, } from "@welshman/util" -import type {Filter} from "@welshman/util" +import type {Filter, TrustedEvent} from "@welshman/util" import {ENABLE_ZAPS} from "@app/env" export const IMAGE_CONTENT_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"] @@ -32,6 +35,28 @@ export const AUDIO_CONTENT_TYPES = [ "audio/flac", ] +export const getUrlTags = (url: string, event: TrustedEvent) => { + // An imeta tag packs its own tags into space-separated values, so unpack them. + const imetas = matchTags(tagSpec("imeta"), event.tags).map(([, ...values]: string[]) => + values.map(value => value.split(" ")), + ) + const imeta = imetas.find(meta => tagValue(tagSpec("url"), meta) === url) + + if (imeta) { + return imeta + } + + // A nip 17 file message describes its one file on the event itself, but an event carrying imeta + // has said all it has to say about each url, so any other link in it is described by nothing. + return imetas.length > 0 ? [] : event.tags +} + +export const getUrlContentType = (url: string, event: TrustedEvent) => { + const tags = getUrlTags(url, event) + + return tagValue(tagSpec("m"), tags) || tagValue(tagSpec("file-type"), tags) || "" +} + export const makeCommentFilter = (kinds: number[], extra: Filter = {}) => ({ kinds: [COMMENT], "#K": kinds.map(String),