aboutsummaryrefslogtreecommitdiffstats
path: root/routes/events.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/events.js')
-rw-r--r--routes/events.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/routes/events.js b/routes/events.js
new file mode 100644
index 00000000..460d09a5
--- /dev/null
+++ b/routes/events.js
@@ -0,0 +1,30 @@
+import app from "$app";
+import redis from "$lib/redis";
+import { pool } from "$lib/nostr";
+import store from "$lib/store";
+import { wait } from "$lib/utils";
+
+app.get("/:pubkey/events", async (req, res) => {
+ try {
+ let { pubkey } = req.params;
+ store.fetching[pubkey] = true;
+ store.timeouts[pubkey] = setTimeout(() => (store.fetching[pubkey] = false), 500);
+
+ pool.subscribe(pubkey, {
+ limit: 500,
+ kinds: [1],
+ authors: [pubkey]
+ });
+
+ let events = [];
+ await wait(() => !store.fetching[pubkey], 10, 10);
+ for (let id of await redis.sMembers(pubkey)) {
+ events.push(JSON.parse(await redis.get(`ev:${id}`)));
+ }
+
+ res.send(events);
+ } catch (e) {
+ console.log(e);
+ res.code(500).send("problem fetching user events");
+ }
+});