Compare commits
11 Commits
8ddecb4acc
...
47919a226e
| Author | SHA1 | Date | |
|---|---|---|---|
| 47919a226e | |||
| 933b7145e5 | |||
| f21647423a | |||
| df7acd9e80 | |||
| 3a4db834ac | |||
| d12151278a | |||
| ca90302f21 | |||
| 16784b37f2 | |||
| e9e6b6054f | |||
| 8fa330fbd3 | |||
| 5f0422a263 |
@@ -318,3 +318,4 @@ Database/Vaults/*
|
||||
# RCL compiled JS must be committed — MapStaticAssets serves from build-time manifest;
|
||||
# gitignored TS output is absent when manifest is generated, so absent from publish output.
|
||||
!DeepDrftShared.Client/wwwroot/js/parallax/
|
||||
!DeepDrftShared.Client/wwwroot/js/knob/
|
||||
@@ -9,11 +9,11 @@ DeepDrftHome is a **net10.0** solution consisting of ten projects implementing a
|
||||
### Core Projects
|
||||
|
||||
- **DeepDrftPublic**: ASP.NET Core host. Blazor Web App with Server + WASM render modes. Owns browser-facing proxy controller for `api/track/*` (metadata listing and audio streaming), MudBlazor theme prerender, and TypeScript→JS audio interop. Public-facing site for listeners.
|
||||
- **DeepDrftPublic.Client**: Blazor WebAssembly assembly. All interactive UI (pages, player stack, dark-mode plumbing, HTTP clients for both backends). Pages include the public `/about` editorial page (`Pages/About.razor` — three-movement **"Liner Notes"** editorial treatment: numbered left-rail (oversized Bodoni numerals + vertical hairline spine + mono marginalia captions), asymmetric content column, pull-quotes breaking into the margin, hand-authored SVG waveform movement dividers (self-contained motif, not the live `WaveformVisualizer`), and stacked editorial definition list for CUTS/SESSIONS/MIXES; active-movement highlight via `about-rail.ts` IntersectionObserver interop; registered in `Layout/Pages.cs`). Consumed by the public site.
|
||||
- **DeepDrftManager**: ASP.NET Core host. Blazor Web App with server-rendered `InteractiveServer` render mode. Hosts all CMS Razor components and pages under `Components/Pages/Cms/`, `Components/Pages/Tracks/`, `Components/Layout/CmsLayout.razor`, and `Components/Shared/` (all inlined from the former `DeepDrftCms` RCL). Public entry point: `Components/Pages/Home.razor` (`@page "/"`, no `[Authorize]`, uses lean `CmsHomeLayout`) — unauthenticated visitors see a DeepDrft-branded splash with a Login CTA; authenticated admins are redirected to `/catalogue` via `RedirectToCatalogue`. The catalogue dashboard (`Components/Pages/Index.razor`) lives at `@page "/catalogue"` and remains `[Authorize]`-gated with `CmsLayout`; its cards are **CUTS / SESSIONS / MIXES**, each deep-linking to `/releases?medium=<medium>` with the matching tab pre-selected. The consolidated browse surface is `Components/Pages/Tracks/Releases.razor` (`@page "/releases"`): bulk-action buttons (Generate All Profiles / Backfill High-res) → medium tab strip (ALL / CUTS / SESSIONS / MIXES) → the active tab's grid; waveform columns (Profile / High-res) — each showing a status icon when a datum is present and an always-visible generate/regenerate button — and per-track info tooltip live in `CmsAlbumBrowser`'s expanded child-row track table. Old list routes `/tracks`, `/tracks/albums`, `/tracks/archive` are kept as aliases on `Releases.razor` so bookmarks don't 404; operational sub-routes (`/tracks/upload`, edit routes, etc.) remain at `/tracks/*`. Gated by AuthBlocks login and hierarchical `Admin` role authorization. All track operations (upload, metadata read/write, delete) are HTTP proxies via `ICmsTrackService` / `CmsTrackService` injected directly into Blazor components; no in-process data layer. Two named HttpClients: `DeepDrft.Content.Cms` (bounded 100 s default, for all non-upload calls) and `DeepDrft.Content.Cms.Upload` (`InfiniteTimeSpan`, for large WAV uploads). Upload progress and idle/heartbeat timeout are driven by a single `ProgressStreamContent` wrapper (`Services/ProgressStreamContent.cs`); `CmsTrackService.UploadTrackAsync` adds a two-phase cancellation (idle window resets per progress tick; separate response-wait budget arms when the body completes).
|
||||
- **DeepDrftPublic.Client**: Blazor WebAssembly assembly. All interactive UI (pages, player stack, dark-mode plumbing, HTTP clients for both backends). Pages include the public `/about` editorial page (`Pages/About.razor` — three-movement **"Liner Notes"** editorial treatment: numbered left-rail (oversized Bodoni numerals + vertical hairline spine + mono marginalia captions), asymmetric content column, pull-quotes breaking into the margin, hand-authored SVG waveform movement dividers (self-contained motif, not the live `WaveformVisualizer`), and stacked editorial definition list for CUTS/SESSIONS/MIXES; active-movement highlight via `about-rail.ts` IntersectionObserver interop; registered in `Layout/Pages.cs`). Home hero stat row (`NowPlayingStats.razor`) is live-data-backed via `IStatsDataService` / `StatsClient` (named `"DeepDrft.API"` client) with a `PersistentComponentState` prerender bridge; `RuntimeFormat` helper converts mix runtime seconds to `hh:mm`. Consumed by the public site.
|
||||
- **DeepDrftManager**: ASP.NET Core host. Blazor Web App with server-rendered `InteractiveServer` render mode. Hosts all CMS Razor components and pages under `Components/Pages/Cms/`, `Components/Pages/Tracks/`, `Components/Layout/CmsLayout.razor`, and `Components/Shared/` (all inlined from the former `DeepDrftCms` RCL). Public entry point: `Components/Pages/Home.razor` (`@page "/"`, no `[Authorize]`, uses lean `CmsHomeLayout`) — unauthenticated visitors see a DeepDrft-branded splash with a Login CTA; authenticated admins are redirected to `/catalogue` via `RedirectToCatalogue`. The catalogue dashboard (`Components/Pages/Index.razor`) lives at `@page "/catalogue"` and remains `[Authorize]`-gated with `CmsLayout`; its cards are **CUTS / SESSIONS / MIXES**, each deep-linking to `/releases?medium=<medium>` with the matching tab pre-selected. The consolidated browse surface is `Components/Pages/Tracks/Releases.razor` (`@page "/releases"`): bulk-action buttons (Generate All Profiles / Backfill High-res) → medium tab strip (ALL / CUTS / SESSIONS / MIXES) → the active tab's grid; waveform columns (Profile / High-res) — each showing a status icon when a datum is present and an always-visible generate/regenerate button — and per-track info tooltip live in `CmsAlbumBrowser`'s expanded child-row track table. Old list routes `/tracks`, `/tracks/albums`, `/tracks/archive` are kept as aliases on `Releases.razor` so bookmarks don't 404; operational sub-routes (`/tracks/upload`, edit routes, etc.) remain at `/tracks/*`. Gated by AuthBlocks login and hierarchical `Admin` role authorization. All track operations (upload, metadata read/write, delete, replace audio) are HTTP proxies via `ICmsTrackService` / `CmsTrackService` injected directly into Blazor components; no in-process data layer. The per-track "Replace audio" affordance in `BatchEdit` / `BatchTrackList` / `BatchTrackDetail` swaps only the vault bytes + regenerates both waveform datums server-side; the track id, `EntryKey`, release membership, position, and all metadata are preserved. The remove control on a persisted track is hidden when it is the release's sole remaining persisted track — a release can reach zero live tracks only via replace or release-level delete, not per-track removal. Two named HttpClients: `DeepDrft.Content.Cms` (bounded 100 s default, for all non-upload calls) and `DeepDrft.Content.Cms.Upload` (`InfiniteTimeSpan`, for large WAV uploads). Upload progress and idle/heartbeat timeout are driven by a single `ProgressStreamContent` wrapper (`Services/ProgressStreamContent.cs`); `CmsTrackService.UploadTrackAsync` adds a two-phase cancellation (idle window resets per progress tick; separate response-wait budget arms when the body completes).
|
||||
- **DeepDrftShared.Client**: Razor Class Library. Shared Blazor components consumed by both `DeepDrftPublic` and `DeepDrftManager` for consistency across public and admin surfaces.
|
||||
- **DeepDrftData**: Class library. EF Core domain logic: `DeepDrftContext`, `TrackConfiguration`, `Migrations`, `TrackRepository`, `TrackService`, `TrackManager`. Consumed by `DeepDrftAPI` and tests.
|
||||
- **DeepDrftAPI**: ASP.NET Core host. Dual-database authority (SQL metadata + FileDatabase binary). AuthBlocks API host (owns registration, migration/seed, JWT endpoints). Track endpoints: streaming, vault write, upload+persist, delete+cleanup, paged list with filters, single metadata (ApiKey-gated operations), metadata update, waveform profiles (512-bucket seeker + per-track high-res visualizer datum in the `track-waveforms` vault), release-track join operations. Release endpoints: paged list with medium filter, single read, session hero-image upload (all unauthenticated reads; authenticated writes via ApiKey). Image endpoints: authenticated upload, unauthenticated streaming.
|
||||
- **DeepDrftAPI**: ASP.NET Core host. Dual-database authority (SQL metadata + FileDatabase binary). AuthBlocks API host (owns registration, migration/seed, JWT endpoints). Track endpoints: streaming, vault write, upload+persist, delete+cleanup, paged list with filters, single metadata (ApiKey-gated operations), metadata update, waveform profiles (512-bucket seeker + per-track high-res visualizer datum in the `track-waveforms` vault), release-track join operations, `POST api/track/duration/backfill` (ApiKey-gated one-time backfill of `DurationSeconds` for existing rows from vault audio). Stats endpoints: `GET api/stats/home` (unauthenticated; returns `HomeStatsDto` with cut track count, per-`ReleaseType` cut release counts, mix release count, and total mix runtime seconds). Release endpoints: paged list with medium filter, single read, session hero-image upload (all unauthenticated reads; authenticated writes via ApiKey). Image endpoints: authenticated upload, unauthenticated streaming.
|
||||
- **DeepDrftContent**: Class library. The FileDatabase implementation in full (Models, Services, Utils, Abstractions, Constants), `AudioProcessor`, content-side `TrackService`. Consumed by hosts and tests.
|
||||
- **DeepDrftModels**: Shared contracts. `TrackEntity`, `TrackDto`, `PagingParameters<T>`, `PagedResult<T>`. Every project references this.
|
||||
- **DeepDrftTests**: NUnit test suite. Comprehensive FileDatabase tests (vault creation, media storage, indexing, factory patterns, utilities). Integration-focused with temp-directory test isolation.
|
||||
@@ -34,7 +34,7 @@ Server-side (SSR): Both clients point directly at DeepDrftAPI (server-to-server,
|
||||
|
||||
1. **SQL Database (PostgreSQL)**: Metadata and track info via Entity Framework
|
||||
- Connection string: Read from `environment/connections.json` via `CredentialTools.ResolvePathOrThrow("connections")` with key `ConnectionStrings:DefaultConnection`.
|
||||
- Entity: `TrackEntity` with `Id`, `EntryKey`, `TrackName`, `Artist`, `Album?`, `Genre?`, `ReleaseDate?`, `ImagePath?`
|
||||
- Entity: `TrackEntity` with `Id`, `EntryKey`, `TrackName`, `Artist`, `Album?`, `Genre?`, `ReleaseDate?`, `ImagePath?`, `DurationSeconds?`
|
||||
- Context: `DeepDrftContext` in `DeepDrftData`
|
||||
|
||||
2. **FileDatabase**: Custom file-based binary storage system
|
||||
@@ -114,10 +114,10 @@ dotnet run --project DeepDrftAPI
|
||||
### Entity Framework (SQL Database)
|
||||
```bash
|
||||
# Add migration (from solution root)
|
||||
dotnet ef migrations add MigrationName --project DeepDrftData --startup-project DeepDrftPublic
|
||||
dotnet ef migrations add MigrationName --project DeepDrftData --startup-project DeepDrftAPI
|
||||
|
||||
# Update database
|
||||
dotnet ef database update --project DeepDrftData --startup-project DeepDrftPublic
|
||||
dotnet ef database update --project DeepDrftData --startup-project DeepDrftAPI
|
||||
```
|
||||
|
||||
## Key Configuration Files
|
||||
|
||||
@@ -6,6 +6,24 @@ Newest entries at the top. Group by phase/wave header (mirroring `PLAN.md` / `CM
|
||||
|
||||
---
|
||||
|
||||
## Home Hero Stats — Live data wiring (landed 2026-06-18)
|
||||
|
||||
**Landed:** 2026-06-18 on dev (commits `5f0422a` + `8fa330f`, merged `e9e6b60`).
|
||||
|
||||
- **What:** Replaced the hard-coded placeholder figures in the public home hero stat row (`NowPlayingStats`) with real SQL-backed aggregates. Resolves the "Real stat-row numbers" deferred item from Phase 0 §0.3.
|
||||
|
||||
- **Why:** The stat row ("47+ / 2 / ∞") was intentionally hard-coded at Phase 0 with a TODO; the data model now has enough shape (releases, medium discriminator, track–release join) to serve real numbers in a single efficient query.
|
||||
|
||||
- **Shape:**
|
||||
- **New SQL column:** `DurationSeconds` (`double?`, column `duration_seconds`) on `TrackEntity` and `TrackDto`. Populated at upload via the existing dual-database add flow (`TrackContentService` extracts duration from vault audio; `UnifiedTrackService` persists it to SQL). Migration `20260618155002_AddTrackDuration`. Configured in `TrackConfiguration`.
|
||||
- **New aggregate query:** `TrackRepository.GetHomeStatsAsync` → `HomeStatsDto` (new DTO in `DeepDrftModels/DTOs/`). Returns cut track count, per-`ReleaseType` cut release counts (zero-count types suppressed), mix release count, and total mix runtime seconds (null durations counted as 0; tracks under soft-deleted releases excluded). Surfaced via `ITrackService.GetHomeStats` on `TrackManager`.
|
||||
- **New API endpoints:** `GET api/stats/home` (`StatsController`, unauthenticated; returns `HomeStatsDto` bare) and `POST api/track/duration/backfill` (ApiKey-gated; one-time backfill of `DurationSeconds` for pre-existing rows from vault audio, delegated to `UnifiedTrackService.BackfillDurationsAsync`).
|
||||
- **New public proxy:** `StatsProxyController` in `DeepDrftPublic` mirrors `ReleaseProxyController`; forwards `GET api/stats/home` from the browser to DeepDrftAPI.
|
||||
- **New client surface:** `StatsClient` (`Clients/`, named `"DeepDrft.API"` client) + `IStatsDataService` / `StatsClientDataService` (`Services/`) registered scoped in `Startup.ConfigureDomainServices`. `RuntimeFormat` static helper (`Helpers/`) converts seconds to `hh:mm`.
|
||||
- **`NowPlayingStats.razor`:** now renders live data — Studio Cuts card (cut track count + zero-suppressed Single/EP/Album breakdown), Mixes card (`MixReleaseCount` "Sets" + `hh:mm` runtime), Plays card (static "XXX / Coming Soon" odometer placeholder). Uses `PersistentComponentState` to bridge the SSR prerender fetch across the WASM seam (only persists on a successful load).
|
||||
|
||||
---
|
||||
|
||||
## Phase 12 — About Page (public site editorial) (landed 2026-06-17)
|
||||
|
||||
**Landed:** 2026-06-17 on dev.
|
||||
|
||||
@@ -110,6 +110,16 @@ Admin backfill view: returns every track with flags indicating whether each wave
|
||||
- **Response**: `List<WaveformStatusDto>` with `TrackId`, `EntryKey`, `TrackName`, `HasProfile` (bool — 512-bucket player-bar seeker profile in `waveform-profiles` vault), and `HasHighRes` (bool — duration-derived high-res visualizer datum in `track-waveforms` vault).
|
||||
- Returns 200 on success. Returns 500 on query error.
|
||||
|
||||
### POST api/track/duration/backfill ([ApiKeyAuthorize])
|
||||
|
||||
Admin backfill: for every track whose `DurationSeconds` SQL column is still null, reads the `AudioBinary.Duration` from the vault and writes it to SQL. Idempotent — a re-run only touches still-null rows; rows that already have a value are skipped.
|
||||
|
||||
- **Header `ApiKey`**: required. Validated by `ApiKeyAuthenticationMiddleware`.
|
||||
- No request body.
|
||||
- Calls `UnifiedTrackService.BackfillDurationsAsync`. Lives on `TrackController` in the literal-route block (before `{trackId}` routes, so the segment is never treated as a trackId).
|
||||
- **Response**: `{ updated: int, skipped: int }` — counts of rows written vs. already-populated rows bypassed.
|
||||
- Returns 200 on success. Returns 500 if the backfill operation fails.
|
||||
|
||||
### DELETE api/track/release/{id:long} ([ApiKeyAuthorize])
|
||||
|
||||
Soft-delete a release row. Used by the albums browser to remove an orphaned release (one with no live tracks).
|
||||
@@ -160,6 +170,17 @@ Soft-delete a release row. Used by the albums browser to remove an orphaned rele
|
||||
- Calls `UnifiedTrackService.DeleteAsync`, which: looks up SQL row → deletes SQL row → deletes vault entry via EntryKey.
|
||||
- Returns 200 on success, 404 if track not found, 500 if deletion fails.
|
||||
|
||||
### POST api/track/{id:long}/replace-audio ([ApiKeyAuthorize])
|
||||
|
||||
**Authenticated endpoint.** Accepts a raw audio file upload (.wav, .mp3, .flac) as `multipart/form-data` and replaces the existing track's vault bytes in place, preserving the track id, `EntryKey`, SQL row (metadata/release/position), and release membership. Both waveform datums (512-bucket seeker profile + high-res visualizer datum) are regenerated after the swap; waveform regen failure is logged and swallowed — it does not fail the replace.
|
||||
|
||||
- **Header `ApiKey`**: required. Validated by `ApiKeyAuthenticationMiddleware`.
|
||||
- **Route parameter `id`** (long): the SQL track ID.
|
||||
- **Form field `audioFile`** (`IFormFile`, required): the replacement audio bytes. File name must end in `.wav`, `.mp3`, or `.flac`.
|
||||
- `[RequestSizeLimit(1 GB)]` + `[RequestFormLimits(MultipartBodyLengthLimit = 1 GB)]` mirror the upload ceiling. The body is streamed to a temp file (correct extension preserved for the audio processor), always deleted in a `finally` block.
|
||||
- Calls `UnifiedTrackService.ReplaceAudioAsync`, which: looks up SQL row by id → calls `TrackContentService.ReplaceTrackAudioAsync(entryKey, tempFilePath)` (registers new audio under the existing `EntryKey`; removes the stale backing file only on a cross-format swap, after the new write succeeds) → regenerates both waveform datums. SQL is not written.
|
||||
- Returns 200 on success. Returns 400 if the file is missing or the format is unsupported. Returns 404 if the track id is not found. Returns 500 if vault processing fails.
|
||||
|
||||
### GET api/track/page (unauthenticated)
|
||||
|
||||
Paged metadata list from SQL with optional filtering. Public browser data, same auth posture as `GET api/track/{id}`.
|
||||
@@ -272,6 +293,20 @@ Stores a hero image in the `images` vault and links it via `SessionMetadata.Hero
|
||||
- Validates MIME type (rejects unsupported types with `.bin` sentinel). Calls `UnifiedReleaseService.SetHeroImageAsync`.
|
||||
- Returns 200 on success. Returns 400 for missing file or unsupported MIME type. Returns 404 if release not found. Returns 500 on processing or vault failure.
|
||||
|
||||
## The stats endpoints
|
||||
|
||||
### GET api/stats/home (unauthenticated)
|
||||
|
||||
Aggregate figures behind the public home hero stat row (`NowPlayingStats`). A single read returns everything the three cards need so the client makes one round-trip. Public, same auth posture as `GET api/track/page`.
|
||||
|
||||
- **Response**: `HomeStatsDto` with:
|
||||
- `CutTrackCount` (int): total non-deleted tracks on Cut-medium releases.
|
||||
- `CutReleaseTypeCounts` (`List<CutReleaseTypeCount>`): per-`ReleaseType` Cut release counts; zero-count types are absent (zero-suppressed server-side).
|
||||
- `MixReleaseCount` (int): total non-deleted Mix-medium releases.
|
||||
- `MixRuntimeSeconds` (double): sum of `DurationSeconds` across all non-deleted tracks on Mix releases (null durations count as 0).
|
||||
- Aggregated in `TrackRepository.GetHomeStatsAsync`, surfaced via `ITrackService`/`TrackManager`. Controller is `StatsController` — a thin HTTP boundary; no domain logic lives there.
|
||||
- Returns 200 on success. Returns 500 on query error.
|
||||
|
||||
## ApiKey middleware behaviour
|
||||
|
||||
`ApiKeyAuthenticationMiddleware` runs on every request but only enforces on endpoints with `[ApiKeyAuthorize]` metadata.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using DeepDrftData;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DeepDrftAPI.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class StatsController : ControllerBase
|
||||
{
|
||||
private readonly ITrackService _sqlTrackService;
|
||||
private readonly ILogger<StatsController> _logger;
|
||||
|
||||
public StatsController(ITrackService sqlTrackService, ILogger<StatsController> logger)
|
||||
{
|
||||
_sqlTrackService = sqlTrackService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// GET api/stats/home (unauthenticated)
|
||||
// Aggregate figures behind the public home hero stat row — one read for all three cards. Same auth
|
||||
// posture as the other public browse reads (GET api/track/page). The aggregation lives in the SQL
|
||||
// service/repository; this controller stays a thin HTTP boundary.
|
||||
[HttpGet("home")]
|
||||
public async Task<ActionResult> GetHome(CancellationToken ct = default)
|
||||
{
|
||||
var result = await _sqlTrackService.GetHomeStats(ct);
|
||||
if (!result.Success || result.Value is null)
|
||||
{
|
||||
var error = result.Messages.FirstOrDefault()?.Message ?? "Unknown error";
|
||||
_logger.LogError("GetHome stats failed: {Error}", error);
|
||||
return StatusCode(500, "Failed to load stats");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
}
|
||||
@@ -173,6 +173,26 @@ public class TrackController : ControllerBase
|
||||
return Ok(status);
|
||||
}
|
||||
|
||||
// POST api/track/duration/backfill ([ApiKeyAuthorize], no body)
|
||||
// One-time admin backfill: for every track whose SQL duration is still null, read the duration from
|
||||
// the vault audio and write it to SQL. Mirrors the waveform backfill posture. Idempotent — a re-run
|
||||
// only touches still-missing rows. Returns { updated, skipped }. Declared in the literal-route block
|
||||
// (before "{trackId}") so the segment is never treated as a trackId.
|
||||
[ApiKeyAuthorize]
|
||||
[HttpPost("duration/backfill")]
|
||||
public async Task<ActionResult> BackfillDurations(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _unifiedService.BackfillDurationsAsync(cancellationToken);
|
||||
if (!result.Success)
|
||||
{
|
||||
var error = result.Messages.FirstOrDefault()?.Message ?? "Unknown error";
|
||||
_logger.LogError("BackfillDurations failed: {Error}", error);
|
||||
return StatusCode(500, error);
|
||||
}
|
||||
|
||||
return Ok(new { updated = result.Value.Updated, skipped = result.Value.Skipped });
|
||||
}
|
||||
|
||||
// POST api/track/upload: raw audio in (multipart/form-data) + metadata → persisted TrackDto out.
|
||||
// Accepts .wav, .mp3, and .flac. Used by the CMS upload flow on DeepDrftManager; that host
|
||||
// proxies the upload here so it never touches the vault disk path or SQL directly.
|
||||
@@ -479,6 +499,86 @@ public class TrackController : ControllerBase
|
||||
return StatusCode(500, error);
|
||||
}
|
||||
|
||||
// POST api/track/{id}/replace-audio ([ApiKeyAuthorize])
|
||||
// Swap an existing track's audio bytes from a raw upload, preserving the track's id, EntryKey,
|
||||
// release membership, position, and metadata. UnifiedTrackService.ReplaceAudioAsync owns the
|
||||
// vault swap + waveform regen; nothing in SQL is written. Mirrors the upload endpoint's temp-file
|
||||
// streaming and 1 GB ceiling (a WAV replace is a large-body upload like the original). The
|
||||
// literal "{id:long}/replace-audio" segment is declared in the literal-route block so it never
|
||||
// resolves to the parameterized "{trackId}" GET.
|
||||
[ApiKeyAuthorize]
|
||||
[HttpPost("{id:long}/replace-audio")]
|
||||
[RequestSizeLimit(1_073_741_824)]
|
||||
[RequestFormLimits(MultipartBodyLengthLimit = 1_073_741_824)]
|
||||
public async Task<ActionResult> ReplaceAudio(
|
||||
long id,
|
||||
[FromForm] IFormFile? audioFile,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("ReplaceAudio called: id={Id}, size={Size}", id, audioFile?.Length);
|
||||
|
||||
if (audioFile is null || audioFile.Length == 0)
|
||||
{
|
||||
return BadRequest("Audio file is required");
|
||||
}
|
||||
|
||||
var uploadExtension = Path.GetExtension(audioFile.FileName).ToLowerInvariant();
|
||||
if (uploadExtension is not (".wav" or ".mp3" or ".flac"))
|
||||
{
|
||||
return BadRequest("Uploaded file must have a .wav, .mp3, or .flac extension");
|
||||
}
|
||||
|
||||
// The processor router selects by extension and reads from disk, so the temp file must carry
|
||||
// the upload's real extension. Mirrors UploadTrack — Path.GetTempFileName() yields .tmp.
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + uploadExtension);
|
||||
|
||||
try
|
||||
{
|
||||
await using (var tempStream = new FileStream(
|
||||
tempPath, FileMode.CreateNew, FileAccess.Write, FileShare.None,
|
||||
bufferSize: 81920, useAsync: true))
|
||||
await using (var uploadStream = audioFile.OpenReadStream())
|
||||
{
|
||||
await uploadStream.CopyToAsync(tempStream, cancellationToken);
|
||||
}
|
||||
|
||||
var result = await _unifiedService.ReplaceAudioAsync(id, tempPath, cancellationToken);
|
||||
if (result.Success)
|
||||
{
|
||||
_logger.LogInformation("ReplaceAudio succeeded: id={Id}", id);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
var error = result.Messages.FirstOrDefault()?.Message ?? "Failed to replace audio";
|
||||
if (string.Equals(error, UnifiedTrackService.TrackNotFoundMessage, StringComparison.Ordinal))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_logger.LogError("ReplaceAudio failed for id {Id}: {Error}", id, error);
|
||||
return StatusCode(500, error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "ReplaceAudio failed for id {Id}", id);
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (System.IO.File.Exists(tempPath))
|
||||
{
|
||||
System.IO.File.Delete(tempPath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "ReplaceAudio: failed to delete temp file {TempPath}", tempPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE api/track/release/{id} ([ApiKeyAuthorize])
|
||||
// Soft-delete a release row directly. Used by the albums browser to remove an orphaned release
|
||||
// (one with no live tracks). "release" is a literal segment, declared here in the literal-route
|
||||
|
||||
@@ -166,6 +166,55 @@ public class UnifiedTrackService
|
||||
return saveResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace an existing track's audio in place: look up the SQL row, swap only the vault bytes
|
||||
/// keyed by its EntryKey, then regenerate both waveform datums from the new audio. Track id,
|
||||
/// EntryKey, release membership, track number, and all metadata are preserved — nothing in SQL
|
||||
/// is written. The waveform regen is best-effort (a missing datum renders as a flat seekbar /
|
||||
/// blank visualizer downstream), so a datum failure is logged and swallowed rather than failing
|
||||
/// the replace. No release-cardinality cascade applies: the track count is unchanged, so the
|
||||
/// single-track-Mix case stays intact.
|
||||
/// </summary>
|
||||
public async Task<Result> ReplaceAudioAsync(long trackId, string tempFilePath, CancellationToken ct)
|
||||
{
|
||||
var lookup = await _sqlTrackService.GetById(trackId);
|
||||
if (!lookup.Success)
|
||||
{
|
||||
var error = lookup.Messages.FirstOrDefault()?.Message ?? "unknown error";
|
||||
_logger.LogError("ReplaceAudioAsync: GetById failed for track {TrackId}: {Error}", trackId, error);
|
||||
return Result.CreateFailResult("Failed to load track.");
|
||||
}
|
||||
|
||||
if (lookup.Value is null)
|
||||
{
|
||||
return Result.CreateFailResult(TrackNotFoundMessage);
|
||||
}
|
||||
|
||||
var entryKey = lookup.Value.EntryKey;
|
||||
|
||||
var newAudio = await _contentTrackContentService.ReplaceTrackAudioAsync(entryKey, tempFilePath);
|
||||
if (newAudio is null)
|
||||
{
|
||||
_logger.LogWarning("ReplaceAudioAsync: content swap returned null for track {TrackId} ({EntryKey})", trackId, entryKey);
|
||||
return Result.CreateFailResult("Failed to process and store the replacement audio.");
|
||||
}
|
||||
|
||||
// The old waveform no longer matches the new bytes. Regenerate both datums in place; keyed
|
||||
// by the same EntryKey, the re-run overwrites the stale data (proven re-runnable). The
|
||||
// freshly stored buffer is the authoritative source — no re-read of the vault needed.
|
||||
try
|
||||
{
|
||||
await _waveformProfileService.ComputeAndStoreAsync(newAudio.Buffer, entryKey);
|
||||
await _waveformProfileService.ComputeAndStoreHighResAsync(newAudio.Buffer, entryKey, newAudio.Duration);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
{
|
||||
_logger.LogError(ex, "ReplaceAudioAsync: waveform regen failed for {EntryKey}; replace unaffected.", entryKey);
|
||||
}
|
||||
|
||||
return Result.CreatePassResult();
|
||||
}
|
||||
|
||||
// Compute and store both waveform datums for a freshly uploaded track: the fixed 512-bucket profile
|
||||
// the player-bar seeker consumes, and the duration-derived high-res datum the lava visualizer
|
||||
// consumes (phase-12 §5 — every track now carries one, computed at upload). Both source the same
|
||||
@@ -193,6 +242,54 @@ public class UnifiedTrackService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One-time backfill: for every non-deleted track whose SQL duration is still null, read the
|
||||
/// processor-extracted runtime from the vault audio (by EntryKey) and write it to SQL. The migration
|
||||
/// cannot read the vault, so this runs at runtime after deploy. Idempotent — a re-run only touches
|
||||
/// rows still missing a duration. Returns (updated, skipped) counts. A per-track vault miss or SQL
|
||||
/// failure is logged and skipped, never aborting the batch.
|
||||
/// </summary>
|
||||
public async Task<ResultContainer<(int Updated, int Skipped)>> BackfillDurationsAsync(CancellationToken ct)
|
||||
{
|
||||
var missing = await _sqlTrackService.GetTracksMissingDuration(ct);
|
||||
if (!missing.Success || missing.Value is null)
|
||||
{
|
||||
var error = missing.Messages.FirstOrDefault()?.Message ?? "Unknown error";
|
||||
_logger.LogError("BackfillDurationsAsync: failed to load tracks missing duration: {Error}", error);
|
||||
return ResultContainer<(int, int)>.CreateFailResult($"Could not load tracks: {error}");
|
||||
}
|
||||
|
||||
var updated = 0;
|
||||
var skipped = 0;
|
||||
foreach (var track in missing.Value)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
|
||||
var audio = await _contentTrackContentService.GetAudioBinaryAsync(track.EntryKey);
|
||||
if (audio is null)
|
||||
{
|
||||
_logger.LogWarning("BackfillDurationsAsync: no vault audio for {EntryKey} (track {Id}); skipping.",
|
||||
track.EntryKey, track.Id);
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
var write = await _sqlTrackService.UpdateDuration(track.Id, audio.Duration, ct);
|
||||
if (!write.Success)
|
||||
{
|
||||
var error = write.Messages.FirstOrDefault()?.Message ?? "Unknown error";
|
||||
_logger.LogWarning("BackfillDurationsAsync: SQL update failed for track {Id}: {Error}", track.Id, error);
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
updated++;
|
||||
}
|
||||
|
||||
_logger.LogInformation("BackfillDurationsAsync complete: {Updated} updated, {Skipped} skipped.", updated, skipped);
|
||||
return ResultContainer<(int, int)>.CreatePassResult((updated, skipped));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a track's SQL row, then its vault entry. SQL is the source of truth: a SQL delete
|
||||
/// failure fails the operation (and leaves the vault untouched), but a subsequent vault delete
|
||||
|
||||
@@ -74,7 +74,10 @@ public class TrackContentService
|
||||
{
|
||||
EntryKey = trackId, // FileDatabase entry ID
|
||||
TrackName = trackName,
|
||||
OriginalFileName = originalFileName
|
||||
OriginalFileName = originalFileName,
|
||||
// Persist the processor-extracted runtime to SQL so aggregate queries (total mix runtime)
|
||||
// need not touch the vault. Same value the high-res waveform compute reads downstream.
|
||||
DurationSeconds = audioBinary.Duration
|
||||
};
|
||||
|
||||
return trackEntity;
|
||||
@@ -100,6 +103,84 @@ public class TrackContentService
|
||||
string? originalFileName = null) =>
|
||||
AddTrackAsync(wavFilePath, trackName, artist, album, genre, releaseDate, originalFileName);
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the audio bytes for an existing track in place: processes a new audio file and
|
||||
/// re-registers it under the SAME <paramref name="entryKey"/> in the tracks vault. The track's
|
||||
/// vault key — and therefore its SQL link, release membership, position, and metadata — is
|
||||
/// untouched; only the binary changes. The new audio is written first; only on confirmed success
|
||||
/// is a stale old backing file cleaned up. A cross-format replacement (e.g. .wav → .flac) leaves
|
||||
/// the old file on disk under its former filename once the index is updated; the post-success
|
||||
/// cleanup removes it. For a same-extension overwrite the register alone suffices — the file is
|
||||
/// written in place. If the register fails the original audio is left intact and null is returned,
|
||||
/// so the track remains playable. Returns the freshly stored <see cref="AudioBinary"/> on success
|
||||
/// (so the caller can regenerate waveform data from the same bytes) — matching the FileDatabase
|
||||
/// swallow-and-return-null contract.
|
||||
/// </summary>
|
||||
public async Task<AudioBinary?> ReplaceTrackAudioAsync(string entryKey, string audioFilePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Capture the old extension before touching the vault. After register the index
|
||||
// will point to the new extension, so we need the old value now to detect a
|
||||
// cross-format swap and clean up the stale file post-success.
|
||||
var existing = await _fileDatabase.LoadResourceAsync<AudioBinary>(VaultConstants.Tracks, entryKey);
|
||||
var oldExtension = existing?.Extension;
|
||||
|
||||
var audioBinary = await _audioProcessorRouter.ProcessAudioFileAsync(audioFilePath);
|
||||
if (audioBinary == null)
|
||||
{
|
||||
Console.WriteLine($"TrackContentService.ReplaceTrackAudioAsync: processing returned null for {entryKey}");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!_fileDatabase.HasVault(VaultConstants.Tracks))
|
||||
{
|
||||
await _fileDatabase.CreateVaultAsync(VaultConstants.Tracks, MediaVaultType.Audio);
|
||||
}
|
||||
|
||||
// Register the new audio. This upserts the index entry (new extension recorded) and
|
||||
// writes the new file to disk. If this fails the original entry and file are untouched.
|
||||
var success = await _fileDatabase.RegisterResourceAsync(VaultConstants.Tracks, entryKey, audioBinary);
|
||||
if (!success)
|
||||
{
|
||||
Console.WriteLine($"TrackContentService.ReplaceTrackAudioAsync: vault write failed for {entryKey}; original audio preserved");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Post-success stale-file cleanup for cross-format swaps. The register wrote the new
|
||||
// file (e.g. .flac) and updated the index to the new extension, but the old backing
|
||||
// file (e.g. .wav) is now unreferenced on disk. Delete it directly by constructing the
|
||||
// old path — RemoveResourceAsync would now resolve to the new extension and delete the
|
||||
// wrong file. Non-fatal: an orphaned old file is a disk-hygiene concern, not a
|
||||
// playback issue (the index no longer references it).
|
||||
if (oldExtension != null && oldExtension != audioBinary.Extension)
|
||||
{
|
||||
var vault = _fileDatabase.GetVault(VaultConstants.Tracks);
|
||||
if (vault != null)
|
||||
{
|
||||
var sanitizedKey = System.Text.RegularExpressions.Regex.Replace(entryKey, @"[^a-zA-Z0-9]", "-");
|
||||
var staleFilePath = Path.Combine(vault.RootPath, $"{sanitizedKey}{oldExtension}");
|
||||
try
|
||||
{
|
||||
if (File.Exists(staleFilePath))
|
||||
File.Delete(staleFilePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"TrackContentService.ReplaceTrackAudioAsync: stale backing-file removal failed for {entryKey} ({staleFilePath}): {ex.Message} — new audio is live; orphaned file may remain on disk");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return audioBinary;
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
{
|
||||
Console.WriteLine($"TrackContentService.ReplaceTrackAudioAsync failed: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves audio binary from FileDatabase
|
||||
/// </summary>
|
||||
|
||||
@@ -42,6 +42,7 @@ DeepDrftData/
|
||||
- `Album`, `Genre`: optional, max 200 / 100
|
||||
- `ReleaseDate`: optional `DateOnly`
|
||||
- `ImagePath`: optional, max 500 (currently a free-form URL string; points to images vault in future)
|
||||
- `DurationSeconds`: optional `double?` (nullable; populated at upload from vault audio; backfillable via `POST api/track/duration/backfill`; used for aggregate mix-runtime queries). Column: `duration_seconds`. Migration: `20260618155002_AddTrackDuration`.
|
||||
|
||||
## Service → Repository → DbContext shape
|
||||
|
||||
@@ -49,6 +50,10 @@ DeepDrftData/
|
||||
- **Repository** (`TrackRepository`): Internal data access. Queries the DbContext. Throws on error (service catches).
|
||||
- **DbContext** (`DeepDrftContext`): EF Core. Directly accessed by repository, never by service (pattern isolation).
|
||||
|
||||
Notable repository / service methods beyond the standard CRUD:
|
||||
|
||||
- `TrackRepository.GetHomeStatsAsync` / `ITrackService.GetHomeStats`: Returns `HomeStatsDto` — cut track count, per-`ReleaseType` cut release counts (zero-suppressed), mix release count, total mix runtime seconds (null durations counted as 0; tracks under a soft-deleted release excluded). Used by `StatsController`.
|
||||
|
||||
Example:
|
||||
|
||||
```csharp
|
||||
@@ -117,10 +122,10 @@ Run from the solution root:
|
||||
|
||||
```bash
|
||||
# Add a migration
|
||||
dotnet ef migrations add MigrationName --project DeepDrftData --startup-project DeepDrftPublic
|
||||
dotnet ef migrations add MigrationName --project DeepDrftData --startup-project DeepDrftAPI
|
||||
|
||||
# Apply to database
|
||||
dotnet ef database update --project DeepDrftData --startup-project DeepDrftPublic
|
||||
dotnet ef database update --project DeepDrftData --startup-project DeepDrftAPI
|
||||
```
|
||||
|
||||
The design-time factory means you can also run `dotnet ef ... --project DeepDrftData` standalone for local development (it doesn't need the startup project).
|
||||
|
||||
@@ -39,6 +39,10 @@ public class TrackConfiguration : BaseEntityConfiguration<TrackEntity>
|
||||
.HasColumnName("track_number")
|
||||
.HasDefaultValue(1);
|
||||
|
||||
// Nullable: existing rows carry NULL until the one-time duration backfill populates them.
|
||||
builder.Property(e => e.DurationSeconds)
|
||||
.HasColumnName("duration_seconds");
|
||||
|
||||
builder.Property(e => e.ReleaseId)
|
||||
.HasColumnName("release_id");
|
||||
|
||||
|
||||
@@ -28,6 +28,25 @@ public interface ITrackService
|
||||
/// <summary>Distinct non-null genres with track counts, genre-ascending.</summary>
|
||||
Task<ResultContainer<List<GenreSummaryDto>>> GetDistinctGenres(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate figures behind the public home hero stat row: Cut track count + per-ReleaseType Cut
|
||||
/// release breakdown, Mix release count, and total Mix runtime in seconds. One read for all three cards.
|
||||
/// </summary>
|
||||
Task<ResultContainer<HomeStatsDto>> GetHomeStats(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Non-deleted tracks whose SQL duration is still null — the work list for the one-time duration
|
||||
/// backfill. The backfill reads each track's stored duration from the vault and writes it via
|
||||
/// <see cref="UpdateDuration"/>.
|
||||
/// </summary>
|
||||
Task<ResultContainer<List<TrackDto>>> GetTracksMissingDuration(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Set the SQL duration for one track. Idempotent: a track whose duration is already set is left
|
||||
/// untouched. Backs the duration backfill. Returns the number of rows updated (0 or 1).
|
||||
/// </summary>
|
||||
Task<ResultContainer<int>> UpdateDuration(long id, double durationSeconds, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Resolve the release matching <paramref name="title"/> + <paramref name="artist"/>, creating
|
||||
/// one from <paramref name="releaseData"/> when none exists. Backs the upload flow's FK
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DeepDrftData.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DeepDrftData.Migrations
|
||||
{
|
||||
[DbContext(typeof(DeepDrftContext))]
|
||||
[Migration("20260618155002_AddTrackDuration")]
|
||||
partial class AddTrackDuration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.MixMetadata", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<long>("ReleaseId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("release_id");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.Property<string>("WaveformEntryKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("character varying(500)")
|
||||
.HasColumnName("waveform_entry_key");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IsDeleted")
|
||||
.HasDatabaseName("IX_mix_metadata_is_deleted");
|
||||
|
||||
b.HasIndex("ReleaseId")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_mix_metadata_release_id");
|
||||
|
||||
b.ToTable("mix_metadata", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.ReleaseEntity", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<string>("Artist")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("character varying(200)")
|
||||
.HasColumnName("artist");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedByUserId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by_user_id");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("description");
|
||||
|
||||
b.Property<string>("EntryKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("entry_key");
|
||||
|
||||
b.Property<string>("Genre")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("genre");
|
||||
|
||||
b.Property<string>("ImagePath")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("character varying(500)")
|
||||
.HasColumnName("image_path");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<string>("Medium")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasDefaultValue("Cut")
|
||||
.HasColumnName("medium");
|
||||
|
||||
b.Property<DateOnly?>("ReleaseDate")
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("release_date");
|
||||
|
||||
b.Property<string>("ReleaseType")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasDefaultValue("Single")
|
||||
.HasColumnName("release_type");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("character varying(200)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EntryKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_release_entry_key");
|
||||
|
||||
b.HasIndex("IsDeleted")
|
||||
.HasDatabaseName("IX_release_is_deleted");
|
||||
|
||||
b.HasIndex("Title", "Artist")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_release_title_artist")
|
||||
.HasFilter("\"is_deleted\" = false");
|
||||
|
||||
b.ToTable("release", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.SessionMetadata", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("HeroImageEntryKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("character varying(500)")
|
||||
.HasColumnName("hero_image_entry_key");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<long>("ReleaseId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("release_id");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IsDeleted")
|
||||
.HasDatabaseName("IX_session_metadata_is_deleted");
|
||||
|
||||
b.HasIndex("ReleaseId")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_session_metadata_release_id");
|
||||
|
||||
b.ToTable("session_metadata", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.TrackEntity", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<double?>("DurationSeconds")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("duration_seconds");
|
||||
|
||||
b.Property<string>("EntryKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("entry_key");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<string>("OriginalFileName")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("character varying(500)")
|
||||
.HasColumnName("original_file_name");
|
||||
|
||||
b.Property<long?>("ReleaseId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("release_id");
|
||||
|
||||
b.Property<string>("TrackName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("character varying(200)")
|
||||
.HasColumnName("track_name");
|
||||
|
||||
b.Property<int>("TrackNumber")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasColumnName("track_number");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IsDeleted")
|
||||
.HasDatabaseName("IX_track_is_deleted");
|
||||
|
||||
b.HasIndex("ReleaseId");
|
||||
|
||||
b.ToTable("track", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.MixMetadata", b =>
|
||||
{
|
||||
b.HasOne("DeepDrftModels.Entities.ReleaseEntity", "Release")
|
||||
.WithOne("MixMetadata")
|
||||
.HasForeignKey("DeepDrftModels.Entities.MixMetadata", "ReleaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Release");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.SessionMetadata", b =>
|
||||
{
|
||||
b.HasOne("DeepDrftModels.Entities.ReleaseEntity", "Release")
|
||||
.WithOne("SessionMetadata")
|
||||
.HasForeignKey("DeepDrftModels.Entities.SessionMetadata", "ReleaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Release");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.TrackEntity", b =>
|
||||
{
|
||||
b.HasOne("DeepDrftModels.Entities.ReleaseEntity", "Release")
|
||||
.WithMany("Tracks")
|
||||
.HasForeignKey("ReleaseId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Release");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DeepDrftModels.Entities.ReleaseEntity", b =>
|
||||
{
|
||||
b.Navigation("MixMetadata");
|
||||
|
||||
b.Navigation("SessionMetadata");
|
||||
|
||||
b.Navigation("Tracks");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DeepDrftData.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddTrackDuration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<double>(
|
||||
name: "duration_seconds",
|
||||
table: "track",
|
||||
type: "double precision",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "duration_seconds",
|
||||
table: "track");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,6 +222,10 @@ namespace DeepDrftData.Migrations
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<double?>("DurationSeconds")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("duration_seconds");
|
||||
|
||||
b.Property<string>("EntryKey")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
|
||||
@@ -3,6 +3,7 @@ using Data.Errors;
|
||||
using DeepDrftData.Data;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Models.Common;
|
||||
@@ -157,6 +158,58 @@ public class TrackRepository : Repository<DeepDrftContext, TrackEntity>
|
||||
.Select(g => new { ReleaseId = g.Key, Count = g.Count() })
|
||||
.ToDictionaryAsync(x => x.ReleaseId, x => x.Count, ct);
|
||||
|
||||
// Aggregate figures for the public home hero stat row, assembled in as few round-trips as is clean.
|
||||
// All counts go through Query (!t.IsDeleted) plus an explicit !t.Release.IsDeleted guard so tracks
|
||||
// under a directly-deleted release are also excluded. Mix runtime sums DurationSeconds with a
|
||||
// null-coalesce to 0 so not-yet-backfilled rows contribute zero rather than throwing or skewing the
|
||||
// total. The cut release-type breakdown is grouped here so a zero-count type is simply absent from
|
||||
// the result (no present-with-zero row).
|
||||
public async Task<HomeStatsDto> GetHomeStatsAsync(CancellationToken ct = default)
|
||||
{
|
||||
var releases = _context.Set<ReleaseEntity>().Where(r => !r.IsDeleted);
|
||||
|
||||
var cutTrackCount = await Query
|
||||
.CountAsync(t => t.Release != null && !t.Release.IsDeleted && t.Release.Medium == ReleaseMedium.Cut, ct);
|
||||
|
||||
var cutReleaseTypeCounts = await releases
|
||||
.Where(r => r.Medium == ReleaseMedium.Cut)
|
||||
.GroupBy(r => r.ReleaseType)
|
||||
.Select(g => new CutReleaseTypeCount { ReleaseType = g.Key, Count = g.Count() })
|
||||
.ToListAsync(ct);
|
||||
|
||||
var mixReleaseCount = await releases
|
||||
.CountAsync(r => r.Medium == ReleaseMedium.Mix, ct);
|
||||
|
||||
var mixRuntimeSeconds = await Query
|
||||
.Where(t => t.Release != null && !t.Release.IsDeleted && t.Release.Medium == ReleaseMedium.Mix)
|
||||
.SumAsync(t => t.DurationSeconds ?? 0d, ct);
|
||||
|
||||
return new HomeStatsDto
|
||||
{
|
||||
CutTrackCount = cutTrackCount,
|
||||
CutReleaseTypeCounts = cutReleaseTypeCounts,
|
||||
MixReleaseCount = mixReleaseCount,
|
||||
MixRuntimeSeconds = mixRuntimeSeconds,
|
||||
};
|
||||
}
|
||||
|
||||
// EntryKey + stored duration for non-deleted tracks whose SQL duration is still null — the work list
|
||||
// the one-time duration backfill iterates. The migration cannot read the vault, so duration is filled
|
||||
// at runtime: this lists which rows still need it, the backfill reads each from the vault and writes
|
||||
// it back via UpdateDurationAsync.
|
||||
public async Task<List<TrackEntity>> GetTracksMissingDurationAsync(CancellationToken ct = default)
|
||||
=> await Query.Where(t => t.DurationSeconds == null).ToListAsync(ct);
|
||||
|
||||
// Set-based duration write for one track (no load round-trip), used by the backfill. The
|
||||
// DurationSeconds == null guard keeps a re-run from re-stamping updated_at on an already-filled row
|
||||
// and from clobbering a value the upload path may have set in the meantime.
|
||||
public async Task<int> UpdateDurationAsync(long id, double durationSeconds, CancellationToken ct = default)
|
||||
=> await Query
|
||||
.Where(t => t.Id == id && t.DurationSeconds == null)
|
||||
.ExecuteUpdateAsync(s => s
|
||||
.SetProperty(t => t.DurationSeconds, durationSeconds)
|
||||
.SetProperty(t => t.UpdatedAt, DateTime.UtcNow), ct);
|
||||
|
||||
// Resolve an existing release by its natural key (title + artist). Returns null when no match,
|
||||
// signalling the manager to create one. Soft-deleted releases never match.
|
||||
public async Task<ReleaseEntity?> GetReleaseByTitleAndArtistAsync(
|
||||
@@ -211,6 +264,7 @@ public class TrackRepository : Repository<DeepDrftContext, TrackEntity>
|
||||
target.TrackName = source.TrackName;
|
||||
target.TrackNumber = source.TrackNumber;
|
||||
target.OriginalFileName = source.OriginalFileName;
|
||||
target.DurationSeconds = source.DurationSeconds;
|
||||
target.ReleaseId = source.ReleaseId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public class TrackConverter : IEntityToModelConverter<TrackEntity, TrackDto>
|
||||
TrackName = entity.TrackName,
|
||||
OriginalFileName = entity.OriginalFileName,
|
||||
TrackNumber = entity.TrackNumber,
|
||||
DurationSeconds = entity.DurationSeconds,
|
||||
ReleaseId = entity.ReleaseId,
|
||||
Release = entity.Release is null ? null : Convert(entity.Release)
|
||||
};
|
||||
@@ -96,6 +97,7 @@ public class TrackConverter : IEntityToModelConverter<TrackEntity, TrackDto>
|
||||
TrackName = model.TrackName,
|
||||
OriginalFileName = model.OriginalFileName,
|
||||
TrackNumber = model.TrackNumber,
|
||||
DurationSeconds = model.DurationSeconds,
|
||||
ReleaseId = model.ReleaseId
|
||||
};
|
||||
}
|
||||
|
||||
@@ -236,6 +236,46 @@ public class TrackManager
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<HomeStatsDto>> GetHomeStats(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var stats = await Repository.GetHomeStatsAsync(cancellationToken);
|
||||
return ResultContainer<HomeStatsDto>.CreatePassResult(stats);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultContainer<HomeStatsDto>.CreateFailResult(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<List<TrackDto>>> GetTracksMissingDuration(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entities = await Repository.GetTracksMissingDurationAsync(cancellationToken);
|
||||
return ResultContainer<List<TrackDto>>.CreatePassResult(
|
||||
entities.Select(TrackConverter.Convert).ToList());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultContainer<List<TrackDto>>.CreateFailResult(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<int>> UpdateDuration(long id, double durationSeconds, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var updated = await Repository.UpdateDurationAsync(id, durationSeconds, cancellationToken);
|
||||
return ResultContainer<int>.CreatePassResult(updated);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultContainer<int>.CreateFailResult(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<TrackDto>> Create(TrackDto newTrack)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<MudStack AlignItems="AlignItems.Center" Spacing="4" Class="my-8">
|
||||
<MudImage Fluid="true" Src="img/cms-hero.png" Alt="Deep Drft" />
|
||||
<MudText Typo="Typo.h2" Align="Align.Center">Deep Drft</MudText>
|
||||
<MudImage Fluid="true" Src="img/cms-hero.webp" Alt="Deep Drft" />
|
||||
<MudText Typo="Typo.subtitle1" Align="Align.Center" Class="text-uppercase mud-text-secondary">
|
||||
Catalogue Management
|
||||
</MudText>
|
||||
|
||||
@@ -59,14 +59,19 @@
|
||||
single-track medium, mirroring BatchUpload's same-named collapse. Cut keeps the full list. *@
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="5">
|
||||
@* ExistingTrackCount counts edit-session persisted rows (Id.HasValue), not authoritative
|
||||
live release count — acceptable because this gate only hides a UI control; the
|
||||
TrySoftDeleteEmptyReleaseAsync backstop remains the authoritative guard. *@
|
||||
<BatchTrackList Tracks="_tracks"
|
||||
@bind-SelectedIndex="_selectedIndex"
|
||||
Disabled="_saving"
|
||||
AllowNewTracks="@(_medium == ReleaseMedium.Cut)"
|
||||
ExistingTrackCount="@_tracks.Count(t => t.Id.HasValue)"
|
||||
OnWavFilesSelected="HandleWavFilesSelected"
|
||||
OnMoveUp="MoveUp"
|
||||
OnMoveDown="MoveDown"
|
||||
OnRemove="RemoveRow" />
|
||||
OnRemove="RemoveRow"
|
||||
OnReplaceFileSelected="HandleReplaceFileSelected" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" md="7">
|
||||
@@ -322,6 +327,85 @@
|
||||
if (_selectedIndex >= _tracks.Count) _selectedIndex = _tracks.Count - 1;
|
||||
}
|
||||
|
||||
private async Task HandleReplaceFileSelected((int Index, IBrowserFile File) picked)
|
||||
{
|
||||
var (index, file) = picked;
|
||||
if (index < 0 || index >= _tracks.Count) return;
|
||||
|
||||
var row = _tracks[index];
|
||||
if (!row.Id.HasValue)
|
||||
{
|
||||
// Defensive: replace is only offered on persisted rows. A new row would have no track to
|
||||
// swap against — it takes the upload path on save instead.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.Name.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Snackbar.Add($"'{file.Name}' is not a .wav file.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var confirmed = await DialogService.ShowMessageBox(
|
||||
"Replace audio",
|
||||
$"Replace the audio for '{row.TrackName}' with '{file.Name}'? " +
|
||||
"Metadata stays the same; the waveform is regenerated for the new audio.",
|
||||
yesText: "Replace", cancelText: "Cancel");
|
||||
if (confirmed != true) return;
|
||||
|
||||
row.Status = BatchRowStatus.Uploading;
|
||||
row.UploadedBytes = 0;
|
||||
row.TotalBytes = file.Size;
|
||||
row.ErrorMessage = null;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
await using var wavStream = file.OpenReadStream(MaxUploadBytes);
|
||||
|
||||
var lastPercent = -1;
|
||||
var progress = new Progress<long>(written =>
|
||||
{
|
||||
row.UploadedBytes = written;
|
||||
if (row.UploadPercent != lastPercent)
|
||||
{
|
||||
lastPercent = row.UploadPercent;
|
||||
StateHasChanged();
|
||||
}
|
||||
});
|
||||
|
||||
var result = await CmsTrackService.ReplaceTrackAudioAsync(
|
||||
row.Id.Value, wavStream, file.Size, file.Name, file.ContentType, progress);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
var error = result.Messages.FirstOrDefault()?.Message ?? "Unknown error";
|
||||
row.Status = BatchRowStatus.Failed;
|
||||
row.ErrorMessage = error;
|
||||
Snackbar.Add($"Replace failed: {error}", Severity.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reset to Queued (not Done): a Done row is skipped by SaveAsync, but the admin may
|
||||
// still want to save pending metadata edits. The audio swap is already persisted.
|
||||
row.Status = BatchRowStatus.Queued;
|
||||
row.OriginalFileName = file.Name;
|
||||
Snackbar.Add($"Replaced audio for '{row.TrackName}'.", Severity.Success);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Replace audio failed for track id {Id}", row.Id);
|
||||
row.Status = BatchRowStatus.Failed;
|
||||
row.ErrorMessage = "Replace failed — please try again.";
|
||||
Snackbar.Add("Replace failed — please try again.", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveCover()
|
||||
{
|
||||
// Defer the actual clear to save: pass "" to UpdateAsync's tri-state imagePath. Nulling
|
||||
|
||||
@@ -21,7 +21,7 @@ else
|
||||
{
|
||||
<MudField Label="Original File" Variant="Variant.Outlined" InnerPadding="false">
|
||||
<MudText Typo="Typo.body2">@(string.IsNullOrEmpty(SelectedTrack.OriginalFileName) ? "—" : SelectedTrack.OriginalFileName)</MudText>
|
||||
<MudText Typo="Typo.caption" Color="Color.Default">Existing track — audio is not editable.</MudText>
|
||||
<MudText Typo="Typo.caption" Color="Color.Default">Use the Replace audio action in the list to swap this track's audio.</MudText>
|
||||
</MudField>
|
||||
}
|
||||
else
|
||||
|
||||
@@ -34,12 +34,37 @@
|
||||
Disabled="@(index == Tracks.Count - 1 || Disabled)"
|
||||
OnClick="@(() => OnMoveDown.InvokeAsync(index))"
|
||||
aria-label="Move track down" />
|
||||
@* Replace audio: existing (persisted) rows only. New rows still pick their WAV
|
||||
via the file input above, so a replace control there would be redundant. A
|
||||
native <label for> drives a per-row hidden InputFile — clicking the icon
|
||||
opens that row's picker with zero JS (no eval, no programmatic .click()). *@
|
||||
@if (row.Id.HasValue)
|
||||
{
|
||||
<label for="@ReplaceInputId(index)" @onclick:stopPropagation="true"
|
||||
style="display: inline-flex; @(Disabled ? "pointer-events: none; opacity: 0.5;" : "cursor: pointer;")">
|
||||
<MudIcon Icon="@Icons.Material.Filled.SwapHoriz"
|
||||
Color="Color.Primary"
|
||||
Size="Size.Small"
|
||||
aria-label="Replace audio" />
|
||||
</label>
|
||||
<InputFile id="@ReplaceInputId(index)"
|
||||
OnChange="@(e => OnReplaceFileSelected.InvokeAsync((index, e.File)))"
|
||||
accept=".wav,audio/wav,audio/x-wav"
|
||||
disabled="@Disabled"
|
||||
style="display: none;" />
|
||||
}
|
||||
@* Remove: hidden for the sole remaining persisted track so a release can never
|
||||
be track-deleted down to zero (that path soft-deletes the whole release). New
|
||||
rows are always removable — dropping one only discards a pending upload. *@
|
||||
@if (!(row.Id.HasValue && ExistingTrackCount <= 1))
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||
Color="Color.Error"
|
||||
Size="Size.Small"
|
||||
Disabled="@Disabled"
|
||||
OnClick="@(() => OnRemove.InvokeAsync(index))"
|
||||
aria-label="Remove track" />
|
||||
}
|
||||
</MudStack>
|
||||
@if (row.Status == BatchRowStatus.Uploading)
|
||||
{
|
||||
@@ -60,11 +85,28 @@
|
||||
[Parameter] public EventCallback<int> SelectedIndexChanged { get; set; }
|
||||
[Parameter] public bool Disabled { get; set; }
|
||||
[Parameter] public bool AllowNewTracks { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Count of existing (persisted, Id-bearing) tracks in the list. When this is 1, the remove
|
||||
/// control on the sole persisted row is suppressed so a release cannot be track-deleted to zero
|
||||
/// (replace + release-level delete remain). New unsaved rows are excluded from this count.
|
||||
/// </summary>
|
||||
[Parameter] public int ExistingTrackCount { get; set; }
|
||||
|
||||
[Parameter] public EventCallback<IReadOnlyList<IBrowserFile>> OnWavFilesSelected { get; set; }
|
||||
[Parameter] public EventCallback<int> OnMoveUp { get; set; }
|
||||
[Parameter] public EventCallback<int> OnMoveDown { get; set; }
|
||||
[Parameter] public EventCallback<int> OnRemove { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the admin picks a replacement WAV for an existing row, carrying the list index and
|
||||
/// the chosen file. Only fired for persisted (Id-bearing) rows.
|
||||
/// </summary>
|
||||
[Parameter] public EventCallback<(int Index, IBrowserFile File)> OnReplaceFileSelected { get; set; }
|
||||
|
||||
// Stable per-row DOM id linking the swap-icon <label> to its hidden InputFile.
|
||||
private static string ReplaceInputId(int index) => $"replace-audio-input-{index}";
|
||||
|
||||
private const int MaxFilesPerPick = 50;
|
||||
|
||||
private Task SelectRow(int index) => SelectedIndexChanged.InvokeAsync(index);
|
||||
|
||||
@@ -71,54 +71,11 @@ public class CmsTrackService : ICmsTrackService
|
||||
IProgress<long>? progress = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
// Two-phase cancellation for the upload send:
|
||||
//
|
||||
// BODY-STREAMING phase (while bytes are on the wire):
|
||||
// idleCts fires if no progress tick arrives within the idle window. Each
|
||||
// ProgressStreamContent chunk resets CancelAfter(idle), so a slow-but-moving
|
||||
// upload never trips it; a genuinely stalled socket does.
|
||||
//
|
||||
// RESPONSE-WAIT phase (after the last byte, while the server persists):
|
||||
// The idle heartbeat goes silent once the body is fully sent. responseCts is
|
||||
// armed at that moment with a larger budget so a fully-uploaded file is never
|
||||
// killed mid-persist. idleCts is simultaneously disarmed (CancelAfter(Infinite))
|
||||
// so it cannot misfire during the response-wait.
|
||||
//
|
||||
// sendCts links both so either deadline — plus the caller's ct — cancels the send.
|
||||
using var idleCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
idleCts.CancelAfter(_uploadIdleTimeout);
|
||||
// Build the WAV part once; the two-phase send helper owns the cancellation plumbing.
|
||||
using var phase = new UploadPhase(this, ct);
|
||||
var wavContent = phase.WrapContent(wavStream, contentLength, contentType, progress);
|
||||
|
||||
// responseCts starts disarmed; the body-complete callback below arms it.
|
||||
using var responseCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
|
||||
// Umbrella token passed to SendAsync — either phase token (or the caller) can cancel.
|
||||
using var sendCts = CancellationTokenSource.CreateLinkedTokenSource(idleCts.Token, responseCts.Token);
|
||||
|
||||
// Rebuild the multipart container so the boundary is owned by HttpClient and the
|
||||
// caller-supplied stream (already buffered by the SignalR upload) is the source.
|
||||
using var multipart = new MultipartFormDataContent();
|
||||
var wavContent = new ProgressStreamContent(
|
||||
wavStream,
|
||||
contentLength,
|
||||
written =>
|
||||
{
|
||||
// One mechanism, three consumers: advance the UI meter, reset the idle heartbeat,
|
||||
// and on body-complete transition to the response-wait budget.
|
||||
progress?.Report(written);
|
||||
if (written < contentLength)
|
||||
{
|
||||
// Body still in flight — keep the idle heartbeat alive.
|
||||
idleCts.CancelAfter(_uploadIdleTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Last byte on the wire. Disarm the idle timer and start the response budget.
|
||||
idleCts.CancelAfter(Timeout.InfiniteTimeSpan);
|
||||
responseCts.CancelAfter(_uploadResponseTimeout);
|
||||
}
|
||||
});
|
||||
wavContent.Headers.ContentType = new MediaTypeHeaderValue(
|
||||
string.IsNullOrWhiteSpace(contentType) ? "audio/wav" : contentType);
|
||||
multipart.Add(wavContent, "audioFile", fileName);
|
||||
multipart.Add(new StringContent(trackName), "trackName");
|
||||
multipart.Add(new StringContent(artist), "artist");
|
||||
@@ -135,36 +92,10 @@ public class CmsTrackService : ICmsTrackService
|
||||
// for an unrecognised value). Authoritative only when this upload creates the release.
|
||||
multipart.Add(new StringContent(medium.ToString()), "medium");
|
||||
|
||||
// Use the dedicated upload client (InfiniteTimeSpan) so the two-phase CTS logic above is the
|
||||
// sole timeout authority. Non-upload operations use the bounded "DeepDrft.Content.Cms" client.
|
||||
var client = _httpClientFactory.CreateClient(UploadClientName);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, UploadPath) { Content = multipart };
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
var send = await phase.SendAsync(UploadPath, multipart, $"upload of {trackName}");
|
||||
if (send.Response is not { } response)
|
||||
{
|
||||
response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, sendCts.Token);
|
||||
}
|
||||
catch (OperationCanceledException) when (!ct.IsCancellationRequested)
|
||||
{
|
||||
// Either idle window (body-streaming stall) or response-wait budget (server persist too slow).
|
||||
if (idleCts.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogWarning("Upload of {TrackName} stalled — no progress for {IdleSeconds}s; aborting.",
|
||||
trackName, _uploadIdleTimeout.TotalSeconds);
|
||||
return ResultContainer<TrackDto>.CreateFailResult(
|
||||
$"Upload stalled — no data transferred for {_uploadIdleTimeout.TotalSeconds:0}s. Please retry.");
|
||||
}
|
||||
// responseCts fired: body reached the server but persist timed out.
|
||||
_logger.LogWarning("Upload of {TrackName} timed out waiting for server response after {ResponseSeconds}s.",
|
||||
trackName, _uploadResponseTimeout.TotalSeconds);
|
||||
return ResultContainer<TrackDto>.CreateFailResult(
|
||||
$"Upload timed out waiting for the server to respond after {_uploadResponseTimeout.TotalSeconds:0}s. Please retry.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for upload of {TrackName}", trackName);
|
||||
return ResultContainer<TrackDto>.CreateFailResult("Content API is unreachable.");
|
||||
return ResultContainer<TrackDto>.CreateFailResult(send.FailureMessage!);
|
||||
}
|
||||
|
||||
using (response)
|
||||
@@ -208,6 +139,172 @@ public class CmsTrackService : ICmsTrackService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result> ReplaceTrackAudioAsync(
|
||||
long id,
|
||||
Stream wavStream,
|
||||
long contentLength,
|
||||
string fileName,
|
||||
string contentType,
|
||||
IProgress<long>? progress = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
// Same two-phase send plumbing as UploadTrackAsync — a WAV replace is an equally large body.
|
||||
// The request carries only the audio part; the server resolves the track by route id and
|
||||
// preserves its metadata, so no metadata fields ride along.
|
||||
using var phase = new UploadPhase(this, ct);
|
||||
var wavContent = phase.WrapContent(wavStream, contentLength, contentType, progress);
|
||||
|
||||
using var multipart = new MultipartFormDataContent();
|
||||
multipart.Add(wavContent, "audioFile", fileName);
|
||||
|
||||
var send = await phase.SendAsync($"api/track/{id}/replace-audio", multipart, $"replace of track {id}");
|
||||
if (send.Response is not { } response)
|
||||
{
|
||||
return Result.CreateFailResult(send.FailureMessage!);
|
||||
}
|
||||
|
||||
using (response)
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Result.CreatePassResult();
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return Result.CreateFailResult("Track not found.");
|
||||
}
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync(ct);
|
||||
var statusCode = (int)response.StatusCode;
|
||||
if (statusCode >= 500)
|
||||
{
|
||||
_logger.LogError("Content API returned {Status} for replace of track {TrackId}: {Body}", statusCode, id, body);
|
||||
return Result.CreateFailResult("Replace failed on the content server. Please try again.");
|
||||
}
|
||||
|
||||
// 4xx: body is user-friendly validation text from DeepDrftAPI — relay as-is.
|
||||
_logger.LogWarning("Content API rejected replace of track {TrackId}: {Status} {Body}", id, statusCode, body);
|
||||
return Result.CreateFailResult(
|
||||
string.IsNullOrWhiteSpace(body) ? $"Replace rejected ({statusCode})." : body);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owns the two-phase cancellation for a large-body multipart send (the original upload and the
|
||||
/// audio replace share it identically):
|
||||
///
|
||||
/// BODY-STREAMING phase (while bytes are on the wire): the idle CTS fires if no progress tick
|
||||
/// arrives within the idle window. Each <see cref="ProgressStreamContent"/> chunk resets it, so a
|
||||
/// slow-but-moving body never trips it; a genuinely stalled socket does.
|
||||
///
|
||||
/// RESPONSE-WAIT phase (after the last byte, while the server persists): the idle heartbeat goes
|
||||
/// silent, so a separate, larger budget is armed at body-complete and the idle timer is disarmed,
|
||||
/// guaranteeing a fully-sent body is never killed mid-persist.
|
||||
///
|
||||
/// The send CTS links both phase tokens plus the caller's token. Single-sourcing this here keeps
|
||||
/// the idle/response-wait behaviour identical across every large-body call.
|
||||
/// </summary>
|
||||
private sealed class UploadPhase : IDisposable
|
||||
{
|
||||
private readonly CmsTrackService _owner;
|
||||
private readonly CancellationToken _callerToken;
|
||||
private readonly CancellationTokenSource _idleCts;
|
||||
private readonly CancellationTokenSource _responseCts;
|
||||
private readonly CancellationTokenSource _sendCts;
|
||||
|
||||
public UploadPhase(CmsTrackService owner, CancellationToken callerToken)
|
||||
{
|
||||
_owner = owner;
|
||||
_callerToken = callerToken;
|
||||
_idleCts = CancellationTokenSource.CreateLinkedTokenSource(callerToken);
|
||||
_idleCts.CancelAfter(owner._uploadIdleTimeout);
|
||||
// responseCts starts disarmed; the body-complete callback arms it.
|
||||
_responseCts = CancellationTokenSource.CreateLinkedTokenSource(callerToken);
|
||||
_sendCts = CancellationTokenSource.CreateLinkedTokenSource(_idleCts.Token, _responseCts.Token);
|
||||
}
|
||||
|
||||
public ProgressStreamContent WrapContent(
|
||||
Stream wavStream, long contentLength, string contentType, IProgress<long>? progress)
|
||||
{
|
||||
var content = new ProgressStreamContent(
|
||||
wavStream,
|
||||
contentLength,
|
||||
written =>
|
||||
{
|
||||
// One mechanism, three consumers: advance the UI meter, reset the idle heartbeat,
|
||||
// and on body-complete transition to the response-wait budget.
|
||||
progress?.Report(written);
|
||||
if (written < contentLength)
|
||||
{
|
||||
_idleCts.CancelAfter(_owner._uploadIdleTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Last byte on the wire. Disarm the idle timer and start the response budget.
|
||||
_idleCts.CancelAfter(Timeout.InfiniteTimeSpan);
|
||||
_responseCts.CancelAfter(_owner._uploadResponseTimeout);
|
||||
}
|
||||
});
|
||||
content.Headers.ContentType = new MediaTypeHeaderValue(
|
||||
string.IsNullOrWhiteSpace(contentType) ? "audio/wav" : contentType);
|
||||
return content;
|
||||
}
|
||||
|
||||
public async Task<LargeBodySendResult> SendAsync(
|
||||
string path, HttpContent content, string operationLabel)
|
||||
{
|
||||
// Dedicated upload client (InfiniteTimeSpan) so the two-phase CTS logic is the sole timeout
|
||||
// authority. Non-upload operations use the bounded "DeepDrft.Content.Cms" client.
|
||||
var client = _owner._httpClientFactory.CreateClient(UploadClientName);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, path) { Content = content };
|
||||
|
||||
try
|
||||
{
|
||||
var response = await client.SendAsync(
|
||||
request, HttpCompletionOption.ResponseHeadersRead, _sendCts.Token);
|
||||
return LargeBodySendResult.Ok(response);
|
||||
}
|
||||
catch (OperationCanceledException) when (!_callerToken.IsCancellationRequested)
|
||||
{
|
||||
if (_idleCts.IsCancellationRequested)
|
||||
{
|
||||
_owner._logger.LogWarning("{Operation} stalled — no progress for {IdleSeconds}s; aborting.",
|
||||
operationLabel, _owner._uploadIdleTimeout.TotalSeconds);
|
||||
return LargeBodySendResult.Fail(
|
||||
$"{operationLabel} stalled — no data transferred for {_owner._uploadIdleTimeout.TotalSeconds:0}s. Please retry.");
|
||||
}
|
||||
_owner._logger.LogWarning("{Operation} timed out waiting for server response after {ResponseSeconds}s.",
|
||||
operationLabel, _owner._uploadResponseTimeout.TotalSeconds);
|
||||
return LargeBodySendResult.Fail(
|
||||
$"{operationLabel} timed out waiting for the server to respond after {_owner._uploadResponseTimeout.TotalSeconds:0}s. Please retry.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_owner._logger.LogError(ex, "Content API call failed for {Operation}", operationLabel);
|
||||
return LargeBodySendResult.Fail("Content API is unreachable.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_sendCts.Dispose();
|
||||
_responseCts.Dispose();
|
||||
_idleCts.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Outcome of a two-phase send: either a live response the caller must dispose, or a user-facing
|
||||
// failure message. Exactly one is non-null.
|
||||
private readonly struct LargeBodySendResult
|
||||
{
|
||||
public HttpResponseMessage? Response { get; private init; }
|
||||
public string? FailureMessage { get; private init; }
|
||||
|
||||
public static LargeBodySendResult Ok(HttpResponseMessage response) => new() { Response = response };
|
||||
public static LargeBodySendResult Fail(string message) => new() { FailureMessage = message };
|
||||
}
|
||||
|
||||
public async Task<Result> DeleteTrackAsync(long id, CancellationToken ct = default)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
|
||||
@@ -51,6 +51,24 @@ public interface ICmsTrackService
|
||||
/// </summary>
|
||||
Task<Result> DeleteTrackAsync(long id, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Replace an existing track's audio via <c>POST api/track/{id}/replace-audio</c>. Swaps only the
|
||||
/// vault bytes and regenerates the track's waveform data server-side; the track id, vault key,
|
||||
/// release membership, position, and metadata are preserved. Uses the dedicated upload client and
|
||||
/// the same two-phase (idle / response-wait) cancellation as <see cref="UploadTrackAsync"/>, since
|
||||
/// a WAV replace is a large-body upload. <paramref name="contentLength"/> sets Content-Length and is
|
||||
/// the denominator for <paramref name="progress"/>; each progress tick resets the idle heartbeat.
|
||||
/// Maps a 404 to a "Track not found." failure.
|
||||
/// </summary>
|
||||
Task<Result> ReplaceTrackAudioAsync(
|
||||
long id,
|
||||
Stream wavStream,
|
||||
long contentLength,
|
||||
string fileName,
|
||||
string contentType,
|
||||
IProgress<long>? progress = null,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Soft-delete a release record via DELETE api/track/release/{id}. Use when a release
|
||||
/// has no live tracks and needs to be removed from the albums browser.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
@@ -15,7 +15,8 @@ DeepDrftModels/
|
||||
├── Entities/
|
||||
│ └── TrackEntity.cs # Database entity for tracks
|
||||
├── DTOs/
|
||||
│ └── TrackDto.cs # DTO mirror of TrackEntity
|
||||
│ ├── TrackDto.cs # DTO mirror of TrackEntity
|
||||
│ └── HomeStatsDto.cs # Aggregate figures for the public home hero stat row
|
||||
├── Models/
|
||||
│ ├── PagingParameters.cs # Pagination configuration (base + generic)
|
||||
│ └── PagedResult.cs # Paginated result wrapper
|
||||
@@ -35,6 +36,7 @@ public string? Album { get; set; } // Optional album (max 200)
|
||||
public string? Genre { get; set; } // Optional genre (max 100)
|
||||
public DateOnly? ReleaseDate { get; set; } // Optional release date
|
||||
public string? ImagePath { get; set; } // Optional image URL (max 500)
|
||||
public double? DurationSeconds { get; set; } // Audio runtime in seconds (nullable; populated at upload, backfilled for older rows)
|
||||
```
|
||||
|
||||
**No `MediaPath` field exists.** That was a legacy name. The field is `EntryKey`.
|
||||
@@ -47,6 +49,17 @@ Convention: required reference fields use `required` modifier; optional referenc
|
||||
|
||||
Mirrors `TrackEntity` structure (identical fields, same nullability). Used where DTO/entity separation is needed for serialisation. In practice, both flow over the wire today, but the separation is available if APIs need to diverge (e.g., hide `Id` in responses).
|
||||
|
||||
## HomeStatsDto
|
||||
|
||||
Aggregate figures behind the public home hero stat row (`NowPlayingStats`). A single round-trip returns everything the three cards need. Fields:
|
||||
|
||||
- `CutTrackCount` (int): total non-deleted tracks on Cut-medium releases.
|
||||
- `CutReleaseTypeCounts` (`List<CutReleaseTypeCount>`): per-`ReleaseType` Cut release counts; zero-count types are absent (suppressed server-side).
|
||||
- `MixReleaseCount` (int): total non-deleted Mix-medium releases.
|
||||
- `MixRuntimeSeconds` (double): sum of `DurationSeconds` across all non-deleted tracks on Mix releases (null durations count as 0). Rendered as `hh:mm` by `RuntimeFormat` on the client.
|
||||
|
||||
`CutReleaseTypeCount` is a nested type (`ReleaseType`, `Count` int) defined in the same file.
|
||||
|
||||
## Pagination system
|
||||
|
||||
### PagingParameters (base)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using DeepDrftModels.Enums;
|
||||
|
||||
namespace DeepDrftModels.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate figures behind the public home hero stat row (NowPlayingStats). A single read returns
|
||||
/// everything the three cards need so the client makes one round-trip. All counts exclude soft-deleted
|
||||
/// rows. The Plays card is a static placeholder and has no field here.
|
||||
/// </summary>
|
||||
public class HomeStatsDto
|
||||
{
|
||||
/// <summary>Total non-deleted tracks whose release is the Cut medium. The Studio Cuts card's primary figure.</summary>
|
||||
public int CutTrackCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Per-ReleaseType counts of non-deleted Cut releases. Only types with at least one release are
|
||||
/// present — a zero-count type is absent from the list (the card suppresses it). The Studio Cuts
|
||||
/// card's secondary breakdown.
|
||||
/// </summary>
|
||||
public List<CutReleaseTypeCount> CutReleaseTypeCounts { get; set; } = [];
|
||||
|
||||
/// <summary>Total non-deleted releases of the Mix medium. The Mixes card's primary figure ("N Sets").</summary>
|
||||
public int MixReleaseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sum of DurationSeconds across all non-deleted tracks on Mix releases. Tracks with a null
|
||||
/// duration (not yet backfilled) contribute 0. The Mixes card's secondary figure, rendered hh:mm.
|
||||
/// </summary>
|
||||
public double MixRuntimeSeconds { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>One row of the Cut release-type breakdown: a ReleaseType and how many Cut releases have it.</summary>
|
||||
public class CutReleaseTypeCount
|
||||
{
|
||||
public ReleaseType ReleaseType { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -16,6 +16,7 @@ public class TrackDto : BaseModel
|
||||
public string TrackName { get; set; } = string.Empty;
|
||||
public string? OriginalFileName { get; set; }
|
||||
public int TrackNumber { get; set; } = 1;
|
||||
public double? DurationSeconds { get; set; }
|
||||
public long? ReleaseId { get; set; }
|
||||
public ReleaseDto? Release { get; set; }
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ public class TrackEntity : BaseEntity, IEntity
|
||||
public required string TrackName { get; set; }
|
||||
public string? OriginalFileName { get; set; }
|
||||
public int TrackNumber { get; set; } = 1;
|
||||
// Audio runtime in seconds, extracted by the processor at upload (AudioBinary.Duration) and
|
||||
// persisted here so aggregate queries (e.g. total mix runtime) read it from SQL rather than the
|
||||
// vault. Nullable: rows that predate this column are valid until the one-time backfill populates them.
|
||||
public double? DurationSeconds { get; set; }
|
||||
public long? ReleaseId { get; set; }
|
||||
public ReleaseEntity? Release { get; set; }
|
||||
}
|
||||
|
||||
@@ -30,10 +30,12 @@ All interactive UI for the site. Blazor WebAssembly. Pages, controls, the stream
|
||||
- `WaveformVisualizerControlPopover.razor`: Pairs the lava-lamp icon button with `WaveformVisualizerControls` as a **screen-centered tinted modal** (Phase 15). The primitive is `MudOverlay` (`DarkBackground="true"`, `Modal="true"`) — **not** `MudPopover`; `AnchorOrigin`/`TransformOrigin` parameters do not exist (a centered modal has no anchor). Clicking the lava-lamp icon opens the overlay; clicking the scrim closes it (knob-drag-safe: `RadialKnob`'s `position:fixed` capture div sits above the scrim during a drag, so releasing outside the panel never fires the close handler). The panel stops click propagation so an inside click is not a dismissal. `[Parameter] Size IconSize` controls the trigger-icon size (default `Large`). This is the unit every host places — one icon anywhere gives the full control panel centered on screen, regardless of where the icon sits. Placed identically on Mix, Cut, Session, and the NowPlaying hero panel (full parity; in NowPlaying it sits in `.np-visualizer-controls` at the panel's top-right corner, not inside `NowPlayingCard`).
|
||||
- `WaveformZoomMapping.cs`: Maps the `WaveformVisualizerControlState.Resolution` fraction to an integer zoom level for the WebGL renderer.
|
||||
- `NowPlayingCard.razor`: Home-page text panel showing the currently playing track (label, title, sub-line). Renders label/"Now Playing" dot, track name, and artist·release sub-line from the cascaded `IStreamingPlayerService`. Subscribes to `IPlayerService.StateChanged` in `OnParametersSet` (reference-guarded, idempotent) and unsubscribes on dispose to re-render on track/state change. No visualizer or popover; those moved to `NowPlaying.razor`.
|
||||
- `NowPlayingStats.razor`: Home hero stat row. Three cards: Studio Cuts (total Cut-medium track count + zero-suppressed per-`ReleaseType` Cut release breakdown), Mixes (`MixReleaseCount` labelled "Sets" + `hh:mm` total mix runtime via `RuntimeFormat`), and Plays (static "XXX / Plays (Coming Soon)" odometer placeholder). Fetches `HomeStatsDto` via `IStatsDataService` on init; bridges the prerender fetch across the WASM seam with `PersistentComponentState` (persists only on a successful load, matching the medium-browse bridge pattern). Implements `IDisposable` to release the `PersistingComponentStateSubscription`.
|
||||
- `NowPlaying.razor`: Owns the home hero's right-side panel (`.now-playing-panel` — the outer wrapper formerly called `.hero-right` in `Home.razor`). Mounts `<WaveformVisualizer Fill="true">` as a full-bleed background inside `.np-visualizer-bg`, `<WaveformVisualizerControlPopover>` in `.np-visualizer-controls` (top-right corner), the three pulsing `.circle-deco` rings, and the content layer (hosts `<NowPlayingCard>` + `<NowPlayingStats>`). `Home.razor`'s `MudItem` renders `<NowPlaying />` directly with no wrapper. Subscribes to `IPlayerService.StateChanged` in `OnParametersSet` (reference-guarded, idempotent) and unsubscribes on dispose — needed because the player cascade is `IsFixed` (the provider's own re-render does not reach `NowPlaying`), so the subscription is the only way to re-render and re-propagate `ReleaseEntryKey`/`TrackId`/`TrackEntryKey` into `<WaveformVisualizer>` when the playing track changes.
|
||||
- `ReleaseDetailScaffold.razor`: Shared scaffold for release detail pages. Gained an optional `Ambient` `RenderFragment` slot (Phase 12) — a full-bleed layer rendered behind the main content. Absent slot = no regression. Cut mounts `<WaveformVisualizer>` + `<WaveformVisualizerControlPopover>` here; Mix uses its own full-bleed mount outside the scaffold.
|
||||
- `Helpers/`: Utilities and mapper functions.
|
||||
- `PlaybackIcons.cs`: Static `Resolve(isPlaying, isPaused, trackId, currentTrackId)` method — the sole glyph-mapping source for transport icons across all surfaces. Returns `(Icon, IsActive, IsPaused)` tuple.
|
||||
- `RuntimeFormat.cs`: Static `ToHoursMinutes(double totalSeconds)` helper. Formats a seconds value as `h:mm` (hours not zero-padded, minutes always two digits). Negative / non-finite inputs return `"0:00"`. Used by `NowPlayingStats` for the mix runtime figure.
|
||||
- `Services/`: Audio player + dark-mode services.
|
||||
- `IPlayerService` / `IStreamingPlayerService`: Contracts exposed to UI.
|
||||
- `AudioPlayerService`: Abstract base (lifecycle, initialise, select track, play/pause/stop/seek/volume).
|
||||
@@ -44,7 +46,9 @@ All interactive UI for the site. Blazor WebAssembly. Pages, controls, the stream
|
||||
- `Clients/`: HTTP API clients (both target DeepDrftAPI).
|
||||
- `TrackClient`: SQL metadata API. Uses named `IHttpClientFactory` client `"DeepDrft.API"`. Sends `page` param (not `pageNumber`). Deserializes response as bare `PagedResult<TrackDto>` (not wrapped in ApiResultDto envelope).
|
||||
- `TrackMediaClient`: Content API. Uses named `IHttpClientFactory` client `"DeepDrft.Content"`. Methods like `GetAudioStreamAsync(trackId, byteOffset?)` → `Stream` with optional Range header support for seek-beyond-buffer.
|
||||
- `StatsClient`: Home stats API. Uses named `IHttpClientFactory` client `"DeepDrft.API"`. Single method `GetHomeStats()` → `ApiResult<HomeStatsDto>` (calls `GET api/stats/home`; response is a bare DTO, no `ApiResultDto` envelope). Registered scoped; consumed via `IStatsDataService`.
|
||||
- `Services/ITrackDataService`: Contract used by the visualizer bridge and other consumers. Includes `GetTrackWaveform(entryKey)` → high-res `WaveformProfileDto` (calls `GET api/track/{entryKey}/waveform/high-res`); used by `WaveformVisualizer` to re-fetch the datum on track change.
|
||||
- `Services/IStatsDataService` / `StatsClientDataService`: Home-stats read abstraction. `IStatsDataService.GetHomeStats()` → `ApiResult<HomeStatsDto>`. `StatsClientDataService` is the single implementation (delegates to `StatsClient`); registered scoped. Components inject `IStatsDataService` so they do not branch on render mode — mirrors `IReleaseDataService`.
|
||||
- `ViewModels/`: Component state.
|
||||
- `TracksViewModel`: Scoped. Holds current page, page size, sort column, descending flag. `SetPage(pageNumber)` calls `TrackClient.GetPageAsync` and updates. Registered in `Startup.ConfigureDomainServices`.
|
||||
- `TrackDetailViewModel`: Scoped. Holds loaded track, loading flag, not-found flag. `Load(entryKey)` fetches via `ITrackDataService` and resets all flags per call (prevents cross-navigation bleed). Registered in `Startup.ConfigureDomainServices`.
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using DeepDrftModels.DTOs;
|
||||
using NetBlocks.Models;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DeepDrftPublic.Client.Clients;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP client for the public stats read surface. Uses the named <c>"DeepDrft.API"</c> client like
|
||||
/// <see cref="TrackClient"/> and <see cref="ReleaseClient"/>: on WASM it points at the public host and
|
||||
/// proxies through <c>StatsProxyController</c>; on SSR prerender it points directly at DeepDrftAPI. The
|
||||
/// route is an unauthenticated read; the response deserializes as a bare DTO (no ApiResultDto envelope),
|
||||
/// matching the API's <c>Ok(value)</c> shape.
|
||||
/// </summary>
|
||||
public class StatsClient
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
private readonly HttpClient _http;
|
||||
|
||||
public StatsClient(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_http = httpClientFactory.CreateClient("DeepDrft.API");
|
||||
}
|
||||
|
||||
public async Task<ApiResult<HomeStatsDto>> GetHomeStats()
|
||||
{
|
||||
var response = await _http.GetAsync("api/stats/home");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return ApiResult<HomeStatsDto>.CreateFailResult($"HTTP {(int)response.StatusCode}");
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var stats = JsonSerializer.Deserialize<HomeStatsDto>(json, JsonOptions);
|
||||
|
||||
return stats is not null
|
||||
? ApiResult<HomeStatsDto>.CreatePassResult(stats)
|
||||
: ApiResult<HomeStatsDto>.CreateFailResult("Failed to deserialize response");
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@
|
||||
<div class="now-playing-content">
|
||||
<NowPlayingCard />
|
||||
|
||||
@* Stat row - hard-coded for now. TODO Phase 2: wire to real track count / identity model. *@
|
||||
@* Stat row — live aggregate figures (Cut track count + type breakdown, Mix sets + runtime);
|
||||
the Plays card is a static placeholder pending real play tracking. *@
|
||||
<NowPlayingStats />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,94 @@
|
||||
@using DeepDrftModels.DTOs
|
||||
@using DeepDrftModels.Enums
|
||||
@using DeepDrftPublic.Client.Helpers
|
||||
@using DeepDrftPublic.Client.Services
|
||||
@implements IDisposable
|
||||
|
||||
<div class="hero-stat-row">
|
||||
@* Studio Cuts — primary figure is the total Cut-medium track count; the secondary breakdown lists
|
||||
per-ReleaseType Cut release counts, zero-count types already suppressed server-side. *@
|
||||
<div class="hero-stat">
|
||||
<div class="hero-stat-num">47+</div>
|
||||
<div class="hero-stat-label">Live Sessions</div>
|
||||
<div class="hero-stat-num">@_stats.CutTrackCount</div>
|
||||
<div class="hero-stat-label">Studio Cuts</div>
|
||||
@if (_stats.CutReleaseTypeCounts.Count > 0)
|
||||
{
|
||||
<div class="hero-stat-breakdown">
|
||||
@foreach (var row in _stats.CutReleaseTypeCounts)
|
||||
{
|
||||
<span class="hero-stat-breakdown-item">@row.Count @PluralizeReleaseType(row.ReleaseType, row.Count)</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@* Mixes — primary figure is the Mix release count labelled "Sets"; the secondary figure is total
|
||||
mix runtime as hh:mm. *@
|
||||
<div class="hero-stat">
|
||||
<div class="hero-stat-num">2</div>
|
||||
<div class="hero-stat-label">Members</div>
|
||||
<div class="hero-stat-num">@_stats.MixReleaseCount</div>
|
||||
<div class="hero-stat-label">Sets</div>
|
||||
<div class="hero-stat-sub">@RuntimeFormat.ToHoursMinutes(_stats.MixRuntimeSeconds) runtime</div>
|
||||
</div>
|
||||
|
||||
@* Plays — static placeholder (real play/share tracking is a future phase). Odometer treatment over
|
||||
the existing card style; copy is placeholder pending sign-off. *@
|
||||
<div class="hero-stat">
|
||||
<div class="hero-stat-num">∞</div>
|
||||
<div class="hero-stat-label">Drift Points</div>
|
||||
<div class="hero-stat-num hero-stat-odometer">XXX</div>
|
||||
<div class="hero-stat-label">Plays (Coming Soon)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Inject] public required IStatsDataService StatsData { get; set; }
|
||||
[Inject] public required PersistentComponentState PersistentState { get; set; }
|
||||
|
||||
private const string PersistKey = "home-stats";
|
||||
|
||||
private HomeStatsDto _stats = new();
|
||||
private bool _loaded;
|
||||
private PersistingComponentStateSubscription _persistingSubscription;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_persistingSubscription = PersistentState.RegisterOnPersisting(Persist);
|
||||
|
||||
// Bridge the prerendered fetch across the prerender -> WASM seam so the WASM boot does not
|
||||
// re-fetch and flicker the figures (the TracksView persistent-state seam, applied to stats).
|
||||
if (PersistentState.TryTakeFromJson<HomeStatsDto>(PersistKey, out var restored) && restored is not null)
|
||||
{
|
||||
_stats = restored;
|
||||
_loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await StatsData.GetHomeStats();
|
||||
if (result is { Success: true, Value: { } stats })
|
||||
{
|
||||
_stats = stats;
|
||||
_loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only bridge a successful fetch. If prerender failed, persist nothing so the WASM pass re-fetches
|
||||
// rather than restoring zeros — mirrors the guard on the medium-browse persist path.
|
||||
private Task Persist()
|
||||
{
|
||||
if (_loaded)
|
||||
PersistentState.PersistAsJson(PersistKey, _stats);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static string PluralizeReleaseType(ReleaseType type, int count)
|
||||
{
|
||||
var label = type switch
|
||||
{
|
||||
ReleaseType.Single => "Single",
|
||||
ReleaseType.EP => "EP",
|
||||
ReleaseType.Album => "Album",
|
||||
_ => type.ToString()
|
||||
};
|
||||
// EP pluralizes as "EPs"; Single/Album take a plain trailing s.
|
||||
return count == 1 ? label : label + "s";
|
||||
}
|
||||
|
||||
public void Dispose() => _persistingSubscription.Dispose();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,42 @@
|
||||
margin-top: 0.4rem;
|
||||
}
|
||||
|
||||
/* Studio Cuts per-ReleaseType breakdown — mono caption rows below the label, reusing the label's
|
||||
palette so the card reads as one block. */
|
||||
.hero-stat-breakdown {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.hero-stat-breakdown-item {
|
||||
font-family: var(--deepdrft-font-mono);
|
||||
font-size: 0.58rem;
|
||||
letter-spacing: 0.12em;
|
||||
color: rgba(250, 250, 248, 0.55);
|
||||
}
|
||||
|
||||
/* Mixes runtime sub-figure — sits under the label, slightly brighter than the label caption. */
|
||||
.hero-stat-sub {
|
||||
font-family: var(--deepdrft-font-mono);
|
||||
font-size: 0.58rem;
|
||||
letter-spacing: 0.12em;
|
||||
color: rgba(250, 250, 248, 0.55);
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
/* Plays placeholder — a light 90s visitor-counter / odometer embellishment over the existing
|
||||
numeric treatment: monospace digits, boxed and tracked out like a mechanical counter. */
|
||||
.hero-stat-odometer {
|
||||
font-family: var(--deepdrft-font-mono);
|
||||
letter-spacing: 0.18em;
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
border: 1px solid rgba(250, 250, 248, 0.12);
|
||||
padding: 0.1rem 0.35rem;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
@media (max-width: 599px) {
|
||||
.hero-stat-row {
|
||||
flex-direction: column;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace DeepDrftPublic.Client.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Formats a runtime expressed in seconds as a compact <c>hh:mm</c> string for the home hero stat row.
|
||||
/// Hours are not zero-padded and may exceed two digits (mixes are few, so a large total simply renders
|
||||
/// "123:45"); minutes are always two digits. Negative or non-finite inputs clamp to "0:00".
|
||||
/// </summary>
|
||||
public static class RuntimeFormat
|
||||
{
|
||||
public static string ToHoursMinutes(double totalSeconds)
|
||||
{
|
||||
if (double.IsNaN(totalSeconds) || double.IsInfinity(totalSeconds) || totalSeconds <= 0)
|
||||
return "0:00";
|
||||
|
||||
var total = TimeSpan.FromSeconds(totalSeconds);
|
||||
var hours = (int)total.TotalHours;
|
||||
return $"{hours}:{total.Minutes:D2}";
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,21 @@
|
||||
@* Desktop Menu *@
|
||||
<div class="d-none d-sm-flex">
|
||||
<nav class="@NavClass">
|
||||
<a class="dd-nav-brand" href="/">Deep DRFT</a>
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
<a class="dd-nav-brand" href="/">
|
||||
<MudImage Src="img/deepdrft-logo-l.webp"
|
||||
Alt="Deep Drft Ornamental Logo Left"
|
||||
Width="24"
|
||||
Height="24 "/>
|
||||
|
||||
<span class="mx-2">Deep DRFT</span>
|
||||
|
||||
<MudImage Src="img/deepdrft-logo-r.webp"
|
||||
Alt="Deep Drft Ornamental Logo Right"
|
||||
Width="24"
|
||||
Height="24 "/>
|
||||
</a>
|
||||
</MudStack>
|
||||
|
||||
<ul class="dd-nav-links">
|
||||
@foreach (var navPage in Pages.MenuPages)
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
/* Brand */
|
||||
.dd-nav-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-family: var(--deepdrft-font-mono);
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.22em;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using DeepDrftModels.DTOs;
|
||||
using NetBlocks.Models;
|
||||
|
||||
namespace DeepDrftPublic.Client.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Home-stats read abstraction. Both SSR and WASM renders are served by <c>StatsClientDataService</c>
|
||||
/// in this assembly, which delegates to <see cref="Clients.StatsClient"/> over HTTP. Components inject
|
||||
/// this single seam so they do not branch on render mode — mirrors <see cref="IReleaseDataService"/>.
|
||||
/// </summary>
|
||||
public interface IStatsDataService
|
||||
{
|
||||
/// <summary>Aggregate figures behind the public home hero stat row, in one round-trip.</summary>
|
||||
Task<ApiResult<HomeStatsDto>> GetHomeStats();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftPublic.Client.Clients;
|
||||
using NetBlocks.Models;
|
||||
|
||||
namespace DeepDrftPublic.Client.Services;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IStatsDataService"/> backed by <see cref="StatsClient"/> (HTTP to the <c>DeepDrft.API</c>
|
||||
/// backend). Used on both the SSR prerender and WASM interactive passes — the stats read surface is
|
||||
/// HTTP-only, so there is no separate in-process implementation.
|
||||
/// </summary>
|
||||
public class StatsClientDataService : IStatsDataService
|
||||
{
|
||||
private readonly StatsClient _statsClient;
|
||||
|
||||
public StatsClientDataService(StatsClient statsClient)
|
||||
{
|
||||
_statsClient = statsClient;
|
||||
}
|
||||
|
||||
public Task<ApiResult<HomeStatsDto>> GetHomeStats() => _statsClient.GetHomeStats();
|
||||
}
|
||||
@@ -26,6 +26,10 @@ public static class Startup
|
||||
services.AddScoped<ReleaseDetailViewModel>();
|
||||
services.AddScoped<CutDetailViewModel>();
|
||||
|
||||
// Home hero stats read surface — same HTTP posture as the track/release clients.
|
||||
services.AddScoped<StatsClient>();
|
||||
services.AddScoped<IStatsDataService, StatsClientDataService>();
|
||||
|
||||
// Waveform visualizer controls — scoped so the eight slider positions persist across navigation
|
||||
// within a session and reset on a fresh page load (see WaveformVisualizerControlState).
|
||||
services.AddScoped<WaveformVisualizerControlState>();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DeepDrftPublic.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Proxies the public stats read surface to DeepDrftAPI so the browser never makes a cross-origin
|
||||
/// request. Mirrors <see cref="ReleaseProxyController"/>: the WASM client issues relative
|
||||
/// <c>api/stats/*</c> requests against this host, which forwards them upstream. SSR prerender calls
|
||||
/// DeepDrftAPI directly via the same named client — no proxy hop on the server side. Unauthenticated read.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/stats")]
|
||||
public class StatsProxyController : ControllerBase
|
||||
{
|
||||
private readonly HttpClient _upstream;
|
||||
private readonly ILogger<StatsProxyController> _logger;
|
||||
|
||||
public StatsProxyController(IHttpClientFactory httpClientFactory, ILogger<StatsProxyController> logger)
|
||||
{
|
||||
_upstream = httpClientFactory.CreateClient("DeepDrft.API");
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>Proxies the home hero aggregate figures. Small JSON, buffered and relayed.</summary>
|
||||
[HttpGet("home")]
|
||||
public async Task<ActionResult> GetHome(CancellationToken ct = default)
|
||||
{
|
||||
HttpResponseMessage upstream;
|
||||
try
|
||||
{
|
||||
upstream = await _upstream.GetAsync("api/stats/home", HttpCompletionOption.ResponseHeadersRead, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Upstream call to DeepDrftAPI stats/home failed");
|
||||
return StatusCode(502, "Upstream unavailable");
|
||||
}
|
||||
|
||||
using (upstream)
|
||||
{
|
||||
if (!upstream.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning("DeepDrftAPI stats/home returned {Status}", (int)upstream.StatusCode);
|
||||
return StatusCode((int)upstream.StatusCode);
|
||||
}
|
||||
|
||||
var json = await upstream.Content.ReadAsStringAsync(ct);
|
||||
return Content(json, "application/json");
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 39 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* knob - pointer capture helpers for RadialKnob.
|
||||
*
|
||||
* setPointerCapture / releasePointerCapture are not exposed via Blazor's
|
||||
* ElementReference, so the component delegates here via JS interop.
|
||||
* Both functions are no-ops when the element reference is stale (e.g. the
|
||||
* component was disposed between the JS call and the microtask).
|
||||
*/
|
||||
/** Capture the pointer on the given element so pointermove/pointerup are
|
||||
* delivered even when the cursor leaves the browser window. */
|
||||
export function capturePointer(el, pointerId) {
|
||||
el.setPointerCapture(pointerId);
|
||||
}
|
||||
/** Release a previously captured pointer. Called on pointercancel.
|
||||
* pointerup releases capture implicitly, but we call this on cancel too. */
|
||||
export function releasePointer(el, pointerId) {
|
||||
el.releasePointerCapture(pointerId);
|
||||
}
|
||||
//# sourceMappingURL=/js/knob/knob.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"knob.js","sourceRoot":"/Interop/","sources":["knob/knob.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;gEACgE;AAChE,MAAM,UAAU,cAAc,CAAC,EAAW,EAAE,SAAiB;IACxD,EAAkB,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;AACrD,CAAC;AAED;6EAC6E;AAC7E,MAAM,UAAU,cAAc,CAAC,EAAW,EAAE,SAAiB;IACxD,EAAkB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;AACzD,CAAC"}
|
||||
@@ -0,0 +1,182 @@
|
||||
using Data.Data.Repositories;
|
||||
using DeepDrftData.Data;
|
||||
using DeepDrftData.Repositories;
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace DeepDrftTests;
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate-query tests for the public home hero stat row, exercising
|
||||
/// <see cref="TrackRepository.GetHomeStatsAsync"/>: the Cut track count, the per-ReleaseType Cut
|
||||
/// release breakdown (zero-count types absent), the Mix release count, and the Mix-runtime sum
|
||||
/// (null durations contributing 0). Runs on the EF in-memory provider like
|
||||
/// <see cref="ReleaseBrowseQueryTests"/> — every predicate here (Count, GroupBy, Sum with a
|
||||
/// null-coalesce) translates in process.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class HomeStatsQueryTests
|
||||
{
|
||||
private DeepDrftContext _context = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<DeepDrftContext>()
|
||||
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
_context = new DeepDrftContext(options);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() => _context.Dispose();
|
||||
|
||||
private TrackRepository CreateRepository()
|
||||
=> new(_context, NullLogger<Repository<DeepDrftContext, TrackEntity>>.Instance);
|
||||
|
||||
private static ReleaseEntity Release(
|
||||
string title, ReleaseMedium medium, ReleaseType releaseType = ReleaseType.Single)
|
||||
=> new()
|
||||
{
|
||||
EntryKey = Guid.NewGuid().ToString("N"),
|
||||
Title = title,
|
||||
Artist = "A",
|
||||
Medium = medium,
|
||||
ReleaseType = releaseType,
|
||||
};
|
||||
|
||||
private static TrackEntity Track(ReleaseEntity release, double? duration = null)
|
||||
=> new()
|
||||
{
|
||||
EntryKey = Guid.NewGuid().ToString("N"),
|
||||
TrackName = "T",
|
||||
Release = release,
|
||||
DurationSeconds = duration,
|
||||
};
|
||||
|
||||
private async Task SeedAsync(IEnumerable<ReleaseEntity> releases, IEnumerable<TrackEntity> tracks)
|
||||
{
|
||||
_context.Releases.AddRange(releases);
|
||||
_context.Tracks.AddRange(tracks);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// Cut track count reflects only tracks whose release is the Cut medium — Session and Mix tracks
|
||||
// are excluded — given a mix of all three media.
|
||||
[Test]
|
||||
public async Task GetHomeStatsAsync_CutTrackCount_CountsOnlyCutMediumTracks()
|
||||
{
|
||||
var cut = Release("Cut", ReleaseMedium.Cut, ReleaseType.Album);
|
||||
var session = Release("Session", ReleaseMedium.Session);
|
||||
var mix = Release("Mix", ReleaseMedium.Mix);
|
||||
await SeedAsync(
|
||||
new[] { cut, session, mix },
|
||||
new[] { Track(cut), Track(cut), Track(session), Track(mix) });
|
||||
|
||||
var stats = await CreateRepository().GetHomeStatsAsync();
|
||||
|
||||
Assert.That(stats.CutTrackCount, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
// The Cut release-type breakdown groups by ReleaseType, and a type with zero Cut releases is absent
|
||||
// from the result entirely (not present-with-zero).
|
||||
[Test]
|
||||
public async Task GetHomeStatsAsync_CutReleaseTypeBreakdown_OmitsZeroCountTypes()
|
||||
{
|
||||
await SeedAsync(
|
||||
new[]
|
||||
{
|
||||
Release("Cut Single 1", ReleaseMedium.Cut, ReleaseType.Single),
|
||||
Release("Cut Single 2", ReleaseMedium.Cut, ReleaseType.Single),
|
||||
Release("Cut Album", ReleaseMedium.Cut, ReleaseType.Album),
|
||||
// A Mix release with ReleaseType.EP must not leak into the Cut breakdown.
|
||||
Release("Mix EP", ReleaseMedium.Mix, ReleaseType.EP),
|
||||
},
|
||||
Array.Empty<TrackEntity>());
|
||||
|
||||
var stats = await CreateRepository().GetHomeStatsAsync();
|
||||
|
||||
Assert.That(stats.CutReleaseTypeCounts.Any(c => c.ReleaseType == ReleaseType.EP), Is.False,
|
||||
"EP has zero Cut releases and must be absent, not present-with-zero");
|
||||
Assert.That(stats.CutReleaseTypeCounts.Single(c => c.ReleaseType == ReleaseType.Single).Count, Is.EqualTo(2));
|
||||
Assert.That(stats.CutReleaseTypeCounts.Single(c => c.ReleaseType == ReleaseType.Album).Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
// Mix release count counts Mix-medium releases, and the runtime sum tolerates null durations:
|
||||
// not-yet-backfilled tracks contribute 0 rather than throwing or skewing the total.
|
||||
[Test]
|
||||
public async Task GetHomeStatsAsync_MixRuntime_TreatsNullDurationsAsZero()
|
||||
{
|
||||
var mixA = Release("Mix A", ReleaseMedium.Mix);
|
||||
var mixB = Release("Mix B", ReleaseMedium.Mix);
|
||||
var cut = Release("Cut", ReleaseMedium.Cut);
|
||||
await SeedAsync(
|
||||
new[] { mixA, mixB, cut },
|
||||
new[]
|
||||
{
|
||||
Track(mixA, duration: 600d),
|
||||
Track(mixB, duration: null), // not yet backfilled — contributes 0
|
||||
Track(cut, duration: 120d), // Cut track must not count toward mix runtime
|
||||
});
|
||||
|
||||
var stats = await CreateRepository().GetHomeStatsAsync();
|
||||
|
||||
Assert.That(stats.MixReleaseCount, Is.EqualTo(2));
|
||||
Assert.That(stats.MixRuntimeSeconds, Is.EqualTo(600d));
|
||||
}
|
||||
|
||||
// Soft-deleted releases and tracks never count toward any figure.
|
||||
[Test]
|
||||
public async Task GetHomeStatsAsync_ExcludesSoftDeletedRowsFromAllFigures()
|
||||
{
|
||||
var liveCut = Release("Live Cut", ReleaseMedium.Cut, ReleaseType.Album);
|
||||
var deletedCut = Release("Dead Cut", ReleaseMedium.Cut, ReleaseType.Album);
|
||||
deletedCut.IsDeleted = true;
|
||||
var mix = Release("Mix", ReleaseMedium.Mix);
|
||||
|
||||
var deletedMixTrack = Track(mix, duration: 999d);
|
||||
deletedMixTrack.IsDeleted = true;
|
||||
|
||||
await SeedAsync(
|
||||
new[] { liveCut, deletedCut, mix },
|
||||
new[] { Track(liveCut), deletedMixTrack });
|
||||
|
||||
var stats = await CreateRepository().GetHomeStatsAsync();
|
||||
|
||||
Assert.That(stats.CutTrackCount, Is.EqualTo(1));
|
||||
Assert.That(stats.CutReleaseTypeCounts.Single(c => c.ReleaseType == ReleaseType.Album).Count, Is.EqualTo(1));
|
||||
Assert.That(stats.MixRuntimeSeconds, Is.EqualTo(0d), "the only mix track is soft-deleted");
|
||||
}
|
||||
|
||||
// A live track under a directly-deleted release must be excluded from the track-based figures.
|
||||
// SoftDeleteReleaseAsync does not cascade to child tracks, so without the !t.Release.IsDeleted
|
||||
// guard the track-count and runtime figures are internally inconsistent with the release-level ones.
|
||||
[Test]
|
||||
public async Task GetHomeStatsAsync_ExcludesLiveTracksUnderSoftDeletedRelease()
|
||||
{
|
||||
var liveCut = Release("Live Cut", ReleaseMedium.Cut, ReleaseType.Album);
|
||||
var deletedCut = Release("Dead Cut", ReleaseMedium.Cut, ReleaseType.Album);
|
||||
deletedCut.IsDeleted = true;
|
||||
var deletedMix = Release("Dead Mix", ReleaseMedium.Mix);
|
||||
deletedMix.IsDeleted = true;
|
||||
|
||||
// Both tracks are themselves live — only their parent release is soft-deleted.
|
||||
var liveTrackUnderDeletedCut = Track(deletedCut);
|
||||
var liveTrackUnderDeletedMix = Track(deletedMix, duration: 900d);
|
||||
|
||||
await SeedAsync(
|
||||
new[] { liveCut, deletedCut, deletedMix },
|
||||
new[] { Track(liveCut), liveTrackUnderDeletedCut, liveTrackUnderDeletedMix });
|
||||
|
||||
var stats = await CreateRepository().GetHomeStatsAsync();
|
||||
|
||||
Assert.That(stats.CutTrackCount, Is.EqualTo(1),
|
||||
"live track under deleted Cut release must not inflate CutTrackCount");
|
||||
Assert.That(stats.MixReleaseCount, Is.EqualTo(0),
|
||||
"deleted Mix release must not count");
|
||||
Assert.That(stats.MixRuntimeSeconds, Is.EqualTo(0d),
|
||||
"live track under deleted Mix release must not inflate MixRuntimeSeconds");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using DeepDrftPublic.Client.Helpers;
|
||||
|
||||
namespace DeepDrftTests;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for the home-stat-row runtime formatter (<see cref="RuntimeFormat.ToHoursMinutes"/>):
|
||||
/// the hh:mm shape, hour rollover past 60 minutes, multi-hour totals, and the clamp on non-positive /
|
||||
/// non-finite input.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class RuntimeFormatTests
|
||||
{
|
||||
// 12h34m -> "12:34": the brief's worked example, hours not zero-padded, minutes two digits.
|
||||
[Test]
|
||||
public void ToHoursMinutes_TwelveHoursThirtyFour_FormatsHhMm()
|
||||
=> Assert.That(RuntimeFormat.ToHoursMinutes((12 * 3600) + (34 * 60)), Is.EqualTo("12:34"));
|
||||
|
||||
// 90 minutes rolls into 1 hour 30 minutes — minutes never exceed 59.
|
||||
[Test]
|
||||
public void ToHoursMinutes_NinetyMinutes_RollsIntoHours()
|
||||
=> Assert.That(RuntimeFormat.ToHoursMinutes(90 * 60), Is.EqualTo("1:30"));
|
||||
|
||||
// Sub-hour totals show 0 hours with zero-padded minutes.
|
||||
[Test]
|
||||
public void ToHoursMinutes_UnderOneHour_ShowsZeroHours()
|
||||
=> Assert.That(RuntimeFormat.ToHoursMinutes(5 * 60), Is.EqualTo("0:05"));
|
||||
|
||||
// Totals beyond 99h are not truncated — hours simply take more than two digits (mixes are few).
|
||||
[Test]
|
||||
public void ToHoursMinutes_BeyondNinetyNineHours_DoesNotTruncate()
|
||||
=> Assert.That(RuntimeFormat.ToHoursMinutes((123 * 3600) + (45 * 60)), Is.EqualTo("123:45"));
|
||||
|
||||
// Zero / negative / non-finite inputs clamp to "0:00" rather than producing a negative or NaN render.
|
||||
[TestCase(0d)]
|
||||
[TestCase(-10d)]
|
||||
[TestCase(double.NaN)]
|
||||
[TestCase(double.PositiveInfinity)]
|
||||
public void ToHoursMinutes_NonPositiveOrNonFinite_ClampsToZero(double seconds)
|
||||
=> Assert.That(RuntimeFormat.ToHoursMinutes(seconds), Is.EqualTo("0:00"));
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
using System.Text;
|
||||
using DeepDrftContent;
|
||||
using DeepDrftContent.Constants;
|
||||
using DeepDrftContent.FileDatabase.Models;
|
||||
using DeepDrftContent.Processors;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using FileDb = DeepDrftContent.FileDatabase.Services.FileDatabase;
|
||||
|
||||
namespace DeepDrftTests;
|
||||
|
||||
/// <summary>
|
||||
/// Integration tests for the content-side audio-replace seam
|
||||
/// (<see cref="TrackContentService.ReplaceTrackAudioAsync"/>) and the waveform regeneration that the
|
||||
/// API orchestrator runs after it. These exercise the real <see cref="FileDb"/>, the real
|
||||
/// <see cref="AudioProcessorRouter"/>, and the real <see cref="WaveformProfileService"/> over
|
||||
/// temp-directory-isolated vaults — the same pattern as <see cref="WaveformProfileServiceTests"/>.
|
||||
///
|
||||
/// The replace contract under test: the vault key (EntryKey) is preserved, only the bytes change,
|
||||
/// no stale backing file is left behind on a cross-format swap, and the waveform datums are
|
||||
/// re-computed against the new audio. SQL-side preservation (track id, release link, position,
|
||||
/// metadata) is guaranteed structurally — the orchestrator never writes SQL on replace — so it is
|
||||
/// documented here rather than asserted against a database this suite does not stand up.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TrackReplaceAudioTests
|
||||
{
|
||||
private string _testDir = string.Empty;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_testDir = Path.Combine(Path.GetTempPath(), "TrackReplaceAudioTests", Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(_testDir);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
try { Directory.Delete(_testDir, recursive: true); }
|
||||
catch { /* Best-effort cleanup — ignore failures */ }
|
||||
}
|
||||
|
||||
private static TrackContentService CreateContentService(FileDb fileDatabase) =>
|
||||
new(fileDatabase, new AudioProcessorRouter(
|
||||
new AudioProcessor(), new Mp3AudioProcessor(), new FlacAudioProcessor()));
|
||||
|
||||
private static WaveformProfileService CreateWaveformService(FileDb fileDatabase) =>
|
||||
new(fileDatabase, new AudioProcessor(), new RmsLoudnessAlgorithm(),
|
||||
Options.Create(new WaveformProfileOptions()), NullLogger<WaveformProfileService>.Instance);
|
||||
|
||||
[Test]
|
||||
public async Task ReplaceTrackAudioAsync_SwapsBytes_PreservingEntryKey()
|
||||
{
|
||||
var fileDatabase = await FileDb.FromAsync(_testDir);
|
||||
Assert.That(fileDatabase, Is.Not.Null);
|
||||
var content = CreateContentService(fileDatabase!);
|
||||
|
||||
// Seed a 2-second track, then replace it with a 6-second one. The entry key is the stable
|
||||
// SQL→vault link; replace must reuse it so the track row keeps pointing at live audio.
|
||||
var original = await WriteWavAsync(BuildMinimalPcmWav(2.0), ".wav");
|
||||
var seeded = await content.AddTrackAsync(original, "Original", "Artist");
|
||||
Assert.That(seeded, Is.Not.Null);
|
||||
var entryKey = seeded!.EntryKey;
|
||||
|
||||
var before = await content.GetAudioBinaryAsync(entryKey);
|
||||
Assert.That(before, Is.Not.Null);
|
||||
var originalDuration = before!.Duration;
|
||||
|
||||
var replacement = await WriteWavAsync(BuildMinimalPcmWav(6.0), ".wav");
|
||||
var newAudio = await content.ReplaceTrackAudioAsync(entryKey, replacement);
|
||||
|
||||
Assert.That(newAudio, Is.Not.Null, "Replace should return the freshly stored audio");
|
||||
|
||||
var after = await content.GetAudioBinaryAsync(entryKey);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(after, Is.Not.Null, "The track must remain retrievable under the same EntryKey");
|
||||
Assert.That(after!.Duration, Is.GreaterThan(originalDuration),
|
||||
"The retrieved audio must reflect the longer replacement, not the original");
|
||||
Assert.That(newAudio!.Duration, Is.EqualTo(after.Duration),
|
||||
"The returned binary must match what is stored under the key");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ReplaceTrackAudioAsync_CrossFormat_RemovesStaleBackingFile()
|
||||
{
|
||||
var fileDatabase = await FileDb.FromAsync(_testDir);
|
||||
var content = CreateContentService(fileDatabase!);
|
||||
|
||||
// A .wav original replaced by a .flac: the backing filename is keyed by extension, so a
|
||||
// register-only swap would strand the old .wav. The replace writes the new entry first, then
|
||||
// cleans up the stale old backing file (detected by comparing old vs. new extension).
|
||||
var original = await WriteWavAsync(BuildMinimalPcmWav(2.0), ".wav");
|
||||
var seeded = await content.AddTrackAsync(original, "Original", "Artist");
|
||||
var entryKey = seeded!.EntryKey;
|
||||
|
||||
var vaultDir = Path.Combine(_testDir, VaultConstants.Tracks);
|
||||
var wavFilesBefore = Directory.GetFiles(vaultDir, "*.wav");
|
||||
Assert.That(wavFilesBefore, Is.Not.Empty, "Sanity: the original .wav backing file exists");
|
||||
|
||||
var replacement = await WriteFlacAsync();
|
||||
var newAudio = await content.ReplaceTrackAudioAsync(entryKey, replacement);
|
||||
|
||||
Assert.That(newAudio, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(Directory.GetFiles(vaultDir, "*.wav"), Is.Empty,
|
||||
"The stale .wav backing file must be removed on a cross-format replace");
|
||||
Assert.That(Directory.GetFiles(vaultDir, "*.flac"), Is.Not.Empty,
|
||||
"The new .flac backing file must be present");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ReplaceThenRegenerate_RewritesWaveformDatumsForNewAudio()
|
||||
{
|
||||
var fileDatabase = await FileDb.FromAsync(_testDir);
|
||||
var content = CreateContentService(fileDatabase!);
|
||||
var waveforms = CreateWaveformService(fileDatabase!);
|
||||
|
||||
// Seed a short track and its waveform datums, then replace with a longer track and regenerate
|
||||
// (the exact sequence UnifiedTrackService.ReplaceAudioAsync runs). The high-res datum is
|
||||
// duration-derived, so a longer replacement yields a denser datum — proving the regen ran
|
||||
// against the new audio rather than leaving the stale datum in place.
|
||||
var original = await WriteWavAsync(BuildMinimalPcmWav(3.0), ".wav");
|
||||
var seeded = await content.AddTrackAsync(original, "Original", "Artist");
|
||||
var entryKey = seeded!.EntryKey;
|
||||
|
||||
var seedAudio = await content.GetAudioBinaryAsync(entryKey);
|
||||
await waveforms.ComputeAndStoreAsync(seedAudio!.Buffer, entryKey);
|
||||
await waveforms.ComputeAndStoreHighResAsync(seedAudio.Buffer, entryKey, seedAudio.Duration);
|
||||
var staleHighRes = await waveforms.GetProfileAsync(entryKey, VaultConstants.TrackWaveforms);
|
||||
Assert.That(staleHighRes, Is.Not.Null);
|
||||
|
||||
var replacement = await WriteWavAsync(BuildMinimalPcmWav(20.0), ".wav");
|
||||
var newAudio = await content.ReplaceTrackAudioAsync(entryKey, replacement);
|
||||
Assert.That(newAudio, Is.Not.Null);
|
||||
|
||||
// Regen step (mirrors the orchestrator).
|
||||
Assert.That(await waveforms.ComputeAndStoreAsync(newAudio!.Buffer, entryKey), Is.True);
|
||||
Assert.That(await waveforms.ComputeAndStoreHighResAsync(newAudio.Buffer, entryKey, newAudio.Duration), Is.True);
|
||||
|
||||
var freshHighRes = await waveforms.GetProfileAsync(entryKey, VaultConstants.TrackWaveforms);
|
||||
var freshProfile = await waveforms.GetProfileAsync(entryKey);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(freshHighRes, Is.Not.Null);
|
||||
Assert.That(freshProfile, Is.Not.Null, "The 512-bucket profile must also be present after regen");
|
||||
Assert.That(freshHighRes!.Length, Is.EqualTo(WaveformResolution.BucketCountForDuration(20.0)),
|
||||
"The high-res datum must track the new (longer) duration");
|
||||
Assert.That(freshHighRes.Length, Is.Not.EqualTo(staleHighRes!.Length),
|
||||
"The regenerated datum must differ from the stale one keyed to the shorter original");
|
||||
});
|
||||
}
|
||||
|
||||
// --- WAV / FLAC test fixtures ---
|
||||
|
||||
private async Task<string> WriteWavAsync(byte[] bytes, string extension)
|
||||
{
|
||||
var path = Path.Combine(_testDir, Guid.NewGuid().ToString("N") + extension);
|
||||
await File.WriteAllBytesAsync(path, bytes);
|
||||
return path;
|
||||
}
|
||||
|
||||
// Minimal valid FLAC: 'fLaC' magic + a STREAMINFO metadata block. The processor reads STREAMINFO
|
||||
// for sample rate / channels / bits / total samples; it does not decode frames, so an empty audio
|
||||
// payload is sufficient to produce a non-null AudioBinary with a .flac extension.
|
||||
private async Task<string> WriteFlacAsync()
|
||||
{
|
||||
var path = Path.Combine(_testDir, Guid.NewGuid().ToString("N") + ".flac");
|
||||
await File.WriteAllBytesAsync(path, BuildMinimalFlac());
|
||||
return path;
|
||||
}
|
||||
|
||||
// Builds a standard-PCM mono 16-bit 44.1 kHz WAV of the requested duration with a full-scale
|
||||
// square wave (non-silent so the loudness algorithm yields a real envelope). Same layout as
|
||||
// WaveformProfileServiceTests.BuildMinimalPcmWav.
|
||||
private static byte[] BuildMinimalPcmWav(double durationSeconds)
|
||||
{
|
||||
const int sampleRate = 44100;
|
||||
const ushort channels = 1;
|
||||
const ushort bitsPerSample = 16;
|
||||
const ushort blockAlign = channels * (bitsPerSample / 8);
|
||||
const uint byteRate = sampleRate * blockAlign;
|
||||
|
||||
var frames = (int)(sampleRate * durationSeconds);
|
||||
var data = new byte[frames * blockAlign];
|
||||
for (var i = 0; i < frames; i++)
|
||||
{
|
||||
var sample = (i % 2 == 0) ? short.MaxValue : short.MinValue;
|
||||
data[i * 2] = (byte)(sample & 0xFF);
|
||||
data[i * 2 + 1] = (byte)((sample >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
using var w = new BinaryWriter(ms, Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
w.Write(Encoding.ASCII.GetBytes("RIFF"));
|
||||
w.Write((uint)(36 + data.Length));
|
||||
w.Write(Encoding.ASCII.GetBytes("WAVE"));
|
||||
|
||||
w.Write(Encoding.ASCII.GetBytes("fmt "));
|
||||
w.Write(16u);
|
||||
w.Write((ushort)1); // PCM
|
||||
w.Write(channels);
|
||||
w.Write((uint)sampleRate);
|
||||
w.Write(byteRate);
|
||||
w.Write(blockAlign);
|
||||
w.Write(bitsPerSample);
|
||||
|
||||
w.Write(Encoding.ASCII.GetBytes("data"));
|
||||
w.Write((uint)data.Length);
|
||||
w.Write(data);
|
||||
|
||||
w.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
// Builds the minimal FLAC the processor can parse: 'fLaC' + one STREAMINFO block (type 0, last).
|
||||
// STREAMINFO is 34 bytes; the processor reads the bit-packed 20-bit sample rate, 3-bit channels,
|
||||
// 5-bit bits-per-sample, and 36-bit total-samples fields. Values: 44.1 kHz, mono, 16-bit, some
|
||||
// total samples so duration > 0.
|
||||
private static byte[] BuildMinimalFlac()
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
ms.Write(Encoding.ASCII.GetBytes("fLaC"));
|
||||
|
||||
// Metadata block header: last-block flag (0x80) | block type 0 (STREAMINFO), then 24-bit length = 34.
|
||||
ms.WriteByte(0x80);
|
||||
ms.WriteByte(0x00);
|
||||
ms.WriteByte(0x00);
|
||||
ms.WriteByte(34);
|
||||
|
||||
var streamInfo = new byte[34];
|
||||
// Bytes 0-1: min block size; 2-3: max block size — non-zero placeholders.
|
||||
streamInfo[0] = 0x10; streamInfo[2] = 0x10;
|
||||
// Bytes 10-17 hold the packed sampleRate(20) | channels(3) | bitsPerSample(5) | totalSamples(36).
|
||||
const int sampleRate = 44100;
|
||||
const int channels = 1;
|
||||
const int bitsPerSample = 16;
|
||||
const long totalSamples = 44100L * 3; // 3 seconds
|
||||
|
||||
// sampleRate occupies the top 20 bits of bytes 10-12.
|
||||
streamInfo[10] = (byte)((sampleRate >> 12) & 0xFF);
|
||||
streamInfo[11] = (byte)((sampleRate >> 4) & 0xFF);
|
||||
// Low 4 bits of sampleRate into the top nibble of byte 12; then (channels-1) in 3 bits and the
|
||||
// top bit of (bitsPerSample-1).
|
||||
var bps = bitsPerSample - 1; // 5-bit field stores bitsPerSample-1
|
||||
streamInfo[12] = (byte)(((sampleRate & 0x0F) << 4)
|
||||
| (((channels - 1) & 0x07) << 1)
|
||||
| ((bps >> 4) & 0x01));
|
||||
// Remaining 4 bits of bps into the top nibble of byte 13, then top 4 bits of the 36-bit total.
|
||||
streamInfo[13] = (byte)(((bps & 0x0F) << 4) | (int)((totalSamples >> 32) & 0x0F));
|
||||
streamInfo[14] = (byte)((totalSamples >> 24) & 0xFF);
|
||||
streamInfo[15] = (byte)((totalSamples >> 16) & 0xFF);
|
||||
streamInfo[16] = (byte)((totalSamples >> 8) & 0xFF);
|
||||
streamInfo[17] = (byte)(totalSamples & 0xFF);
|
||||
|
||||
ms.Write(streamInfo);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -89,7 +89,8 @@ Addresses **G2**. No code change. The remediation is a one-line code comment (st
|
||||
- **`DeepDrftManager` (CMS).** Render mode is `InteractiveServer` (server-rendered, single lifecycle — no SSR→WASM handoff). The whole class of bug does not exist there. Not audited beyond confirming the render mode.
|
||||
- **`DeepDrftData`, `DeepDrftContent`, `DeepDrftAPI`.** Server-side only; never reach WASM. No client lifecycle.
|
||||
- **`AudioPlayerProvider` / `StreamingAudioPlayerService` / `AudioPlayerBar` / `SpectrumVisualizer` / `PlayStateIcon` / `WaveformSeeker`.** These subscribe to the player's `StateChanged` multicast and re-render off live runtime state. They hold no prerender-fetched data to persist — the player cannot be live during prerender (gesture-gated). Their `OnParametersSet`/`OnAfterRender` subscription logic is correct fencing, not a missing persist. Leave them.
|
||||
- **`NowPlayingStats`, `DeepDrftHero` stat row, genre cards, feature cards on `Home.razor`.** Fully static markup (hard-coded copy, no fetch). Same content on both passes → no flip. The only animated one is the hero (G1/R1); the rest have no entrance animation (`Home.razor.css` has only steady-state `transition:` rules on hover/theme, lines 127/145/199/368/489/509 — those fire on interaction, not mount, and are correct).
|
||||
- **`NowPlayingStats` stat row on `Home.razor`.** Live data — fetches `HomeStatsDto` via `IStatsDataService`/`StatsClient` (`GET api/stats/home`) and bridges the prerender→WASM fetch through `PersistentComponentState` (same Mode A seam as S1/S2). On the WASM pass the persisted `HomeStatsDto` is restored before any fetch, so there is no skeleton-to-content swap or re-fetch. No entrance animation, no flip. Already correct; do not touch.
|
||||
- **`DeepDrftHero` genre cards, feature cards on `Home.razor`.** Fully static markup (hard-coded copy, no fetch). Same content on both passes → no flip. No entrance animation (`Home.razor.css` has only steady-state `transition:` rules on hover/theme, lines 127/145/199/368/489/509 — those fire on interaction, not mount, and are correct).
|
||||
- **Infinite/steady-state CSS animations** — `circle-deco` pulse-ring (`NowPlaying.razor.css`), waveform `wave-dance`/`blink` (`NowPlayingCard.razor.css`), spectrum bars. These loop continuously by design; a remount restarting their loop is imperceptible (they never "settle"). Not entrance animations, not a regression.
|
||||
- **CSS / JS asset staleness across deploys.** Separate concern, already handled: `@Assets[...]` fingerprints CSS (`App.razor`), `<ImportMap />` fingerprints the audio JS module graph. Do not conflate with the seam work.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user