mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-01 20:54:24 +01:00
feat: render account from pubkey if no kind 0 exists - /v1/accounts/search
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user