diff options
| author | Adam Soltys <[email protected]> | 2025-01-21 23:28:00 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-21 23:28:00 -0800 |
| commit | 9662c2754834599a1074d12565279674c20af467 (patch) | |
| tree | 1d77aaedf19b035378236305af582c903e025467 /lib/strfry.ts | |
| parent | eb4e16b5599e67a65962db2a07629dfdcdda57dc (diff) | |
| download | coinos-server-9662c2754834599a1074d12565279674c20af467.tar.gz coinos-server-9662c2754834599a1074d12565279674c20af467.zip | |
notes and stuff
Diffstat (limited to 'lib/strfry.ts')
| -rw-r--r-- | lib/strfry.ts | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/lib/strfry.ts b/lib/strfry.ts index 231e3533..926ca429 100644 --- a/lib/strfry.ts +++ b/lib/strfry.ts @@ -1,9 +1,10 @@ import { randomUUID } from "crypto"; import { connect, createServer } from "net"; +import type { Event } from "nostr-tools"; -const exec = async (cmd) => +const exec = async (cmd: string, data = ""): Promise<Event[]> => new Promise((resolve, reject) => { - const c = `/app/strfry ${cmd} 2>/dev/null`; + const c = `${cmd} 2>/dev/null`; const id = randomUUID(); const resultSocketPath = `/sockets/result_${id}`; @@ -11,8 +12,8 @@ const exec = async (cmd) => let resultBuffer = ""; const results = []; - socket.on("data", (data) => { - resultBuffer += data.toString(); + socket.on("data", (chunk) => { + resultBuffer += chunk.toString(); const parts = resultBuffer.split("\n"); for (let i = 0; i < parts.length - 1; i++) { @@ -20,7 +21,7 @@ const exec = async (cmd) => const parsedObject = JSON.parse(parts[i]); results.push(parsedObject); } catch (e) { - console.error(parts[i]); + console.error("Failed to parse:", parts[i]); } } @@ -38,7 +39,8 @@ const exec = async (cmd) => resultServer.listen(resultSocketPath, () => { const controlClient = connect("/sockets/ctrl", () => { - const message = `${resultSocketPath} ${c}\n`; + // Send the command and data payload + const message = `${resultSocketPath} ${c}\n${data}\n`; controlClient.write(message); controlClient.end(); }); @@ -53,7 +55,26 @@ const exec = async (cmd) => }); }); -export const count = (f) => exec(`scan --count '${JSON.stringify(f)}'\n`); -export const scan = (f) => exec(`scan '${JSON.stringify(f)}'\n`); +// const filter2params = (f) => { +// let r = ""; +// +// const { limit, since, until } = f; +// +// if (limit) r += `-l ${limit} `; +// if (since) r += `-s ${since} `; +// if (until) r += `-u ${until} `; +// +// for (const k of f.kinds || []) r += `-k ${k} `; +// for (const a of f.authors || []) r += `-a ${a} `; +// for (const e of f["#e"] || []) r += `-e ${e} `; +// for (const p of f["#p"] || []) r += `-p ${p} `; +// +// return r; +// }; + +export const load = (data) => exec(`echo '${data}' | /app/strfry import --no-verify\n`); +export const count = (f) => + exec(`/app/strfry scan --count '${JSON.stringify(f)}'\n`); +export const scan = (f) => exec(`/app/strfry scan '${JSON.stringify(f)}'\n`); export const sync = (r, f) => - exec(`sync ${r} --dir down --filter '${JSON.stringify(f)}'\n`); + exec(`/app/strfry sync ${r} --dir down --filter '${JSON.stringify(f)}'\n`); |
