feat: optimize profile caching mechanism

This commit is contained in:
codytseng
2025-11-02 16:59:05 +08:00
parent 6b22380d26
commit 2ae223b552
4 changed files with 50 additions and 23 deletions

View File

@@ -38,7 +38,7 @@ export function pubkeyToNpub(pubkey: string) {
}
}
export function userIdToPubkey(userId: string) {
export function userIdToPubkey(userId: string, throwOnInvalid = false): string {
if (userId.startsWith('npub1') || userId.startsWith('nprofile1')) {
try {
const { type, data } = nip19.decode(userId)
@@ -48,6 +48,9 @@ export function userIdToPubkey(userId: string) {
return data.pubkey
}
} catch (error) {
if (throwOnInvalid) {
throw new Error('Invalid id')
}
console.error('Error decoding userId:', userId, 'error:', error)
}
}