/** * Query authors by hash ID or pubkey (for backward compatibility) * Read only from IndexedDB - no network requests */ import type { SimplePoolWithSub } from '@/types/nostr-tools-extended' import { objectCache } from './objectCache' /** * Fetch author presentation by hash ID or pubkey * Read only from IndexedDB - no network requests * If the parameter looks like a pubkey (64 hex chars), it uses pubkey lookup * Otherwise, it uses hash ID lookup */ export async function fetchAuthorByHashId( _pool: SimplePoolWithSub, hashIdOrPubkey: string ): Promise { // Check if it's a pubkey (64 hex characters) for backward compatibility if (/^[a-f0-9]{64}$/i.test(hashIdOrPubkey)) { // Read only from IndexedDB cache const cached = await objectCache.getAuthorByPubkey(hashIdOrPubkey) if (cached) { const presentation = cached // Calculate totalSponsoring from cache const { getAuthorSponsoring } = await import('./sponsoring') presentation.totalSponsoring = await getAuthorSponsoring(presentation.pubkey) return presentation } // Not found in cache - return null (no network request) return null } // Otherwise, treat as hash ID const hashId = hashIdOrPubkey const { getCachedObjectById } = await import('./helpers/queryHelpers') const cached = await getCachedObjectById('author', hashId) if (cached) { const presentation = cached // Calculate totalSponsoring from cache const { getAuthorSponsoring } = await import('./sponsoring') presentation.totalSponsoring = await getAuthorSponsoring(presentation.pubkey) return presentation } // Not found in cache - return null (no network request) return null }