d5c2952bec
### 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>
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using NexusReader.Application.Abstractions.Services;
|
|
|
|
namespace NexusReader.Infrastructure.Services;
|
|
|
|
/// <summary>
|
|
/// Infrastructure implementation of book storage using local filesystem.
|
|
/// All paths returned are relative to the web root.
|
|
/// </summary>
|
|
public class BookStorageService : IBookStorageService
|
|
{
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
|
public BookStorageService(IWebHostEnvironment environment)
|
|
{
|
|
_environment = environment;
|
|
}
|
|
|
|
public async Task<string> SaveEbookAsync(byte[] data, string fileName)
|
|
{
|
|
using var stream = new MemoryStream(data);
|
|
return await SaveEbookAsync(stream, fileName);
|
|
}
|
|
|
|
public async Task<string> SaveEbookAsync(Stream data, string fileName)
|
|
{
|
|
var uploadsFolder = Path.Combine(_environment.WebRootPath, "uploads");
|
|
EnsureDirectoryExists(uploadsFolder);
|
|
|
|
var uniqueFileName = $"{Guid.NewGuid()}_{fileName}";
|
|
var filePath = Path.Combine(uploadsFolder, uniqueFileName);
|
|
|
|
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
|
{
|
|
await data.CopyToAsync(fileStream);
|
|
}
|
|
|
|
return Path.Combine("uploads", uniqueFileName);
|
|
}
|
|
|
|
public async Task<string?> SaveCoverAsync(byte[] data, string fileName)
|
|
{
|
|
if (data == null || data.Length == 0) return null;
|
|
using var stream = new MemoryStream(data);
|
|
return await SaveCoverAsync(stream, fileName);
|
|
}
|
|
|
|
public async Task<string?> SaveCoverAsync(Stream data, string fileName)
|
|
{
|
|
var coversFolder = Path.Combine(_environment.WebRootPath, "covers");
|
|
EnsureDirectoryExists(coversFolder);
|
|
|
|
var uniqueFileName = $"{Guid.NewGuid()}_{fileName}";
|
|
var filePath = Path.Combine(coversFolder, uniqueFileName);
|
|
|
|
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
|
{
|
|
await data.CopyToAsync(fileStream);
|
|
}
|
|
|
|
return Path.Combine("covers", uniqueFileName);
|
|
}
|
|
|
|
private void EnsureDirectoryExists(string path)
|
|
{
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
}
|
|
}
|