- Fix unused function warnings by renaming to _unusedExtractTags - Fix type errors in nostrTagSystem.ts for includes() calls - Fix type errors in reviews.ts for filter kinds array - Fix ArrayBuffer type errors in articleEncryption.ts - Remove unused imports (DecryptionKey, decryptArticleContent, extractTagsFromEvent) - All TypeScript checks now pass without disabling any controls
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import type { Event } from 'nostr-tools'
|
|
import { nostrService } from './nostr'
|
|
import type { SimplePoolWithSub } from '@/types/nostr-tools-extended'
|
|
import type { Article } from '@/types/nostr'
|
|
import { parseArticleFromEvent } from './nostrEventParsing'
|
|
import { buildTagFilter } from './nostrTagSystem'
|
|
|
|
const RELAY_URL = process.env.NEXT_PUBLIC_NOSTR_RELAY_URL ?? 'wss://relay.damus.io'
|
|
|
|
export function getArticlesBySeries(seriesId: string, timeoutMs: number = 5000, limit: number = 100): Promise<Article[]> {
|
|
const pool = nostrService.getPool()
|
|
if (!pool) {
|
|
throw new Error('Pool not initialized')
|
|
}
|
|
const poolWithSub = pool as SimplePoolWithSub
|
|
const filters = [
|
|
{
|
|
...buildTagFilter({
|
|
type: 'publication',
|
|
seriesId,
|
|
}),
|
|
limit,
|
|
},
|
|
]
|
|
|
|
return new Promise<Article[]>((resolve) => {
|
|
const results: Article[] = []
|
|
const sub = poolWithSub.sub([RELAY_URL], filters)
|
|
let finished = false
|
|
|
|
const done = () => {
|
|
if (finished) {
|
|
return
|
|
}
|
|
finished = true
|
|
sub.unsub()
|
|
resolve(results)
|
|
}
|
|
|
|
sub.on('event', (event: Event) => {
|
|
const parsed = parseArticleFromEvent(event)
|
|
if (parsed) {
|
|
results.push(parsed)
|
|
}
|
|
})
|
|
|
|
sub.on('eose', () => done())
|
|
setTimeout(() => done(), timeoutMs).unref?.()
|
|
})
|
|
}
|