### Description This PR implements **Issue #34: [UI/UX] Implement Hybrid Metadata Verification Form in Ingestion Modal**. ### Key Changes - **Metadata Verification State**: Introduced a new state in `BookIngestionModal.razor` allowing users to edit `Title` and `Author` before final ingestion. - **Cover Image Preview**: Added a high-fidelity cover preview with a CSS-based glowing placeholder fallback for books without embedded covers. - **Ingestion Pipeline**: - Implemented `IngestEbookCommand` and `IngestEbookCommandHandler`. - Added `IBookStorageService` and its implementation for managing EPUB and cover file storage. - Exposed `POST /api/library/ingest` Minimal API endpoint with `.DisableAntiforgery()` to handle client-side JSON uploads. - **Stability Fixes**: - Resolved DI validation errors in the WASM client by providing a dummy `IBookStorageService` registration. - Adjusted Kestrel request limits to handle large EPUB payloads (up to 100MB). - Corrected middleware ordering to ensure Antiforgery works correctly with Authentication. ### Verification - Solution builds successfully. - Manual verification of modal state transitions and API ingestion logic. Closes #34. --------- Co-authored-by: Marek Jasiński <jasins.marek@gmail.com> Reviewed-on: #41 Reviewed-by: Marek Jaisński <jasins.marek@gmail.com> Co-authored-by: Antigravity <antigravity@google.com> Co-committed-by: Antigravity <antigravity@google.com>
This commit was merged in pull request #41.
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using NexusReader.Application.Abstractions.Services
|
||||
@using NexusReader.Application.Queries.Reader
|
||||
@using NexusReader.Application.Commands.Library
|
||||
@using System.Net.Http.Json
|
||||
@inject IEpubMetadataExtractor MetadataExtractor
|
||||
@inject ILogger<BookIngestionModal> Logger
|
||||
@inject HttpClient Http
|
||||
@inject IReaderNavigationService ReaderNavigation
|
||||
@inject IJSRuntime JSRuntime
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@if (IsOpen)
|
||||
@@ -24,22 +29,48 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="metadata-state" style="@(Metadata != null && !IsParsing ? "display:flex;" : "display:none;")">
|
||||
<div class="verification-state" style="@(IsVerifying && !IsParsing ? "display:flex;" : "display:none;")">
|
||||
@if (Metadata != null)
|
||||
{
|
||||
<div class="metadata-info">
|
||||
<h3>@Metadata.Title</h3>
|
||||
<p class="author">@Metadata.Author</p>
|
||||
<div class="verification-layout">
|
||||
<div class="cover-preview">
|
||||
@if (Metadata.CoverImage != null)
|
||||
{
|
||||
<img src="data:image/jpeg;base64,@Convert.ToBase64String(Metadata.CoverImage)" alt="Cover Preview" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="glowing-placeholder">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"></path><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"></path></svg>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="verification-form">
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="form-input" @bind="Metadata.Title" placeholder="Enter book title" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Author</label>
|
||||
<input type="text" class="form-input" @bind="Metadata.Author" placeholder="Enter author name" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn btn-primary">Confirm & Upload</button>
|
||||
<button class="btn btn-secondary" @onclick="Reset">Cancel</button>
|
||||
<NexusButton Class="btn-secondary" OnClick="Reset" Disabled="IsIngesting">Back</NexusButton>
|
||||
<NexusButton Class="@($"btn-primary {(IsIngesting ? "btn-loading" : "")}")"
|
||||
OnClick="SaveToLibrary"
|
||||
Disabled="IsIngesting">
|
||||
@(IsIngesting ? "" : "Save to Library")
|
||||
</NexusButton>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="upload-state @(_isDragging ? "drag-over" : "")"
|
||||
style="@(!IsParsing && Metadata == null ? "display:flex;" : "display:none;")"
|
||||
style="@(!IsParsing && !IsVerifying ? "display:flex;" : "display:none;")"
|
||||
@ondragenter="OnDragEnter"
|
||||
@ondragleave="OnDragLeave">
|
||||
<div class="drop-zone">
|
||||
@@ -64,6 +95,8 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
|
||||
@code {
|
||||
/// <summary>
|
||||
/// 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<IngestResult>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -12,4 +12,9 @@ public interface IReaderNavigationService
|
||||
Task GoToNextChapter();
|
||||
Task GoToPreviousChapter();
|
||||
Task UpdateMetadataAsync(int currentIndex, int totalChapters, string title);
|
||||
|
||||
/// <summary>
|
||||
/// Navigates to the reader for a specific book.
|
||||
/// </summary>
|
||||
void NavigateToBook(Guid bookId);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user