Wrap sync in app

This commit is contained in:
Jon Staab
2024-09-27 09:25:15 -07:00
parent 0c2e58811b
commit b6c338376a
2 changed files with 49 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import {flatten} from '@welshman/lib'
import {push as basePush, pull as basePull, sync as baseSync, pushWithoutNegentropy, pullWithoutNegentropy, syncWithoutNegentropy} from "@welshman/net"
import type {PullOpts, PushOpts, SyncOpts} from "@welshman/net"
import {relaysByUrl} from './relays'
export const hasNegentropy = (url: string) => {
const p = relaysByUrl.get().get(url)?.profile
if (p?.supported_nips?.includes(77)) return true
if (p?.software?.includes('strfry') && !p?.version?.match(/^0\./)) return true
return false
}
export const pull = async (opts: PullOpts) =>
flatten(
await Promise.all(
opts.relays.map(relay =>
hasNegentropy(relay)
? basePull({...opts, relays: [relay]})
: pullWithoutNegentropy({...opts, relays: [relay]})
)
)
)
export const push = async (opts: PushOpts) =>
flatten(
await Promise.all(
opts.relays.map(relay =>
hasNegentropy(relay)
? basePush({...opts, relays: [relay]})
: pushWithoutNegentropy({...opts, relays: [relay]})
)
)
)
export const sync = async (opts: SyncOpts) =>
flatten(
await Promise.all(
opts.relays.map(relay =>
hasNegentropy(relay)
? baseSync({...opts, relays: [relay]})
: syncWithoutNegentropy({...opts, relays: [relay]})
)
)
)
+2
View File
@@ -16,6 +16,8 @@ export type RelayProfile = {
name?: string
pubkey?: string
contact?: string
software?: string
version?: string
description?: string
supported_nips?: number[]
limitation?: {