From 61cb8f4941c84f165ce6e793a12975693979c02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Tue, 11 Jun 2024 22:06:51 +0200 Subject: [PATCH] Add script for syncing notes from remote relays --- docker-compose.yml | 1 + extras/strfry/strfry-sync.ts | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 extras/strfry/strfry-sync.ts diff --git a/docker-compose.yml b/docker-compose.yml index 4b70859..d38ed17 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -113,6 +113,7 @@ services: - ./docker/strfry/strfry.conf:/etc/strfry.conf - ./extras/strfry/ldap-policy.ts:/opt/ldap-policy.ts - ./extras/strfry/strfry-policy.ts:/opt/strfry-policy.ts + - ./extras/strfry/strfry-sync.ts:/opt/strfry-sync.ts - strfry-data:/var/lib/strfry networks: - external_network diff --git a/extras/strfry/strfry-sync.ts b/extras/strfry/strfry-sync.ts new file mode 100644 index 0000000..4b24540 --- /dev/null +++ b/extras/strfry/strfry-sync.ts @@ -0,0 +1,39 @@ +import { load } from "https://deno.land/std@0.224.0/dotenv/mod.ts"; +import { Client } from 'npm:ldapts'; + +const dirname = new URL('.', import.meta.url).pathname; +await load({ envPath: `${dirname}/.env`, export: true }); + +const opts = { + url: Deno.env.get("LDAP_URL"), + bindDN: Deno.env.get("LDAP_BIND_DN"), + password: Deno.env.get("LDAP_PASSWORD"), + searchDN: Deno.env.get("LDAP_SEARCH_DN"), + relayUrl: Deno.args[0] +} + +const client = new Client({ url: opts.url }); + +try { + await client.bind(opts.bindDN, opts.password); + + const { searchEntries } = await client.search(opts.searchDN, { + filter: `(nostrKey=*)`, + attributes: ['nostrKey'] + }); + + const pubkeys = searchEntries.map(e => e.nostrKey); + const filter = JSON.stringify({ authors: pubkeys }); + + const p = Deno.run({ cmd: [ + "strfry", "sync", opts.relayUrl, + "--dir", "down", "--filter", filter + ]}); + + const result = await p.status(); + + Deno.exit(result.code); +} catch (ex) { + console.error(ex); + Deno.exit(1); +}