publish(task 9): blossom-server-liste-loader (kind:10063)

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) <noreply@anthropic.com>
This commit is contained in:
Jörg Lohrer 2026-04-18 05:28:44 +02:00
parent 1ec48ad1a9
commit 0a858371bf
2 changed files with 50 additions and 0 deletions

View File

@ -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<string[]> {
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)
}

View File

@ -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'])
})