blob: b2791e74feaccab3c36a0b87e6bf9e0da2ca5f67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import * as net from "net";
import type { Event } from "nostr-tools";
const controlSocketPath = "/home/bun/app/data/sockets/strsrv.sock";
export const scan = (f: object): Promise<Event[]> =>
new Promise((resolve, reject) => {
const result = [];
const client = net
.createConnection(controlSocketPath)
.on("connect", () => {
client.write(`${JSON.stringify(f)}\n`);
})
.on("data", (data) => {
result.push(data);
})
.on("end", () => {
resolve(
Buffer.concat(result)
.toString("utf8")
.split("\n")
.filter((l) => l)
.map((l) => JSON.parse(l) as Event),
);
})
.on("error", (e) => {
reject(e.message);
});
});
|