Support multiple relays for fetching content
This commit is contained in:
parent
856b10358c
commit
453a0f14d3
@ -1,6 +1,4 @@
|
||||
PORT=8000
|
||||
BASE_URL=http://localhost:8000
|
||||
HOME_RELAY_URL=wss://nostr.kosmos.org
|
||||
RELAY_URLS=wss://nostr.kosmos.org,wss://nostr.x0f.org
|
||||
LDAP_URL=ldap://10.1.1.116:389
|
||||
LDAP_BIND_DN=uid=service,ou=kosmos.org,cn=applications,dc=kosmos,dc=org
|
||||
LDAP_PASSWORD=123456abcdef
|
||||
|
@ -17,10 +17,12 @@ try {
|
||||
log(`Could not find or parse a "users.yaml" config`, "yellow");
|
||||
}
|
||||
|
||||
const relay_urls = Deno.env.get("RELAY_URLS")?.split(",");
|
||||
|
||||
const config = {
|
||||
port: Deno.env.get("PORT") || 8000,
|
||||
base_url: Deno.env.get("BASE_URL") || `http://localhost:8000`,
|
||||
home_relay_url: Deno.env.get("HOME_RELAY_URL") || "",
|
||||
relay_urls,
|
||||
staticUsers: staticUsers,
|
||||
ldapEnabled: !!Deno.env.get("LDAP_URL"),
|
||||
ldap: {
|
||||
|
17
nostr.ts
17
nostr.ts
@ -1,4 +1,4 @@
|
||||
import { NRelay1 } from "@nostrify/nostrify";
|
||||
import { NPool, NRelay1 } from "@nostrify/nostrify";
|
||||
import config from "./config.ts";
|
||||
|
||||
export interface NEvent {
|
||||
@ -11,13 +11,18 @@ export interface NEvent {
|
||||
tags: Array<[string, string, string?]>;
|
||||
}
|
||||
|
||||
export const relay = new NRelay1(config.home_relay_url);
|
||||
const relayPool = new NPool({
|
||||
open: (url) => new NRelay1(url),
|
||||
reqRouter: async (filters) => new Map(
|
||||
config.relay_urls.map(url => [ url, filters ])
|
||||
)
|
||||
});
|
||||
|
||||
export async function fetchReplaceableEvent(
|
||||
pubkey: string,
|
||||
identifier: string,
|
||||
) {
|
||||
let events = await relay.query([{
|
||||
let events = await relayPool.query([{
|
||||
authors: [pubkey],
|
||||
kinds: [30023],
|
||||
"#d": [identifier],
|
||||
@ -27,7 +32,7 @@ export async function fetchReplaceableEvent(
|
||||
if (events.length > 0) {
|
||||
return events[0];
|
||||
} else {
|
||||
events = await relay.query([{
|
||||
events = await relayPool.query([{
|
||||
authors: [pubkey],
|
||||
kinds: [30024],
|
||||
"#d": [identifier],
|
||||
@ -39,7 +44,7 @@ export async function fetchReplaceableEvent(
|
||||
}
|
||||
|
||||
export async function fetchArticlesByAuthor(pubkey: string) {
|
||||
const events = await relay.query([{
|
||||
const events = await relayPool.query([{
|
||||
authors: [pubkey],
|
||||
kinds: [30023],
|
||||
limit: 10,
|
||||
@ -49,7 +54,7 @@ export async function fetchArticlesByAuthor(pubkey: string) {
|
||||
}
|
||||
|
||||
export async function fetchProfileEvent(pubkey: string) {
|
||||
const events = await relay.query([{
|
||||
const events = await relayPool.query([{
|
||||
authors: [pubkey],
|
||||
kinds: [0],
|
||||
limit: 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user