hex regex typo fix

This commit is contained in:
Siddharth Singh 2024-08-06 00:26:04 +05:30
parent 6691908fc4
commit 4f8ebb95f3
No known key found for this signature in database
2 changed files with 6 additions and 6 deletions

View file

@ -39,7 +39,7 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
}; };
try { try {
if (params.acct && !params.statusId) { if (params.acct && !params.statusId) {
const key = /[a-z0-9]/.test(params.acct) ? 'pubkey' : 'handle'; const key = /[a-f0-9]/.test(params.acct) ? 'pubkey' : 'handle';
const profile = await fetchProfile({ [key]: params.acct }); const profile = await fetchProfile({ [key]: params.acct });
const handle = await getHandle(params.acct, profile); const handle = await getHandle(params.acct, profile);
res.type = 'profile'; res.type = 'profile';

View file

@ -108,7 +108,7 @@ function truncate(s: string, len: number, ellipsis = '…') {
export async function getHandle(id: string, acc?: ProfileInfo) { export async function getHandle(id: string, acc?: ProfileInfo) {
let handle: string | undefined = ''; let handle: string | undefined = '';
const handlePubkey = async (pubkey: string) => { const pubkeyToHandle = async (pubkey: string) => {
const fallback = nip19.npubEncode(pubkey).slice(0, 8); const fallback = nip19.npubEncode(pubkey).slice(0, 8);
try { try {
const author = acc || await fetchProfile({ pubkey }); const author = acc || await fetchProfile({ pubkey });
@ -120,14 +120,14 @@ export async function getHandle(id: string, acc?: ProfileInfo) {
return fallback; return fallback;
}; };
if (/[a-z0-9]{64}/.test(id)) { if (/[a-f0-9]{64}/.test(id)) {
handle = await handlePubkey(id); handle = await pubkeyToHandle(id);
} else if (n.bech32().safeParse(id).success) { } else if (n.bech32().safeParse(id).success) {
if (id.startsWith('npub')) { if (id.startsWith('npub')) {
handle = await handlePubkey(nip19.decode(id as `npub1${string}`).data); handle = await pubkeyToHandle(nip19.decode(id as `npub1${string}`).data);
} else if (id.startsWith('nprofile')) { } else if (id.startsWith('nprofile')) {
const decoded = nip19.decode(id as `nprofile1${string}`).data.pubkey; const decoded = nip19.decode(id as `nprofile1${string}`).data.pubkey;
handle = await handlePubkey(decoded); handle = await pubkeyToHandle(decoded);
} else { } else {
throw new Error('non-nprofile or -npub bech32 passed to getHandle()'); throw new Error('non-nprofile or -npub bech32 passed to getHandle()');
} }