feat: render account from pubkey if no kind 0 exists - /v1/accounts/search

This commit is contained in:
P. Reis 2024-04-20 20:58:12 -03:00
parent 1c126425ac
commit 60a1ff7adc
1 changed files with 12 additions and 0 deletions

View File

@ -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);
};