From d3b47dfdd78c69ea07efd72389c50530d5a0729c Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Wed, 18 Sep 2024 12:37:08 +0200
Subject: [PATCH] demonstrate subset of remote rpc api

---
 src/scripts/rpcDatapod.ts | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 src/scripts/rpcDatapod.ts

diff --git a/src/scripts/rpcDatapod.ts b/src/scripts/rpcDatapod.ts
new file mode 100644
index 0000000..6933d6e
--- /dev/null
+++ b/src/scripts/rpcDatapod.ts
@@ -0,0 +1,32 @@
+import { create } from 'kubo-rpc-client'
+import type { KuboRPCClient } from 'kubo-rpc-client'
+import { Agent } from 'http'
+import { EMPTY_NODE_CID } from '../consts'
+
+// this script demonstrate the use of a subset of the API served through nginx
+// allows to use a remote node without admin privilege on it
+
+const KUBO_RPC = 'https://rpc.datapod.gyroi.de/'
+
+const kubo: KuboRPCClient = create({
+  url: new URL(KUBO_RPC),
+  agent: new Agent({
+    maxSockets: 50000
+  })
+})
+
+async function doit() {
+  // getting works
+  const n = (await kubo.dag.get(EMPTY_NODE_CID)).value
+  console.log(n)
+  // putting works
+  const obj = { kind: 123456, value: "this is a text I'm going to publish", something: [1, 2, 3] }
+  const cid = await kubo.dag.put(obj)
+  console.log(cid)
+  // pubsub publish works
+  const enc = new TextEncoder()
+  await kubo.pubsub.publish('ddd', enc.encode("hello, I'm there\n"))
+  console.log('published ;)')
+}
+
+doit()
-- 
GitLab