From 60a1ff7adce1e65a59c9b35aa8490bc7d27b05e8 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Sat, 20 Apr 2024 20:58:12 -0300 Subject: [PATCH] feat: render account from pubkey if no kind 0 exists - /v1/accounts/search --- src/controllers/api/accounts.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 9e250fa..c689899 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -16,6 +16,7 @@ import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { renderRelationship } from '@/views/mastodon/relationships.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; import { hydrateEvents } from '@/storages/hydrate.ts'; +import { decode } from 'npm:nostr-tools@^2.5.0/nip19'; const usernameSchema = z .string().min(1).max(30) @@ -100,6 +101,17 @@ const accountSearchController: AppController = async (c) => { signal: c.req.raw.signal, }); + if ((results.length < 1) && query.match(/npub1\w+/)) { + const possibleNpub = query; + try { + const npubHex = decode(possibleNpub); + return c.json([await accountFromPubkey(String(npubHex.data))]); + } catch (e) { + console.log(e); + return c.json([]); + } + } + const accounts = await Promise.all(results.map((event) => renderAccount(event))); return c.json(accounts); };