59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import { NPool, NRelay1 } from "@nostrify/nostrify";
|
|
import config from "./config.ts";
|
|
|
|
const relayPool = new NPool({
|
|
open: (url) => new NRelay1(url),
|
|
// deno-lint-ignore require-await
|
|
reqRouter: async (filters) =>
|
|
new Map(
|
|
config.relay_urls.map((url) => [url, filters]),
|
|
),
|
|
// deno-lint-ignore require-await
|
|
eventRouter: async (_event) => [],
|
|
});
|
|
|
|
export async function fetchReplaceableEvent(
|
|
pubkey: string,
|
|
identifier: string,
|
|
) {
|
|
let events = await relayPool.query([{
|
|
authors: [pubkey],
|
|
kinds: [30023],
|
|
"#d": [identifier],
|
|
limit: 1,
|
|
}]);
|
|
|
|
if (events.length > 0) {
|
|
return events[0];
|
|
} else {
|
|
events = await relayPool.query([{
|
|
authors: [pubkey],
|
|
kinds: [30024],
|
|
"#d": [identifier],
|
|
limit: 1,
|
|
}]);
|
|
|
|
return events.length > 0 ? events[0] : null;
|
|
}
|
|
}
|
|
|
|
export async function fetchArticlesByAuthor(pubkey: string) {
|
|
const events = await relayPool.query([{
|
|
authors: [pubkey],
|
|
kinds: [30023],
|
|
limit: 10,
|
|
}]);
|
|
|
|
return events;
|
|
}
|
|
|
|
export async function fetchProfileEvent(pubkey: string) {
|
|
const events = await relayPool.query([{
|
|
authors: [pubkey],
|
|
kinds: [0],
|
|
limit: 1,
|
|
}]);
|
|
|
|
return events.length > 0 ? events[0] : null;
|
|
}
|