mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
Merge pull request #40 from dergigi/fix-500
Fix serverless import resolution for profile helpers
This commit is contained in:
@@ -4,7 +4,7 @@ import { nip19 } from 'nostr-tools'
|
|||||||
import { AddressPointer } from 'nostr-tools/nip19'
|
import { AddressPointer } from 'nostr-tools/nip19'
|
||||||
import { NostrEvent, Filter } from 'nostr-tools'
|
import { NostrEvent, Filter } from 'nostr-tools'
|
||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
import { extractProfileDisplayName } from '../src/utils/profileUtils'
|
import { extractProfileDisplayName } from '../lib/profile'
|
||||||
|
|
||||||
const { getArticleTitle, getArticleImage, getArticleSummary } = Helpers
|
const { getArticleTitle, getArticleImage, getArticleSummary } = Helpers
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ type CacheEntry = {
|
|||||||
const WEEK_MS = 7 * 24 * 60 * 60 * 1000
|
const WEEK_MS = 7 * 24 * 60 * 60 * 1000
|
||||||
const memoryCache = new Map<string, CacheEntry>()
|
const memoryCache = new Map<string, CacheEntry>()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function escapeHtml(text: string): string {
|
function escapeHtml(text: string): string {
|
||||||
return text
|
return text
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
|
|||||||
39
lib/profile.ts
Normal file
39
lib/profile.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { nip19 } from 'nostr-tools'
|
||||||
|
import type { NostrEvent } from 'nostr-tools'
|
||||||
|
|
||||||
|
export function getNpubFallbackDisplay(pubkey: string): string {
|
||||||
|
try {
|
||||||
|
const npub = nip19.npubEncode(pubkey)
|
||||||
|
return `${npub.slice(5, 12)}...`
|
||||||
|
} catch {
|
||||||
|
return `${pubkey.slice(0, 8)}...`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractProfileDisplayName(profileEvent: NostrEvent | null | undefined): string {
|
||||||
|
if (!profileEvent || profileEvent.kind !== 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const profileData = JSON.parse(profileEvent.content || '{}') as {
|
||||||
|
name?: string
|
||||||
|
display_name?: string
|
||||||
|
nip05?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profileData.name) return profileData.name
|
||||||
|
if (profileData.display_name) return profileData.display_name
|
||||||
|
if (profileData.nip05) return profileData.nip05
|
||||||
|
|
||||||
|
return getNpubFallbackDisplay(profileEvent.pubkey)
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
return getNpubFallbackDisplay(profileEvent.pubkey)
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,40 +1,2 @@
|
|||||||
import { NostrEvent } from 'nostr-tools'
|
export { extractProfileDisplayName } from '../../lib/profile'
|
||||||
import { getNpubFallbackDisplay } from './nostrUriResolver'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract display name from a profile event (kind:0) with consistent priority order
|
|
||||||
* Priority: name || display_name || nip05 || npub fallback
|
|
||||||
*
|
|
||||||
* @param profileEvent The profile event (kind:0) to extract name from
|
|
||||||
* @returns Display name string, or empty string if event is invalid
|
|
||||||
*/
|
|
||||||
export function extractProfileDisplayName(profileEvent: NostrEvent | null | undefined): string {
|
|
||||||
if (!profileEvent || profileEvent.kind !== 0) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const profileData = JSON.parse(profileEvent.content || '{}') as {
|
|
||||||
name?: string
|
|
||||||
display_name?: string
|
|
||||||
nip05?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consistent priority: name || display_name || nip05
|
|
||||||
if (profileData.name) return profileData.name
|
|
||||||
if (profileData.display_name) return profileData.display_name
|
|
||||||
if (profileData.nip05) return profileData.nip05
|
|
||||||
|
|
||||||
// Fallback to npub if no name fields
|
|
||||||
return getNpubFallbackDisplay(profileEvent.pubkey)
|
|
||||||
} catch (error) {
|
|
||||||
// If JSON parsing fails, use npub fallback
|
|
||||||
try {
|
|
||||||
return getNpubFallbackDisplay(profileEvent.pubkey)
|
|
||||||
} catch {
|
|
||||||
// If npub encoding also fails, return empty string
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user