- Modified `.env.example` to reflect new API URL structure and added CDN configuration for external storage. - Updated `.gitignore` to include deployment secrets and certificate files, ensuring sensitive information is not committed. - Revised `BACKEND_INTEGRATION.md` to clarify authentication methods, replacing Cognito references with Nostr NIP-98. - Deleted outdated documentation files (`CONTENT-INTEGRATION-COMPLETE.md`, `CURSOR-MCP-SETUP.md`, `FINAL-STATUS.md`, `FIXES-APPLIED.md`, `INDEEHHUB-INTEGRATION.md`, `PROJECT-COMPLETE.md`, `PROJECT-SUMMARY.md`) to streamline project documentation. These changes enhance the clarity of the environment setup and improve the overall documentation structure for better developer onboarding.
100 lines
2.3 KiB
TypeScript
100 lines
2.3 KiB
TypeScript
// Nostr relay pool and connection management
|
|
import { SimplePool, Event as NostrEvent } from 'nostr-tools'
|
|
|
|
const DEFAULT_RELAYS = [
|
|
'wss://relay.damus.io',
|
|
'wss://nos.lol',
|
|
'wss://relay.nostr.band',
|
|
'wss://relay.snort.social'
|
|
]
|
|
|
|
// Kind numbers for IndeeHub content types
|
|
export const NOSTR_KINDS = {
|
|
VIDEO_HORIZONTAL: 34235, // NIP-71 Video horizontal
|
|
VIDEO_VERTICAL: 34236, // NIP-71 Video vertical
|
|
LONG_FORM: 30023, // NIP-23 Long-form content
|
|
SHORT_FORM: 1, // Regular notes for shorts
|
|
}
|
|
|
|
class NostrService {
|
|
private pool: SimplePool
|
|
private relays: string[]
|
|
|
|
constructor(relays: string[] = DEFAULT_RELAYS) {
|
|
this.pool = new SimplePool()
|
|
this.relays = relays
|
|
}
|
|
|
|
/**
|
|
* Fetch video content from Nostr
|
|
* Using NIP-71 for video events
|
|
*/
|
|
async fetchVideos(limit: number = 50): Promise<NostrEvent[]> {
|
|
try {
|
|
const events = await this.pool.querySync(this.relays, {
|
|
kinds: [NOSTR_KINDS.VIDEO_HORIZONTAL, NOSTR_KINDS.VIDEO_VERTICAL],
|
|
limit
|
|
})
|
|
|
|
return events
|
|
} catch (error) {
|
|
console.error('Error fetching videos from Nostr:', error)
|
|
return []
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fetch content by creator (pubkey)
|
|
*/
|
|
async fetchByCreator(pubkey: string, limit: number = 20): Promise<NostrEvent[]> {
|
|
try {
|
|
const events = await this.pool.querySync(this.relays, {
|
|
kinds: [NOSTR_KINDS.VIDEO_HORIZONTAL, NOSTR_KINDS.VIDEO_VERTICAL],
|
|
authors: [pubkey],
|
|
limit
|
|
})
|
|
|
|
return events
|
|
} catch (error) {
|
|
console.error('Error fetching creator content:', error)
|
|
return []
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Subscribe to new content events
|
|
*/
|
|
subscribeToContent(
|
|
callback: (event: NostrEvent) => void,
|
|
kinds: number[] = [NOSTR_KINDS.VIDEO_HORIZONTAL, NOSTR_KINDS.VIDEO_VERTICAL]
|
|
) {
|
|
const sub = this.pool.subscribeMany(
|
|
this.relays,
|
|
{ kinds, limit: 10 },
|
|
{
|
|
onevent(event) {
|
|
callback(event)
|
|
}
|
|
}
|
|
)
|
|
|
|
return () => sub.close()
|
|
}
|
|
|
|
/**
|
|
* Publish a view/watch event (NIP-XX view tracking — not yet implemented)
|
|
*/
|
|
async publishView(_videoEventId: string) {
|
|
// View tracking via Nostr not yet implemented
|
|
}
|
|
|
|
/**
|
|
* Close all connections
|
|
*/
|
|
close() {
|
|
this.pool.close(this.relays)
|
|
}
|
|
}
|
|
|
|
export const nostrService = new NostrService()
|