lint fix wip
This commit is contained in:
parent
b2e6250ff5
commit
964f4aeb60
@ -1,7 +1,7 @@
|
|||||||
import { nostrService } from './nostr'
|
import { nostrService } from './nostr'
|
||||||
import type { AlbyInvoice } from '@/types/alby'
|
import type { AlbyInvoice } from '@/types/alby'
|
||||||
import { getStoredPrivateContent, getStoredInvoice, removeStoredPrivateContent } from './articleStorage'
|
import { getStoredPrivateContent, getStoredInvoice, removeStoredPrivateContent } from './articleStorage'
|
||||||
import { buildPresentationEvent, fetchAuthorPresentationFromPool, sendEncryptedContent } from './articlePublisherHelpers'
|
import { buildPresentationEvent, sendEncryptedContent } from './articlePublisherHelpers'
|
||||||
import type { ArticleDraft, AuthorPresentationDraft, PublishedArticle } from './articlePublisherTypes'
|
import type { ArticleDraft, AuthorPresentationDraft, PublishedArticle } from './articlePublisherTypes'
|
||||||
import { prepareAuthorKeys, isValidCategory, type PublishValidationResult } from './articlePublisherValidation'
|
import { prepareAuthorKeys, isValidCategory, type PublishValidationResult } from './articlePublisherValidation'
|
||||||
import { buildFailure, encryptAndPublish } from './articlePublisherPublish'
|
import { buildFailure, encryptAndPublish } from './articlePublisherPublish'
|
||||||
@ -209,11 +209,18 @@ export class ArticlePublisher {
|
|||||||
|
|
||||||
async getAuthorPresentation(pubkey: string): Promise<import('@/types/nostr').AuthorPresentationArticle | null> {
|
async getAuthorPresentation(pubkey: string): Promise<import('@/types/nostr').AuthorPresentationArticle | null> {
|
||||||
try {
|
try {
|
||||||
const pool = nostrService.getPool()
|
// Read only from IndexedDB cache
|
||||||
if (!pool) {
|
const { objectCache } = await import('./objectCache')
|
||||||
return null
|
const cached = await objectCache.getAuthorByPubkey(pubkey)
|
||||||
|
if (cached) {
|
||||||
|
const presentation = cached
|
||||||
|
// Calculate totalSponsoring from cache
|
||||||
|
const { getAuthorSponsoring } = await import('./sponsoring')
|
||||||
|
presentation.totalSponsoring = await getAuthorSponsoring(presentation.pubkey)
|
||||||
|
return presentation
|
||||||
}
|
}
|
||||||
return fetchAuthorPresentationFromPool(pool, pubkey)
|
// Not found in cache - return null (no network request)
|
||||||
|
return null
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error getting author presentation:', error)
|
console.error('Error getting author presentation:', error)
|
||||||
return null
|
return null
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export async function fetchAuthorByHashId(
|
|||||||
// Read only from IndexedDB cache
|
// Read only from IndexedDB cache
|
||||||
const cached = await objectCache.getAuthorByPubkey(hashIdOrPubkey)
|
const cached = await objectCache.getAuthorByPubkey(hashIdOrPubkey)
|
||||||
if (cached) {
|
if (cached) {
|
||||||
const presentation = cached as import('@/types/nostr').AuthorPresentationArticle
|
const presentation = cached
|
||||||
// Calculate totalSponsoring from cache
|
// Calculate totalSponsoring from cache
|
||||||
const { getAuthorSponsoring } = await import('./sponsoring')
|
const { getAuthorSponsoring } = await import('./sponsoring')
|
||||||
presentation.totalSponsoring = await getAuthorSponsoring(presentation.pubkey)
|
presentation.totalSponsoring = await getAuthorSponsoring(presentation.pubkey)
|
||||||
|
|||||||
@ -121,7 +121,7 @@ class NotificationDetector {
|
|||||||
|
|
||||||
// Create notifications for objects created after last scan
|
// Create notifications for objects created after last scan
|
||||||
for (const obj of userObjects) {
|
for (const obj of userObjects) {
|
||||||
const cachedObj = obj as CachedObject
|
const cachedObj = obj
|
||||||
if (cachedObj.createdAt * 1000 > this.lastScanTime) {
|
if (cachedObj.createdAt * 1000 > this.lastScanTime) {
|
||||||
const eventId = cachedObj.id.split(':')[1] ?? cachedObj.id
|
const eventId = cachedObj.id.split(':')[1] ?? cachedObj.id
|
||||||
await notificationService.createNotification({
|
await notificationService.createNotification({
|
||||||
@ -172,7 +172,7 @@ class NotificationDetector {
|
|||||||
// We can't track old/new state easily, so we'll create notification
|
// We can't track old/new state easily, so we'll create notification
|
||||||
// if object was published recently (created in last hour and published)
|
// if object was published recently (created in last hour and published)
|
||||||
const oneHourAgo = Date.now() - 60 * 60 * 1000
|
const oneHourAgo = Date.now() - 60 * 60 * 1000
|
||||||
const cachedObj = obj as CachedObject
|
const cachedObj = obj
|
||||||
if (cachedObj.createdAt * 1000 > oneHourAgo) {
|
if (cachedObj.createdAt * 1000 > oneHourAgo) {
|
||||||
const relays = cachedObj.published as string[]
|
const relays = cachedObj.published as string[]
|
||||||
await notificationService.createNotification({
|
await notificationService.createNotification({
|
||||||
@ -276,7 +276,7 @@ class NotificationDetector {
|
|||||||
case 'payment_note':
|
case 'payment_note':
|
||||||
return `Une note de paiement a été ajoutée`
|
return `Une note de paiement a été ajoutée`
|
||||||
case 'published':
|
case 'published':
|
||||||
const cachedObj = _obj as CachedObject
|
const cachedObj = _obj
|
||||||
const relays = Array.isArray(cachedObj.published) ? cachedObj.published : []
|
const relays = Array.isArray(cachedObj.published) ? cachedObj.published : []
|
||||||
return `Votre contenu a été publié sur ${relays.length} relais`
|
return `Votre contenu a été publié sur ${relays.length} relais`
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
* Continuously attempts to publish objects with published === false
|
* Continuously attempts to publish objects with published === false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { nostrService } from './nostr'
|
|
||||||
import { objectCache, type ObjectType } from './objectCache'
|
import { objectCache, type ObjectType } from './objectCache'
|
||||||
import { relaySessionManager } from './relaySessionManager'
|
import { relaySessionManager } from './relaySessionManager'
|
||||||
import { publishLog } from './publishLog'
|
import { publishLog } from './publishLog'
|
||||||
|
|||||||
@ -118,7 +118,6 @@ class ServiceWorkerSyncHandler {
|
|||||||
try {
|
try {
|
||||||
console.warn('[SWSyncHandler] Executing notification detection request for:', userPubkey)
|
console.warn('[SWSyncHandler] Executing notification detection request for:', userPubkey)
|
||||||
const { notificationDetector } = await import('./notificationDetector')
|
const { notificationDetector } = await import('./notificationDetector')
|
||||||
const { writeService } = await import('./writeService')
|
|
||||||
|
|
||||||
// Scanner IndexedDB pour détecter les nouveaux événements
|
// Scanner IndexedDB pour détecter les nouveaux événements
|
||||||
await notificationDetector.scan()
|
await notificationDetector.scan()
|
||||||
@ -132,36 +131,31 @@ class ServiceWorkerSyncHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle publish request from Service Worker
|
* Handle publish request from Service Worker
|
||||||
|
* Uses websocketService to route events to Service Worker
|
||||||
*/
|
*/
|
||||||
private async handlePublishRequest(event: Event, relays: string[]): Promise<void> {
|
private async handlePublishRequest(event: Event, relays: string[]): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.warn('[SWSyncHandler] Executing publish request for event:', event.id)
|
console.warn('[SWSyncHandler] Executing publish request for event:', event.id)
|
||||||
const pool = nostrService.getPool()
|
const { websocketService } = await import('./websocketService')
|
||||||
if (!pool) {
|
|
||||||
throw new Error('Pool not initialized')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish to specified relays
|
|
||||||
const pubs = pool.publish(relays, event)
|
|
||||||
const results = await Promise.allSettled(pubs)
|
|
||||||
|
|
||||||
const { publishLog } = await import('./publishLog')
|
const { publishLog } = await import('./publishLog')
|
||||||
|
|
||||||
|
// Publish to specified relays via websocketService (routes to Service Worker)
|
||||||
|
const statuses = await websocketService.publishEvent(event, relays)
|
||||||
const successfulRelays: string[] = []
|
const successfulRelays: string[] = []
|
||||||
|
|
||||||
results.forEach((result, index) => {
|
statuses.forEach((status, index) => {
|
||||||
const relayUrl = relays[index]
|
const relayUrl = relays[index]
|
||||||
if (!relayUrl) {
|
if (!relayUrl) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status === 'fulfilled') {
|
if (status.success) {
|
||||||
successfulRelays.push(relayUrl)
|
successfulRelays.push(relayUrl)
|
||||||
// Log successful publication
|
// Log successful publication
|
||||||
void publishLog.logPublication(event.id, relayUrl, true, undefined)
|
void publishLog.logPublication(event.id, relayUrl, true, undefined)
|
||||||
} else {
|
} else {
|
||||||
const error = result.reason
|
const errorMessage = status.error ?? 'Unknown error'
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
console.error(`[SWSyncHandler] Relay ${relayUrl} failed:`, errorMessage)
|
||||||
console.error(`[SWSyncHandler] Relay ${relayUrl} failed:`, error)
|
|
||||||
// Log failed publication
|
// Log failed publication
|
||||||
void publishLog.logPublication(event.id, relayUrl, false, errorMessage)
|
void publishLog.logPublication(event.id, relayUrl, false, errorMessage)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,7 @@ import '@/styles/globals.css'
|
|||||||
import type { AppProps } from 'next/app'
|
import type { AppProps } from 'next/app'
|
||||||
import { useI18n } from '@/hooks/useI18n'
|
import { useI18n } from '@/hooks/useI18n'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { platformSyncService } from '@/lib/platformSync'
|
|
||||||
import { nostrAuthService } from '@/lib/nostrAuth'
|
import { nostrAuthService } from '@/lib/nostrAuth'
|
||||||
import { syncUserContentToCache } from '@/lib/userContentSync'
|
|
||||||
import { syncProgressManager } from '@/lib/syncProgressManager'
|
|
||||||
import { relaySessionManager } from '@/lib/relaySessionManager'
|
import { relaySessionManager } from '@/lib/relaySessionManager'
|
||||||
import { publishWorker } from '@/lib/publishWorker'
|
import { publishWorker } from '@/lib/publishWorker'
|
||||||
import { swSyncHandler } from '@/lib/swSyncHandler'
|
import { swSyncHandler } from '@/lib/swSyncHandler'
|
||||||
@ -69,74 +66,51 @@ export default function App({ Component, pageProps }: AppProps): React.ReactElem
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Start platform sync on app mount and resume on each page navigation
|
// Start platform sync on app mount via Service Worker only
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Start continuous sync (runs periodically in background, uses Service Worker if available)
|
const startPlatformSync = async (): Promise<void> => {
|
||||||
void platformSyncService.startContinuousSync()
|
try {
|
||||||
|
const isReady = await swClient.isReady()
|
||||||
// Also trigger a sync on each page navigation
|
if (isReady) {
|
||||||
const handleRouteChange = (): void => {
|
await swClient.startPlatformSync()
|
||||||
if (!platformSyncService.isSyncing()) {
|
}
|
||||||
void platformSyncService.startSync()
|
} catch (error) {
|
||||||
|
console.warn('[App] Service Worker not available for platform sync:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startPlatformSync()
|
||||||
|
|
||||||
|
// Trigger sync on each page navigation
|
||||||
|
const handleRouteChange = (): void => {
|
||||||
|
void startPlatformSync()
|
||||||
|
}
|
||||||
|
|
||||||
// Listen to route changes
|
// Listen to route changes
|
||||||
const router = require('next/router').default
|
const router = require('next/router').default
|
||||||
router.events?.on('routeChangeComplete', handleRouteChange)
|
router.events?.on('routeChangeComplete', handleRouteChange)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
router.events?.off('routeChangeComplete', handleRouteChange)
|
router.events?.off('routeChangeComplete', handleRouteChange)
|
||||||
void platformSyncService.stopSync()
|
void swClient.stopPlatformSync()
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Start user content sync on app mount and on each page navigation if connected
|
// Start user content sync on app mount via Service Worker only
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
let syncInProgress = false
|
|
||||||
|
|
||||||
const startUserSync = async (): Promise<void> => {
|
const startUserSync = async (): Promise<void> => {
|
||||||
if (syncInProgress) {
|
|
||||||
console.warn('[App] Sync already in progress, skipping')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = nostrAuthService.getState()
|
const state = nostrAuthService.getState()
|
||||||
console.warn('[App] Checking connection state:', { connected: state.connected, hasPubkey: Boolean(state.pubkey) })
|
|
||||||
if (!state.connected || !state.pubkey) {
|
if (!state.connected || !state.pubkey) {
|
||||||
console.warn('[App] Not connected or no pubkey, skipping sync')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
syncInProgress = true
|
|
||||||
console.warn('[App] Starting user content sync...')
|
|
||||||
|
|
||||||
// Try to use Service Worker for background sync
|
|
||||||
try {
|
try {
|
||||||
const isReady = await swClient.isReady()
|
const isReady = await swClient.isReady()
|
||||||
if (isReady) {
|
if (isReady) {
|
||||||
console.warn('[App] Using Service Worker for user content sync')
|
|
||||||
await swClient.startUserSync(state.pubkey)
|
await swClient.startUserSync(state.pubkey)
|
||||||
// Still sync immediately in main thread for UI feedback
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('[App] Service Worker not available, using direct sync:', error)
|
console.warn('[App] Service Worker not available for user content sync:', error)
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await syncUserContentToCache(state.pubkey, (progress) => {
|
|
||||||
syncProgressManager.setProgress(progress)
|
|
||||||
if (progress.completed) {
|
|
||||||
syncProgressManager.setProgress(null)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
console.warn('[App] User content sync completed')
|
|
||||||
syncProgressManager.setProgress(null)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[App] Error during user content sync:', error)
|
|
||||||
syncProgressManager.setProgress(null)
|
|
||||||
} finally {
|
|
||||||
syncInProgress = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,15 +120,13 @@ export default function App({ Component, pageProps }: AppProps): React.ReactElem
|
|||||||
// Also listen to connection changes and route changes to sync when user connects or navigates
|
// Also listen to connection changes and route changes to sync when user connects or navigates
|
||||||
const router = require('next/router').default
|
const router = require('next/router').default
|
||||||
const handleRouteChange = (): void => {
|
const handleRouteChange = (): void => {
|
||||||
if (!syncInProgress) {
|
void startUserSync()
|
||||||
void startUserSync()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router.events?.on('routeChangeComplete', handleRouteChange)
|
router.events?.on('routeChangeComplete', handleRouteChange)
|
||||||
|
|
||||||
const unsubscribe = nostrAuthService.subscribe((state) => {
|
const unsubscribe = nostrAuthService.subscribe((state) => {
|
||||||
if (state.connected && state.pubkey && !syncInProgress) {
|
if (state.connected && state.pubkey) {
|
||||||
void startUserSync()
|
void startUserSync()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -171,3 +143,4 @@ export default function App({ Component, pageProps }: AppProps): React.ReactElem
|
|||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user