refactor: decode pubkey with right import in search account
This commit is contained in:
parent
49f06869a3
commit
12b030c8aa
|
@ -16,7 +16,6 @@ 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)
|
||||
|
@ -104,7 +103,7 @@ const accountSearchController: AppController = async (c) => {
|
|||
if ((results.length < 1) && query.match(/npub1\w+/)) {
|
||||
const possibleNpub = query;
|
||||
try {
|
||||
const npubHex = decode(possibleNpub);
|
||||
const npubHex = nip19.decode(possibleNpub);
|
||||
return c.json([await accountFromPubkey(String(npubHex.data))]);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
|
|
@ -9,7 +9,6 @@ import { nip05Cache } from '@/utils/nip05.ts';
|
|||
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { decode } from 'npm:nostr-tools@^2.5.0/nip19';
|
||||
|
||||
/** Matches NIP-05 names with or without an @ in front. */
|
||||
const ACCT_REGEX = /^@?(?:([\w.+-]+)@)?([\w.-]+)$/;
|
||||
|
@ -62,7 +61,7 @@ const searchController: AppController = async (c) => {
|
|||
if ((result.data.type === 'accounts') && (accounts.length < 1) && (result.data.q.match(/npub1\w+/))) {
|
||||
const possibleNpub = result.data.q;
|
||||
try {
|
||||
const npubHex = decode(possibleNpub);
|
||||
const npubHex = nip19.decode(possibleNpub);
|
||||
accounts.push(await accountFromPubkey(String(npubHex.data)));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
@ -70,8 +69,8 @@ const searchController: AppController = async (c) => {
|
|||
}
|
||||
|
||||
return c.json({
|
||||
accounts: accounts,
|
||||
statuses: statuses,
|
||||
accounts,
|
||||
statuses,
|
||||
hashtags: [],
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue