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