@if (Metadata != null)
{
-
@@ -64,6 +95,8 @@
}
+
+
@code {
///
/// Gets or sets a value indicating whether the modal is open.
@@ -79,8 +112,11 @@
private bool _isDragging;
private bool IsParsing { get; set; }
+ private bool IsVerifying { get; set; }
+ private bool IsIngesting { get; set; }
private LocalEpubMetadata? Metadata { get; set; }
private string? ErrorMessage { get; set; }
+ private byte[]? _epubBytes;
// Allow up to 50 MB
private const long MaxFileSize = 50 * 1024 * 1024;
@@ -95,9 +131,12 @@
private void Reset()
{
IsParsing = false;
+ IsVerifying = false;
+ IsIngesting = false;
Metadata = null;
ErrorMessage = null;
_isDragging = false;
+ _epubBytes = null;
}
private void OnDragEnter() => _isDragging = true;
@@ -123,17 +162,17 @@
try
{
using var stream = file.OpenReadStream(MaxFileSize);
-
- // In Blazor WASM, we might need to copy to memory stream first for synchronous parsing if the parser doesn't stream well over interop
using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
+ _epubBytes = memoryStream.ToArray();
+
memoryStream.Position = 0;
-
var result = await MetadataExtractor.ExtractMetadataAsync(memoryStream);
if (result.IsSuccess)
{
Metadata = result.Value;
+ IsVerifying = true;
}
else
{
@@ -143,7 +182,7 @@
catch (Exception ex)
{
Logger.LogError(ex, "Error uploading EPUB");
- ErrorMessage = $"An unexpected error occurred: {ex.Message} \n {ex.StackTrace}";
+ ErrorMessage = $"An unexpected error occurred: {ex.Message}";
}
finally
{
@@ -151,9 +190,56 @@
StateHasChanged();
}
}
+
+ private async Task SaveToLibrary()
+ {
+ if (Metadata == null || _epubBytes == null) return;
+
+ IsIngesting = true;
+ ErrorMessage = null;
+ StateHasChanged();
+
+ try
+ {
+ var request = new IngestEbookRequest(
+ Metadata.Title,
+ Metadata.Author,
+ Metadata.CoverImage != null ? Convert.ToBase64String(Metadata.CoverImage) : null,
+ Convert.ToBase64String(_epubBytes)
+ );
+
+ var response = await Http.PostAsJsonAsync("api/library/ingest", request);
+
+ if (response.IsSuccessStatusCode)
+ {
+ var result = await response.Content.ReadFromJsonAsync();
+ if (result != null)
+ {
+ await CloseModal();
+ ReaderNavigation.NavigateToBook(result.Id);
+ }
+ }
+ else
+ {
+ ErrorMessage = await response.Content.ReadAsStringAsync();
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error during ingestion");
+ ErrorMessage = "Failed to save book to library. Please try again.";
+ }
+ finally
+ {
+ IsIngesting = false;
+ StateHasChanged();
+ }
+ }
+
+ private record IngestResult(Guid Id);
+
public ValueTask DisposeAsync()
{
- // Cleanup if necessary
return ValueTask.CompletedTask;
}
}
diff --git a/src/NexusReader.UI.Shared/Components/Organisms/BookIngestionModal.razor.css b/src/NexusReader.UI.Shared/Components/Organisms/BookIngestionModal.razor.css
index 635ca08..64f412f 100644
--- a/src/NexusReader.UI.Shared/Components/Organisms/BookIngestionModal.razor.css
+++ b/src/NexusReader.UI.Shared/Components/Organisms/BookIngestionModal.razor.css
@@ -242,11 +242,139 @@
transform: translateY(0);
}
+/* Verification State */
+.verification-state {
+ display: flex;
+ flex-direction: column;
+ gap: 1.5rem;
+ animation: fadeIn 0.4s ease-out;
+}
+
+.verification-layout {
+ display: grid;
+ grid-template-columns: 140px 1fr;
+ gap: 2rem;
+ align-items: start;
+}
+
+.cover-preview {
+ width: 140px;
+ height: 200px;
+ border-radius: 12px;
+ overflow: hidden;
+ background: rgba(255, 255, 255, 0.03);
+ border: 1px solid rgba(255, 255, 255, 0.1);
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
+ position: relative;
+}
+
+.cover-preview img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.glowing-placeholder {
+ width: 100%;
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
+ position: relative;
+ overflow: hidden;
+}
+
+.glowing-placeholder::after {
+ content: '';
+ position: absolute;
+ width: 150%;
+ height: 150%;
+ background: radial-gradient(circle, var(--nexus-neon-alpha, rgba(0, 255, 153, 0.15)) 0%, transparent 70%);
+ animation: pulseGlow 4s infinite alternate;
+}
+
+.glowing-placeholder svg {
+ color: var(--nexus-neon, #00ffaa);
+ opacity: 0.5;
+ z-index: 1;
+ filter: drop-shadow(0 0 10px var(--nexus-neon-alpha-deep, rgba(0, 255, 153, 0.3)));
+}
+
+.verification-form {
+ display: flex;
+ flex-direction: column;
+ gap: 1.25rem;
+}
+
+.form-group {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+}
+
+.form-group label {
+ font-size: 0.75rem;
+ text-transform: uppercase;
+ letter-spacing: 1px;
+ color: var(--nexus-text-muted, #888);
+ font-weight: 600;
+}
+
+.form-input {
+ background: rgba(255, 255, 255, 0.03);
+ border: 1px solid rgba(255, 255, 255, 0.1);
+ border-radius: 8px;
+ padding: 0.75rem 1rem;
+ color: var(--nexus-text);
+ font-family: var(--nexus-font-sans);
+ transition: all 0.3s;
+}
+
+.form-input:focus {
+ outline: none;
+ border-color: var(--nexus-neon, #00ffaa);
+ background: rgba(255, 255, 255, 0.06);
+ box-shadow: 0 0 15px rgba(0, 255, 153, 0.1);
+}
+
.error-message {
margin-top: 1rem;
- color: #ff5555;
+ color: var(--nexus-error, #ff5555);
text-align: center;
font-size: 0.9rem;
+ padding: 0.75rem;
+ background: var(--nexus-error-alpha, rgba(255, 85, 85, 0.1));
+ border-radius: 8px;
+ border: 1px solid var(--nexus-error-alpha-deep, rgba(255, 85, 85, 0.2));
+}
+
+@keyframes pulseGlow {
+ from { transform: scale(1); opacity: 0.5; }
+ to { transform: scale(1.2); opacity: 0.8; }
+}
+
+.btn:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+ filter: grayscale(1);
+}
+
+.btn-loading {
+ position: relative;
+ color: transparent !important;
+}
+
+.btn-loading::after {
+ content: "";
+ position: absolute;
+ width: 20px;
+ height: 20px;
+ border: 2px solid rgba(0, 0, 0, 0.1);
+ border-top-color: #000;
+ border-radius: 50%;
+ animation: spin 0.8s linear infinite;
}
@keyframes fadeIn {
diff --git a/src/NexusReader.UI.Shared/Services/IReaderNavigationService.cs b/src/NexusReader.UI.Shared/Services/IReaderNavigationService.cs
index 31c1b25..ff7096d 100644
--- a/src/NexusReader.UI.Shared/Services/IReaderNavigationService.cs
+++ b/src/NexusReader.UI.Shared/Services/IReaderNavigationService.cs
@@ -12,4 +12,9 @@ public interface IReaderNavigationService
Task GoToNextChapter();
Task GoToPreviousChapter();
Task UpdateMetadataAsync(int currentIndex, int totalChapters, string title);
+
+ ///
+ /// Navigates to the reader for a specific book.
+ ///
+ void NavigateToBook(Guid bookId);
}
diff --git a/src/NexusReader.UI.Shared/Services/ReaderNavigationService.cs b/src/NexusReader.UI.Shared/Services/ReaderNavigationService.cs
index 837daf7..15e55ce 100644
--- a/src/NexusReader.UI.Shared/Services/ReaderNavigationService.cs
+++ b/src/NexusReader.UI.Shared/Services/ReaderNavigationService.cs
@@ -1,9 +1,17 @@
using System.Linq;
+using Microsoft.AspNetCore.Components;
namespace NexusReader.UI.Shared.Services;
public class ReaderNavigationService : IReaderNavigationService
{
+ private readonly NavigationManager _navigationManager;
+
+ public ReaderNavigationService(NavigationManager navigationManager)
+ {
+ _navigationManager = navigationManager;
+ }
+
public int CurrentChapterIndex { get; private set; } = 0;
public int TotalChapters { get; private set; } = 1;
public string ChapterTitle { get; private set; } = "Loading...";
@@ -47,6 +55,11 @@ public class ReaderNavigationService : IReaderNavigationService
}
}
+ public void NavigateToBook(Guid bookId)
+ {
+ _navigationManager.NavigateTo($"/reader/{bookId}");
+ }
+
private async Task NotifyNavigationChangedAsync()
{
var handlers = OnNavigationChanged?.GetInvocationList();
diff --git a/src/NexusReader.Web.Client/Program.cs b/src/NexusReader.Web.Client/Program.cs
index 461854d..eeb4f74 100644
--- a/src/NexusReader.Web.Client/Program.cs
+++ b/src/NexusReader.Web.Client/Program.cs
@@ -45,6 +45,7 @@ builder.Services.AddScoped(sp => sp.GetRequiredService().Cre
// Dummy registrations for server-only handlers to satisfy DI validation
builder.Services.AddSingleton>(new ThrowingDbContextFactory());
builder.Services.AddSingleton>>(new ThrowingEmbeddingGenerator());
+builder.Services.AddSingleton(new ThrowingBookStorageService());
builder.Services.AddApplication();
builder.Services.AddScoped();
@@ -64,3 +65,13 @@ public class ThrowingEmbeddingGenerator : IEmbeddingGenerator throw new NotSupportedException("Embedding generation cannot be used in WASM client.");
public object? GetService(Type serviceType, object? serviceKey = null) => null;
}
+
+public class ThrowingBookStorageService : IBookStorageService
+{
+ private const string ErrorMessage = "File storage operations are not supported in the WASM client. Use the API endpoint for ingestion.";
+
+ public Task SaveEbookAsync(byte[] data, string fileName) => throw new NotSupportedException(ErrorMessage);
+ public Task SaveEbookAsync(Stream data, string fileName) => throw new NotSupportedException(ErrorMessage);
+ public Task SaveCoverAsync(byte[] data, string fileName) => throw new NotSupportedException(ErrorMessage);
+ public Task SaveCoverAsync(Stream data, string fileName) => throw new NotSupportedException(ErrorMessage);
+}
diff --git a/src/NexusReader.Web.Client/Services/WasmEpubService.cs b/src/NexusReader.Web.Client/Services/WasmEpubService.cs
index 63c5760..e2cb7de 100644
--- a/src/NexusReader.Web.Client/Services/WasmEpubService.cs
+++ b/src/NexusReader.Web.Client/Services/WasmEpubService.cs
@@ -48,7 +48,7 @@ public class WasmEpubMetadataExtractor : IEpubMetadataExtractor
var title = bookRef.Title ?? "Unknown Title";
var author = bookRef.Author ?? "Unknown Author";
byte[]? cover = await bookRef.ReadCoverAsync();
- return Result.Ok(new LocalEpubMetadata(title, author, cover));
+ return Result.Ok(new LocalEpubMetadata { Title = title, Author = author, CoverImage = cover });
}
catch (Exception ex)
{
diff --git a/src/NexusReader.Web/Program.cs b/src/NexusReader.Web/Program.cs
index 9dc5875..0cdd861 100644
--- a/src/NexusReader.Web/Program.cs
+++ b/src/NexusReader.Web/Program.cs
@@ -1,9 +1,11 @@
using NexusReader.Web.Components;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Components;
using NexusReader.Application;
using NexusReader.Infrastructure;
using NexusReader.Application.Abstractions.Services;
using NexusReader.Application.Queries.User;
+using NexusReader.Application.Commands.Library;
using MediatR;
using NexusReader.Web.Client.Services;
using NexusReader.UI.Shared.Services;
@@ -48,13 +50,23 @@ builder.Services.AddScoped(
builder.Services.AddScoped();
builder.Services.AddScoped();
-builder.Services.AddHttpClient("NexusAPI", client =>
+builder.Services.AddHttpClient("NexusAPI", (sp, client) =>
{
- client.BaseAddress = new Uri(builder.Configuration["ApiBaseUrl"] ?? "http://localhost:5000");
+ var configuration = sp.GetRequiredService();
+ var apiBaseUrl = configuration["ApiBaseUrl"];
+ if (!string.IsNullOrEmpty(apiBaseUrl))
+ {
+ client.BaseAddress = new Uri(apiBaseUrl);
+ }
+ else
+ {
+ // For local development/Interactive Server, we use the current base address
+ var nav = sp.GetRequiredService();
+ client.BaseAddress = new Uri(nav.BaseUri);
+ }
});
builder.Services.AddScoped(sp => sp.GetRequiredService().CreateClient("NexusAPI"));
-builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped();
builder.Services.AddCascadingAuthenticationState();
@@ -220,9 +232,9 @@ if (!app.Environment.IsDevelopment())
app.UseHttpsRedirection();
}
-app.UseAntiforgery();
app.UseAuthentication();
app.UseAuthorization();
+app.UseAntiforgery();
app.MapStaticAssets();
app.MapHub("/synchub");
@@ -281,6 +293,30 @@ knowledgeApi.MapDelete("/", async (IKnowledgeService knowledgeService) =>
return Results.BadRequest(errorMsg);
});
+app.MapPost("/api/library/ingest", async ([FromBody] IngestEbookRequest request, ClaimsPrincipal user, IMediator mediator) =>
+{
+ var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
+ if (string.IsNullOrEmpty(userId)) return Results.Unauthorized();
+
+ var epubData = Convert.FromBase64String(request.EpubDataBase64);
+ byte[]? coverData = !string.IsNullOrEmpty(request.CoverImageBase64)
+ ? Convert.FromBase64String(request.CoverImageBase64)
+ : null;
+
+ var command = new IngestEbookCommand(
+ request.Title,
+ request.AuthorName,
+ coverData,
+ epubData,
+ userId
+ );
+
+ var result = await mediator.Send(command);
+ if (result.IsSuccess) return Results.Ok(new { Id = result.Value });
+
+ return Results.BadRequest(result.Errors.FirstOrDefault()?.Message ?? "Ingestion failed");
+}).RequireAuthorization().DisableAntiforgery();
+
app.MapPost("/api/StripeWebhook", async (
HttpContext context,
UserManager userManager,