mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
hex regex typo fix
This commit is contained in:
parent
6691908fc4
commit
4f8ebb95f3
2 changed files with 6 additions and 6 deletions
|
|
@ -39,7 +39,7 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
|
|||
};
|
||||
try {
|
||||
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 handle = await getHandle(params.acct, profile);
|
||||
res.type = 'profile';
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ function truncate(s: string, len: number, ellipsis = '…') {
|
|||
export async function getHandle(id: string, acc?: ProfileInfo) {
|
||||
let handle: string | undefined = '';
|
||||
|
||||
const handlePubkey = async (pubkey: string) => {
|
||||
const pubkeyToHandle = async (pubkey: string) => {
|
||||
const fallback = nip19.npubEncode(pubkey).slice(0, 8);
|
||||
try {
|
||||
const author = acc || await fetchProfile({ pubkey });
|
||||
|
|
@ -120,14 +120,14 @@ export async function getHandle(id: string, acc?: ProfileInfo) {
|
|||
return fallback;
|
||||
};
|
||||
|
||||
if (/[a-z0-9]{64}/.test(id)) {
|
||||
handle = await handlePubkey(id);
|
||||
if (/[a-f0-9]{64}/.test(id)) {
|
||||
handle = await pubkeyToHandle(id);
|
||||
} else if (n.bech32().safeParse(id).success) {
|
||||
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')) {
|
||||
const decoded = nip19.decode(id as `nprofile1${string}`).data.pubkey;
|
||||
handle = await handlePubkey(decoded);
|
||||
handle = await pubkeyToHandle(decoded);
|
||||
} else {
|
||||
throw new Error('non-nprofile or -npub bech32 passed to getHandle()');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue