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 { 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)
|
||||||
|
@ -104,7 +103,7 @@ const accountSearchController: AppController = async (c) => {
|
||||||
if ((results.length < 1) && query.match(/npub1\w+/)) {
|
if ((results.length < 1) && query.match(/npub1\w+/)) {
|
||||||
const possibleNpub = query;
|
const possibleNpub = query;
|
||||||
try {
|
try {
|
||||||
const npubHex = decode(possibleNpub);
|
const npubHex = nip19.decode(possibleNpub);
|
||||||
return c.json([await accountFromPubkey(String(npubHex.data))]);
|
return c.json([await accountFromPubkey(String(npubHex.data))]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { nip05Cache } from '@/utils/nip05.ts';
|
||||||
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.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';
|
|
||||||
|
|
||||||
/** Matches NIP-05 names with or without an @ in front. */
|
/** Matches NIP-05 names with or without an @ in front. */
|
||||||
const ACCT_REGEX = /^@?(?:([\w.+-]+)@)?([\w.-]+)$/;
|
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+/))) {
|
if ((result.data.type === 'accounts') && (accounts.length < 1) && (result.data.q.match(/npub1\w+/))) {
|
||||||
const possibleNpub = result.data.q;
|
const possibleNpub = result.data.q;
|
||||||
try {
|
try {
|
||||||
const npubHex = decode(possibleNpub);
|
const npubHex = nip19.decode(possibleNpub);
|
||||||
accounts.push(await accountFromPubkey(String(npubHex.data)));
|
accounts.push(await accountFromPubkey(String(npubHex.data)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -70,8 +69,8 @@ const searchController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.json({
|
return c.json({
|
||||||
accounts: accounts,
|
accounts,
|
||||||
statuses: statuses,
|
statuses,
|
||||||
hashtags: [],
|
hashtags: [],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue