aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/nostr.ts26
-rw-r--r--lib/strfry.ts30
-rw-r--r--lib/utils.ts2
3 files changed, 44 insertions, 14 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts
index 90c33694..44febae3 100644
--- a/lib/nostr.ts
+++ b/lib/nostr.ts
@@ -6,7 +6,7 @@ import { fail, wait } from "$lib/utils";
import { nip19, finalizeEvent } from "nostr-tools";
import { emit } from "$lib/sockets";
import { hex } from "@scure/base";
-import { Relay as ntr } from 'nostr-tools/relay'
+import { Relay as ntr } from "nostr-tools/relay";
export const serverPubkey = hex.encode(
getPublicKey(nip19.decode(config.nostrKey).data),
@@ -24,7 +24,7 @@ export let fillPool = () => {
});
pool.on("event", async (_, sub, ev) => {
- if (!coinos && coinos.ws.readyState !== WebSocket.OPEN) return;
+ if (!coinos || coinos.ws.readyState !== WebSocket.OPEN) return;
if (timeouts[sub]) timeouts[sub].extend(ev);
try {
let content;
@@ -73,7 +73,9 @@ export let fillPool = () => {
updated: ev.created_at,
};
- await s(`user:${pubkey}`, JSON.stringify(user));
+ console.log("SAVING", pubkey);
+
+ await s(`user:${pubkey}`, user);
} else if (sub.includes("messages")) {
let pubkey = sub.split(":")[0];
await db.sAdd(`${pubkey}:messages`, ev.id);
@@ -108,11 +110,7 @@ export let fillPool = () => {
let now = () => Math.round(Date.now() / 1000);
let timeouts = {};
-export let q = async (
- sub,
- query,
- { timeout = 20000, since = 3600, eager = 200 },
-) =>
+export let q = async (sub, query, { timeout = 20000, eager = 20000 } = {}) =>
new Promise(async (r, j) => {
let start = Date.now();
let seen = [];
@@ -269,9 +267,11 @@ export async function handleZap(invoice) {
l("sending receipt");
- await Promise.allSettled(relays.map(async (url) => {
- let r = await ntr.connect(url);
- await r.publish(signed);
- r.close()
- }));
+ await Promise.allSettled(
+ relays.map(async (url) => {
+ let r = await ntr.connect(url);
+ await r.publish(signed);
+ r.close();
+ }),
+ );
}
diff --git a/lib/strfry.ts b/lib/strfry.ts
new file mode 100644
index 00000000..ebc14ed3
--- /dev/null
+++ b/lib/strfry.ts
@@ -0,0 +1,30 @@
+import { connect } from "net";
+
+export default (cmd) =>
+ new Promise((r, j) => {
+ let results = [];
+ let c = `/app/strfry ${cmd} 2>/dev/null\n`;
+ let client = connect("/sockets/ctrl", () => client.write(c));
+
+ let s = "";
+ client.on("data", (data) => {
+ s += data.toString();
+ // console.log("S", s);
+
+ try {
+ let parts = s.split("}");
+
+ for (let i = 0; i < parts.length - 1; i++) {
+ let completeJson = parts[i] + "}";
+ results.push(JSON.parse(completeJson));
+ }
+
+ s = parts[parts.length - 1];
+ } catch (err) {
+ console.error("Error parsing JSON:", err.message);
+ }
+ });
+
+ client.on("error", (e) => j(e.message));
+ client.on("close", () => r(results));
+ });
diff --git a/lib/utils.ts b/lib/utils.ts
index e79f459f..a805f343 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -71,7 +71,7 @@ export let fields = [
export let getUser = async (username) => {
if (username === "undefined") fail("invalid user");
let user = await migrate(username);
- if (user && !user.nwc) {
+ if (user && !user.anon && !user.nwc) {
user.nwc = bytesToHex(randomBytes(32));
await s(getPublicKey(user.nwc), user.id);
await s(`user:${user.id}`, user);