feat: render account from pubkey if no kind 0 exists - /v1/accounts/search
This commit is contained in:
parent
1c126425ac
commit
60a1ff7adc
|
@ -16,6 +16,7 @@ import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||||
import { renderRelationship } from '@/views/mastodon/relationships.ts';
|
import { renderRelationship } from '@/views/mastodon/relationships.ts';
|
||||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
|
import { decode } from 'npm:nostr-tools@^2.5.0/nip19';
|
||||||
|
|
||||||
const usernameSchema = z
|
const usernameSchema = z
|
||||||
.string().min(1).max(30)
|
.string().min(1).max(30)
|
||||||
|
@ -100,6 +101,17 @@ const accountSearchController: AppController = async (c) => {
|
||||||
signal: c.req.raw.signal,
|
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)));
|
const accounts = await Promise.all(results.map((event) => renderAccount(event)));
|
||||||
return c.json(accounts);
|
return c.json(accounts);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue