From 5c5e16c42aa832531feccd8274091db3a93fd017 Mon Sep 17 00:00:00 2001 From: Darwin <77340894+charmful0x@users.noreply.github.com> Date: Mon, 24 Oct 2022 09:36:13 +0200 Subject: [PATCH] feat: address/label lookup --- src/app.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app.js b/src/app.js index cd83447..689f12b 100644 --- a/src/app.js +++ b/src/app.js @@ -30,6 +30,21 @@ app.get("/stats", async (req, res) => { res.send(jsonRes); }); +app.get("/profile/:label_addr", async (req, res) => { + res.setHeader("Content-Type", "application/json"); + + const encodedState = await getAnsState(); + const decodedState = JSON.parse(base64url.decode(encodedState)); + const label_addr = req.params.label_addr; + + const profile = + label_addr.length === 43 + ? decodedState?.res?.find((label) => label.user === label_addr) + : decodedState?.res?.find((label) => label.currentLabel === label_addr); + + res.send(profile); +}); + app.listen(port, async () => { await polling(); console.log(`listening at PORT: ${port}`);