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:
parent
1ec48ad1a9
commit
0a858371bf
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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'])
|
||||
})
|
||||
Loading…
Reference in New Issue