**Motivations:** - Keep dependencies up to date for security and features - Automate dependency updates in deployment script - Fix compatibility issues with major version updates (React 19, Next.js 16, nostr-tools 2.x) **Root causes:** - Dependencies were outdated - Deployment script did not update dependencies before deploying - Major version updates introduced breaking API changes **Correctifs:** - Updated all dependencies to latest versions using npm-check-updates - Modified deploy.sh to run npm-check-updates before installing dependencies - Fixed nostr-tools 2.x API changes (generatePrivateKey -> generateSecretKey, signEvent -> finalizeEvent, verifySignature -> verifyEvent) - Fixed React 19 ref types to accept null - Fixed JSX namespace issues (JSX.Element -> React.ReactElement) - Added proper types for event callbacks - Fixed SimplePool.sub typing issues with type assertions **Evolutions:** - Deployment script now automatically updates dependencies to latest versions before deploying - All dependencies updated to latest versions (Next.js 14->16, React 18->19, nostr-tools 1->2, etc.) **Pages affectées:** - package.json - deploy.sh - lib/keyManagement.ts - lib/nostr.ts - lib/nostrRemoteSigner.ts - lib/zapVerification.ts - lib/platformTrackingEvents.ts - lib/sponsoringTracking.ts - lib/articlePublisherHelpersVerification.ts - lib/contentDeliveryVerification.ts - lib/paymentPollingZapReceipt.ts - lib/nostrPrivateMessages.ts - lib/nostrSubscription.ts - lib/nostrZapVerification.ts - lib/markdownRenderer.tsx - components/AuthorFilter.tsx - components/AuthorFilterButton.tsx - components/UserArticlesList.tsx - types/nostr-tools-extended.ts
103 lines
3.0 KiB
TypeScript
103 lines
3.0 KiB
TypeScript
import { useState } from 'react'
|
|
import { nostrService } from '@/lib/nostr'
|
|
import { articlePublisher } from '@/lib/articlePublisher'
|
|
import type { Article } from '@/types/nostr'
|
|
import type { NostrProfile } from '@/types/nostr'
|
|
|
|
interface AuthorPresentationDraft {
|
|
authorName: string
|
|
presentation: string
|
|
contentDescription: string
|
|
mainnetAddress: string
|
|
pictureUrl?: string
|
|
}
|
|
|
|
export function useAuthorPresentation(pubkey: string | null) {
|
|
const [loading, setLoading] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
const [success, setSuccess] = useState(false)
|
|
|
|
const publishPresentation = async (draft: AuthorPresentationDraft): Promise<void> => {
|
|
if (!pubkey) {
|
|
setError('Clé publique non disponible')
|
|
return
|
|
}
|
|
|
|
setLoading(true)
|
|
setError(null)
|
|
|
|
try {
|
|
const privateKey = nostrService.getPrivateKey()
|
|
if (!privateKey) {
|
|
setError('Clé privée requise pour publier. Veuillez vous connecter avec un portefeuille Nostr qui fournit des capacités de signature.')
|
|
setLoading(false)
|
|
return
|
|
}
|
|
|
|
// Update Nostr profile (kind 0) with author name and picture
|
|
const profileUpdates: Partial<NostrProfile> = {
|
|
name: draft.authorName.trim(),
|
|
...(draft.pictureUrl ? { picture: draft.pictureUrl } : {}),
|
|
}
|
|
try {
|
|
await nostrService.updateProfile(profileUpdates)
|
|
} catch (e) {
|
|
console.error('Error updating profile:', e)
|
|
// Continue with article publication even if profile update fails
|
|
}
|
|
|
|
// Create presentation article
|
|
const title = `Présentation de ${draft.authorName.trim()}`
|
|
const preview = draft.presentation.substring(0, 200)
|
|
const fullContent = `${draft.presentation}\n\n---\n\nDescription du contenu :\n${draft.contentDescription}`
|
|
|
|
const result = await articlePublisher.publishPresentationArticle(
|
|
{
|
|
title,
|
|
preview,
|
|
content: fullContent,
|
|
presentation: draft.presentation,
|
|
contentDescription: draft.contentDescription,
|
|
mainnetAddress: draft.mainnetAddress,
|
|
...(draft.pictureUrl ? { pictureUrl: draft.pictureUrl } : {}),
|
|
},
|
|
pubkey,
|
|
privateKey
|
|
)
|
|
|
|
if (result.success) {
|
|
setSuccess(true)
|
|
} else {
|
|
setError(result.error ?? 'Erreur lors de la publication')
|
|
}
|
|
} catch (e) {
|
|
const errorMessage = e instanceof Error ? e.message : 'Erreur inconnue'
|
|
console.error('Error publishing presentation:', e)
|
|
setError(errorMessage)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
const checkPresentationExists = async (): Promise<Article | null> => {
|
|
if (!pubkey) {
|
|
return null
|
|
}
|
|
|
|
try {
|
|
return await articlePublisher.getAuthorPresentation(pubkey)
|
|
} catch (e) {
|
|
console.error('Error checking presentation:', e)
|
|
return null
|
|
}
|
|
}
|
|
|
|
return {
|
|
loading,
|
|
error,
|
|
success,
|
|
publishPresentation,
|
|
checkPresentationExists,
|
|
}
|
|
}
|