From 0a858371bfa7a8375aa499b43c4f29f2c8478617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Sat, 18 Apr 2026 05:28:44 +0200 Subject: [PATCH] publish(task 9): blossom-server-liste-loader (kind:10063) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parseBlossomServers(ev) extrahiert "server"-tag-urls, normalisiert trailing-slash. loadBlossomServers(bootstrapRelay, pubkey) fragt kind:10063 via applesauce-relay. 3 tests grĂ¼n. Co-Authored-By: Claude Opus 4.6 (1M context) --- publish/src/core/blossom-list.ts | 22 ++++++++++++++++++++++ publish/tests/blossom-list_test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 publish/src/core/blossom-list.ts create mode 100644 publish/tests/blossom-list_test.ts diff --git a/publish/src/core/blossom-list.ts b/publish/src/core/blossom-list.ts new file mode 100644 index 0000000..8edc156 --- /dev/null +++ b/publish/src/core/blossom-list.ts @@ -0,0 +1,22 @@ +import { Relay } from 'applesauce-relay' +import { firstValueFrom, timeout } from 'rxjs' +import type { SignedEvent } from './relays.ts' + +export function parseBlossomServers(ev: { tags: string[][] }): string[] { + return ev.tags + .filter((t) => t[0] === 'server' && t[1]) + .map((t) => t[1].replace(/\/$/, '')) +} + +export async function loadBlossomServers( + bootstrapRelay: string, + authorPubkeyHex: string, +): Promise { + const relay = new Relay(bootstrapRelay) + const ev = await firstValueFrom( + relay + .request({ kinds: [10063], authors: [authorPubkeyHex], limit: 1 }) + .pipe(timeout({ first: 10_000 })), + ) as SignedEvent + return parseBlossomServers(ev) +} diff --git a/publish/tests/blossom-list_test.ts b/publish/tests/blossom-list_test.ts new file mode 100644 index 0000000..ccbd2e3 --- /dev/null +++ b/publish/tests/blossom-list_test.ts @@ -0,0 +1,28 @@ +import { assertEquals } from '@std/assert' +import { parseBlossomServers } from '../src/core/blossom-list.ts' + +Deno.test('parseBlossomServers: extrahiert server-urls in reihenfolge', () => { + const ev = { + kind: 10063, + tags: [ + ['server', 'https://a.example'], + ['server', 'https://b.example'], + ['other', 'ignored'], + ], + } + assertEquals(parseBlossomServers(ev), ['https://a.example', 'https://b.example']) +}) + +Deno.test('parseBlossomServers: leere liste bei fehlenden tags', () => { + assertEquals(parseBlossomServers({ tags: [] }), []) +}) + +Deno.test('parseBlossomServers: entfernt trailing-slash normalisierung', () => { + const ev = { + kind: 10063, + tags: [ + ['server', 'https://a.example/'], + ], + } + assertEquals(parseBlossomServers(ev), ['https://a.example']) +})