feat: Ingestion Pipeline Stabilization and WASM Service Proxies (#42)
This PR stabilizes the Nexus Ingestion Engine by implementing functional service proxies for the Blazor WASM client and refining the backend infrastructure for real-time progress tracking and database compatibility. ### Key Changes - **Infrastructure Stabilization**: - Implemented production-grade `EbookRepository` with PostgreSQL `EF.Functions.ILike` support. - Enforced `IsReadyForReading = false` state for newly added ebooks (resolves #35). - Updated `SignalRSyncBroadcaster` to support targeted user messaging and ingestion-specific progress updates (resolves #37). - **WASM Client Functional Proxies**: - Replaced "Throwing" dummy services with `WasmEbookRepository`, `WasmSyncBroadcaster`, `WasmBookStorageService`, and `WasmEmbeddingGenerator`. - These services proxy requests to the backend via a new set of Minimal API endpoints in `NexusReader.Web`. - **Domain Refinement**: - Added `IsReadyForReading` flag to the `Ebook` entity to manage background AI processing states. ### Related Issues - Fixes #35 - Fixes #36 - Fixes #37 --------- Co-authored-by: Marek Jasiński <jasins.marek@gmail.com> Reviewed-on: #42 Co-authored-by: Antigravity <antigravity@google.com> Co-committed-by: Antigravity <antigravity@google.com>
This commit was merged in pull request #42.
This commit is contained in:
@@ -240,6 +240,8 @@
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
// Clear the large byte array so it is eligible for GC even if the component is cached.
|
||||
_epubBytes = null;
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
@using NexusReader.Application.Queries.Reader
|
||||
@using Microsoft.JSInterop
|
||||
@using NexusReader.UI.Shared.Services
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@implements IDisposable
|
||||
@inject IMediator Mediator
|
||||
@inject IJSRuntime JS
|
||||
@@ -11,8 +12,8 @@
|
||||
@inject KnowledgeCoordinator Coordinator
|
||||
@inject IReaderInteractionService InteractionService
|
||||
@inject ISyncService SyncService
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject ILogger<ReaderCanvas> Logger
|
||||
|
||||
<div class="reader-canvas @(ThemeService.IsLightMode ? "theme-light" : "theme-dark")">
|
||||
@if (ViewModel == null)
|
||||
@@ -59,7 +60,7 @@
|
||||
await Coordinator.ClearAsync();
|
||||
ThemeService.OnThemeChanged += HandleUpdate;
|
||||
NavigationService.OnNavigationChanged += OnNavigationChanged;
|
||||
|
||||
|
||||
InteractionService.OnScrollToBlockRequested += HandleScrollRequested;
|
||||
InteractionService.OnHighlightBlockRequested += HandleHighlightRequested;
|
||||
InteractionService.OnTextSelected += HandleTextSelected;
|
||||
@@ -102,7 +103,10 @@
|
||||
var module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/NexusReader.UI.Shared/js/selectionHandler.js");
|
||||
await module.InvokeVoidAsync("initSelectionListener", DotNetObjectReference.Create(this), _containerRef);
|
||||
}
|
||||
catch { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed to initialize JS selection listener. Text selection will be unavailable.");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitializeObserverAsync()
|
||||
@@ -112,24 +116,25 @@
|
||||
var module = await JS.InvokeAsync<IJSObjectReference>("import", "./_content/NexusReader.UI.Shared/js/readerObserver.js");
|
||||
await module.InvokeVoidAsync("initObserver", DotNetObjectReference.Create(this), ".reader-flow-container", ".block-wrapper");
|
||||
}
|
||||
catch { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed to initialize JS scroll observer. Reading progress sync will be unavailable.");
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task HandleBlockReached(string blockId, string content)
|
||||
{
|
||||
await Coordinator.OnBlockReachedAsync(blockId, content);
|
||||
|
||||
|
||||
if (ViewModel != null)
|
||||
{
|
||||
// Calculate progress: (CurrentChapter / TotalChapters) * 100
|
||||
// Simple approximation for now: chapter-based
|
||||
double progress = ((double)(ViewModel.CurrentChapterIndex + 1) / ViewModel.TotalChapters) * 100;
|
||||
|
||||
|
||||
await SyncService.UpdateProgressAsync(
|
||||
blockId,
|
||||
ViewModel.EbookId,
|
||||
progress,
|
||||
blockId,
|
||||
ViewModel.EbookId,
|
||||
progress,
|
||||
ViewModel.ChapterTitle,
|
||||
ViewModel.CurrentChapterIndex);
|
||||
}
|
||||
@@ -137,10 +142,8 @@
|
||||
|
||||
private async Task HandleSyncProgressReceived(string blockId, DateTime timestamp)
|
||||
{
|
||||
// For now, let's just scroll to the node if it's in the current view,
|
||||
// or just log it. Usually, we should prompt the user.
|
||||
Console.WriteLine($"[Sync] Received progress from another device: {blockId} at {timestamp}");
|
||||
|
||||
Logger.LogInformation("[Sync] Received progress from another device: block {BlockId} at {Timestamp}", blockId, timestamp);
|
||||
|
||||
await ScrollToNodeAsync(blockId);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
@@ -148,7 +151,7 @@
|
||||
[JSInvokable]
|
||||
public async Task HandleTextSelected(string text, string blockId, SelectionCoordinates coords)
|
||||
{
|
||||
Console.WriteLine($"[ReaderCanvas] Text selected: {text} at {coords.Top},{coords.Left}");
|
||||
Logger.LogDebug("[ReaderCanvas] Text selected in block {BlockId}", blockId);
|
||||
_selectedText = text;
|
||||
_selectedBlockId = blockId;
|
||||
_selectionCoords = coords;
|
||||
@@ -172,7 +175,7 @@
|
||||
{
|
||||
_highlightedBlockId = blockId;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(3000); // Highlight for 3 seconds
|
||||
await Task.Delay(3000);
|
||||
if (_highlightedBlockId == blockId)
|
||||
{
|
||||
_highlightedBlockId = null;
|
||||
@@ -192,37 +195,42 @@
|
||||
{
|
||||
ViewModel = null;
|
||||
StatusMessage = "Fetching content...";
|
||||
|
||||
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
var userId = authState.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
var result = await Mediator.Send(new GetReaderPageQuery(index, userId));
|
||||
var ebookId = NavigationService.CurrentEbookId;
|
||||
if (ebookId == Guid.Empty)
|
||||
{
|
||||
StatusMessage = "No book selected. Please open a book from your library.";
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await Mediator.Send(new GetReaderPageQuery(ebookId, index, userId));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
ViewModel = result.Value;
|
||||
await NavigationService.UpdateMetadataAsync(ViewModel.CurrentChapterIndex, ViewModel.TotalChapters, ViewModel.ChapterTitle);
|
||||
|
||||
// Trigger full page graph generation after loading
|
||||
|
||||
await Coordinator.ProcessFullPageAsync(GetFullPageContent());
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusMessage = $"Error: {result.Errors.FirstOrDefault()?.Message ?? "Failed to load"}";
|
||||
Logger.LogError("Failed to load chapter {Index} for ebook {EbookId}: {Errors}", index, ebookId, string.Join(", ", result.Errors.Select(e => e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAiAction(string action)
|
||||
{
|
||||
Console.WriteLine($"Action Triggered from Bubble: {action}");
|
||||
}
|
||||
|
||||
public async Task ScrollToNodeAsync(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await JS.InvokeVoidAsync("eval", $"document.getElementById('{id}')?.scrollIntoView({{ behavior: 'smooth', block: 'center' }});");
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed to scroll to node {NodeId}.", id);
|
||||
}
|
||||
}
|
||||
|
||||
private Task HandleUpdate() => InvokeAsync(StateHasChanged);
|
||||
@@ -231,7 +239,7 @@
|
||||
{
|
||||
ThemeService.OnThemeChanged -= HandleUpdate;
|
||||
NavigationService.OnNavigationChanged -= OnNavigationChanged;
|
||||
|
||||
|
||||
InteractionService.OnScrollToBlockRequested -= HandleScrollRequested;
|
||||
InteractionService.OnHighlightBlockRequested -= HandleHighlightRequested;
|
||||
InteractionService.OnTextSelected -= HandleTextSelected;
|
||||
|
||||
@@ -2,19 +2,20 @@ namespace NexusReader.UI.Shared.Services;
|
||||
|
||||
public interface IReaderNavigationService
|
||||
{
|
||||
Guid CurrentEbookId { get; }
|
||||
int CurrentChapterIndex { get; }
|
||||
int TotalChapters { get; }
|
||||
string ChapterTitle { get; }
|
||||
|
||||
|
||||
event Func<Task>? OnNavigationChanged;
|
||||
|
||||
|
||||
Task GoToChapter(int index);
|
||||
Task GoToNextChapter();
|
||||
Task GoToPreviousChapter();
|
||||
Task UpdateMetadataAsync(int currentIndex, int totalChapters, string title);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Navigates to the reader for a specific book.
|
||||
/// Navigates to the reader for a specific book and records the current ebook ID.
|
||||
/// </summary>
|
||||
void NavigateToBook(Guid bookId);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,11 @@ public sealed partial class KnowledgeCoordinator : IDisposable
|
||||
private readonly IReaderInteractionService _interactionService;
|
||||
private readonly ILogger<KnowledgeCoordinator> _logger;
|
||||
|
||||
public event Action<GraphDataDto>? OnGraphUpdated;
|
||||
/// <summary>
|
||||
/// Raised when the knowledge graph has been updated with new data.
|
||||
/// Subscribers must return a Task to enable proper async handling.
|
||||
/// </summary>
|
||||
public event Func<GraphDataDto, Task>? OnGraphUpdated;
|
||||
|
||||
public KnowledgeCoordinator(
|
||||
IKnowledgeService knowledgeService,
|
||||
@@ -61,7 +65,8 @@ public sealed partial class KnowledgeCoordinator : IDisposable
|
||||
if (packet.Graph != null)
|
||||
{
|
||||
await _graphService.UpdateGraph(packet.Graph);
|
||||
OnGraphUpdated?.Invoke(packet.Graph);
|
||||
if (OnGraphUpdated != null)
|
||||
await OnGraphUpdated.Invoke(packet.Graph);
|
||||
await _platformService.VibrateSuccessAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace NexusReader.UI.Shared.Services;
|
||||
@@ -12,6 +11,7 @@ public class ReaderNavigationService : IReaderNavigationService
|
||||
_navigationManager = navigationManager;
|
||||
}
|
||||
|
||||
public Guid CurrentEbookId { get; private set; } = Guid.Empty;
|
||||
public int CurrentChapterIndex { get; private set; } = 0;
|
||||
public int TotalChapters { get; private set; } = 1;
|
||||
public string ChapterTitle { get; private set; } = "Loading...";
|
||||
@@ -21,7 +21,7 @@ public class ReaderNavigationService : IReaderNavigationService
|
||||
public async Task GoToChapter(int index)
|
||||
{
|
||||
if (index < 0 || index >= TotalChapters) return;
|
||||
|
||||
|
||||
CurrentChapterIndex = index;
|
||||
await NotifyNavigationChangedAsync();
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class ReaderNavigationService : IReaderNavigationService
|
||||
if (CurrentChapterIndex != currentIndex) { CurrentChapterIndex = currentIndex; changed = true; }
|
||||
if (TotalChapters != totalChapters) { TotalChapters = totalChapters; changed = true; }
|
||||
if (ChapterTitle != title) { ChapterTitle = title; changed = true; }
|
||||
|
||||
|
||||
if (changed)
|
||||
{
|
||||
await NotifyNavigationChangedAsync();
|
||||
@@ -57,6 +57,8 @@ public class ReaderNavigationService : IReaderNavigationService
|
||||
|
||||
public void NavigateToBook(Guid bookId)
|
||||
{
|
||||
CurrentEbookId = bookId;
|
||||
CurrentChapterIndex = 0;
|
||||
_navigationManager.NavigateTo($"/reader/{bookId}");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using FluentResults;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NexusReader.Application.Abstractions.Services;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace NexusReader.UI.Shared.Services;
|
||||
|
||||
@@ -10,6 +10,7 @@ public class SyncService : ISyncService, IAsyncDisposable
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly INativeStorageService _storageService;
|
||||
private readonly IPlatformService _platformService;
|
||||
private readonly ILogger<SyncService> _logger;
|
||||
private HubConnection? _hubConnection;
|
||||
private bool _isInitialized;
|
||||
private CancellationTokenSource? _debounceCts;
|
||||
@@ -19,11 +20,13 @@ public class SyncService : ISyncService, IAsyncDisposable
|
||||
public SyncService(
|
||||
HttpClient httpClient,
|
||||
INativeStorageService storageService,
|
||||
IPlatformService platformService)
|
||||
IPlatformService platformService,
|
||||
ILogger<SyncService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_storageService = storageService;
|
||||
_platformService = platformService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<Result> InitializeAsync()
|
||||
@@ -78,9 +81,9 @@ public class SyncService : ISyncService, IAsyncDisposable
|
||||
try
|
||||
{
|
||||
await Task.Delay(2000, token);
|
||||
|
||||
|
||||
if (!_isInitialized) await InitializeAsync();
|
||||
|
||||
|
||||
if (_hubConnection?.State == HubConnectionState.Connected)
|
||||
{
|
||||
await _hubConnection.SendAsync("UpdateProgress", pageId, ebookId, progress, chapterTitle, token);
|
||||
@@ -90,7 +93,7 @@ public class SyncService : ISyncService, IAsyncDisposable
|
||||
catch (TaskCanceledException) { /* Ignored, user kept scrolling */ }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[SyncService] Error sending progress: {ex.Message}");
|
||||
_logger.LogError(ex, "[SyncService] Error sending reading progress for page {PageId}.", pageId);
|
||||
}
|
||||
}, token);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user