CMS Phase 9 Wave 3: Release Archive tab, medium selector, Session/Mix browsers
Renames Genre tab to Release Archive with switch-free medium card group (Enum.GetValues-driven). Adds MediumFields single dispatch + CutFields/SessionFields/ MixFields per-medium sections embedded by all five upload/edit forms. BatchUpload enforces single-track invariant for Session/Mix. Adds CmsSessionBrowser (hero-image upload) and CmsMixBrowser (waveform status + per-row Generate trigger). ICmsReleaseService/CmsReleaseService wraps api/release endpoints. Note: medium selector is forward-compat only — API write path pending.
This commit is contained in:
@@ -0,0 +1,222 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftModels.Enums;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
|
||||
namespace DeepDrftManager.Services;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP client over DeepDrftAPI's <c>api/release</c> family for CMS release operations. Mirrors
|
||||
/// <see cref="CmsTrackService"/>: the Manager is InteractiveServer-only with no in-process data
|
||||
/// layer, so every read and write is a network call. The ApiKey is baked into the
|
||||
/// <c>DeepDrft.Content.Cms</c> named client's default headers; the unauthenticated reads still go
|
||||
/// through it (the extra header is harmless on public endpoints).
|
||||
/// </summary>
|
||||
public class CmsReleaseService : ICmsReleaseService
|
||||
{
|
||||
private const string ContentCmsClientName = "DeepDrft.Content.Cms";
|
||||
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ILogger<CmsReleaseService> _logger;
|
||||
|
||||
public CmsReleaseService(
|
||||
IHttpClientFactory httpClientFactory,
|
||||
ILogger<CmsReleaseService> logger)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<PagedResult<ReleaseDto>>> GetPagedAsync(
|
||||
ReleaseMedium? medium,
|
||||
int page, int pageSize, string? sortColumn, bool sortDescending,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
var query = $"api/release?page={page}&pageSize={pageSize}&sortDescending={sortDescending}";
|
||||
if (medium is { } m)
|
||||
{
|
||||
query += $"&medium={Uri.EscapeDataString(m.ToString())}";
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(sortColumn))
|
||||
{
|
||||
query += $"&sortColumn={Uri.EscapeDataString(sortColumn)}";
|
||||
}
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
response = await client.GetAsync(query, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for release page (medium {Medium})", medium);
|
||||
return ResultContainer<PagedResult<ReleaseDto>>.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogError("Content API release page failed: {Status}", (int)response.StatusCode);
|
||||
return ResultContainer<PagedResult<ReleaseDto>>.CreateFailResult("Failed to load releases.");
|
||||
}
|
||||
|
||||
PagedResult<ReleaseDto>? paged;
|
||||
try
|
||||
{
|
||||
paged = await response.Content.ReadFromJsonAsync<PagedResult<ReleaseDto>>(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to deserialize release page from Content API response");
|
||||
return ResultContainer<PagedResult<ReleaseDto>>.CreateFailResult("Content API returned an unexpected response.");
|
||||
}
|
||||
|
||||
if (paged is null)
|
||||
{
|
||||
_logger.LogError("Content API returned a null release page");
|
||||
return ResultContainer<PagedResult<ReleaseDto>>.CreateFailResult("Content API returned an empty response.");
|
||||
}
|
||||
|
||||
return ResultContainer<PagedResult<ReleaseDto>>.CreatePassResult(paged);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<ReleaseDto?>> GetByIdAsync(long id, CancellationToken ct = default)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
response = await client.GetAsync($"api/release/{id}", ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for release {ReleaseId}", id);
|
||||
return ResultContainer<ReleaseDto?>.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return ResultContainer<ReleaseDto?>.CreatePassResult(null);
|
||||
}
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogError("Content API release lookup failed for {ReleaseId}: {Status}", id, (int)response.StatusCode);
|
||||
return ResultContainer<ReleaseDto?>.CreateFailResult("Failed to load release.");
|
||||
}
|
||||
|
||||
ReleaseDto? release;
|
||||
try
|
||||
{
|
||||
release = await response.Content.ReadFromJsonAsync<ReleaseDto>(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to deserialize ReleaseDto from Content API response");
|
||||
return ResultContainer<ReleaseDto?>.CreateFailResult("Content API returned an unexpected response.");
|
||||
}
|
||||
|
||||
return ResultContainer<ReleaseDto?>.CreatePassResult(release);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result> UploadSessionHeroImageAsync(
|
||||
long releaseId,
|
||||
Stream imageStream,
|
||||
string fileName,
|
||||
string contentType,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
using var multipart = new MultipartFormDataContent();
|
||||
var imageContent = new StreamContent(imageStream);
|
||||
imageContent.Headers.ContentType = new MediaTypeHeaderValue(
|
||||
string.IsNullOrWhiteSpace(contentType) ? "application/octet-stream" : contentType);
|
||||
// Field name "image" matches the controller's [FromForm] IFormFile image parameter.
|
||||
multipart.Add(imageContent, "image", fileName);
|
||||
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, $"api/release/{releaseId}/session/hero-image")
|
||||
{
|
||||
Content = multipart
|
||||
};
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for hero-image upload of release {ReleaseId}", releaseId);
|
||||
return Result.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Result.CreatePassResult();
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return Result.CreateFailResult("Release not found.");
|
||||
}
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync(ct);
|
||||
var statusCode = (int)response.StatusCode;
|
||||
if (statusCode >= 500)
|
||||
{
|
||||
_logger.LogError("Content API returned {Status} for hero-image upload of release {ReleaseId}: {Body}", statusCode, releaseId, body);
|
||||
return Result.CreateFailResult("Hero image upload failed on the content server.");
|
||||
}
|
||||
|
||||
// 4xx: body is user-friendly validation text from DeepDrftAPI — relay as-is.
|
||||
_logger.LogWarning("Content API rejected hero-image upload for release {ReleaseId}: {Status} {Body}", releaseId, statusCode, body);
|
||||
return Result.CreateFailResult(
|
||||
string.IsNullOrWhiteSpace(body) ? $"Hero image upload rejected ({statusCode})." : body);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result> GenerateMixWaveformAsync(long releaseId, CancellationToken ct = default)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
|
||||
HttpResponseMessage response;
|
||||
try
|
||||
{
|
||||
response = await client.PostAsync($"api/release/{releaseId}/mix/waveform", null, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for mix waveform generation of release {ReleaseId}", releaseId);
|
||||
return Result.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Result.CreatePassResult();
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return Result.CreateFailResult("Mix audio not found.");
|
||||
}
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync(ct);
|
||||
_logger.LogError("Content API mix waveform generation failed for release {ReleaseId}: {Status} {Body}", releaseId, (int)response.StatusCode, body);
|
||||
return Result.CreateFailResult("Failed to generate mix waveform.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ using DeepDrftModels.DTOs;
|
||||
|
||||
namespace DeepDrftManager.Services;
|
||||
|
||||
/// <summary>The three browse dimensions for the /tracks page.</summary>
|
||||
/// <summary>The browse dimensions for the /tracks page.</summary>
|
||||
public enum BrowseMode
|
||||
{
|
||||
Tracks,
|
||||
Albums,
|
||||
Archive,
|
||||
Genres,
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ public class CmsTrackService : ICmsTrackService
|
||||
long createdByUserId,
|
||||
ReleaseType releaseType,
|
||||
int trackNumber,
|
||||
ReleaseMedium medium = ReleaseMedium.Cut,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
// Rebuild the multipart container so the boundary is owned by HttpClient and the
|
||||
@@ -63,6 +64,9 @@ public class CmsTrackService : ICmsTrackService
|
||||
multipart.Add(new StringContent(createdByUserId.ToString()), "createdByUserId");
|
||||
multipart.Add(new StringContent(releaseType.ToString()), "releaseType");
|
||||
multipart.Add(new StringContent(trackNumber.ToString()), "trackNumber");
|
||||
// Forward-compatible: the upload endpoint does not bind a "medium" field yet (server defaults
|
||||
// to Cut). Sent so the value round-trips once the API grows the parameter; ignored until then.
|
||||
multipart.Add(new StringContent(medium.ToString()), "medium");
|
||||
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, UploadPath) { Content = multipart };
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftModels.Enums;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
|
||||
namespace DeepDrftManager.Services;
|
||||
|
||||
/// <summary>
|
||||
/// CMS-side release operations for the Manager host. Mirrors <see cref="ICmsTrackService"/>: every
|
||||
/// read and write goes over HTTP to DeepDrftAPI's <c>api/release</c> family, which is the single
|
||||
/// authority over both the SQL metadata store and the binary vault. The Manager holds no in-process
|
||||
/// data layer.
|
||||
/// </summary>
|
||||
public interface ICmsReleaseService
|
||||
{
|
||||
/// <summary>
|
||||
/// Fetch a page of releases from <c>GET api/release</c>, optionally filtered to one
|
||||
/// <paramref name="medium"/>. The matching medium's metadata satellite is populated on each row;
|
||||
/// the others are null. Null medium returns all releases unfiltered.
|
||||
/// </summary>
|
||||
Task<ResultContainer<PagedResult<ReleaseDto>>> GetPagedAsync(
|
||||
ReleaseMedium? medium,
|
||||
int page, int pageSize, string? sortColumn, bool sortDescending,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Fetch a single release with both metadata navs from <c>GET api/release/{id}</c> (nulls for the
|
||||
/// non-matching medium). A 404 returns a passing result with a null value.
|
||||
/// </summary>
|
||||
Task<ResultContainer<ReleaseDto?>> GetByIdAsync(long id, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Upload a Session hero image via <c>POST api/release/{id}/session/hero-image</c> (multipart).
|
||||
/// The server stores it in the image vault and sets <c>SessionMetadata.HeroImageEntryKey</c>.
|
||||
/// Maps a 404 to a "Release not found." failure; relays 4xx validation text as-is.
|
||||
/// </summary>
|
||||
Task<Result> UploadSessionHeroImageAsync(
|
||||
long releaseId,
|
||||
Stream imageStream,
|
||||
string fileName,
|
||||
string contentType,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Trigger high-resolution waveform generation for a Mix via
|
||||
/// <c>POST api/release/{id}/mix/waveform</c> (no body). The server fetches the mix audio from its
|
||||
/// own vault, computes the datum, stores it, and sets <c>MixMetadata.WaveformEntryKey</c>. Maps a
|
||||
/// 404 to a "Mix audio not found." failure.
|
||||
/// </summary>
|
||||
Task<Result> GenerateMixWaveformAsync(long releaseId, CancellationToken ct = default);
|
||||
}
|
||||
@@ -18,6 +18,10 @@ public interface ICmsTrackService
|
||||
/// orphan is handled and logged server-side; here it surfaces as a failed result.
|
||||
/// <paramref name="originalFileName"/> is the browser's filename, captured at upload time and
|
||||
/// stored as metadata; it is not user-editable afterwards.
|
||||
/// <paramref name="medium"/> sets the parent release's <see cref="ReleaseMedium"/>. NOTE: the
|
||||
/// current <c>POST api/track/upload</c> endpoint has no <c>medium</c> form field, so the value is
|
||||
/// sent forward-compatibly and ignored server-side until the API binds it (Cut is the server
|
||||
/// default). Wiring the selector through here keeps the CMS ready for that API change.
|
||||
/// </summary>
|
||||
Task<ResultContainer<TrackDto>> UploadTrackAsync(
|
||||
Stream wavStream,
|
||||
@@ -32,6 +36,7 @@ public interface ICmsTrackService
|
||||
long createdByUserId,
|
||||
ReleaseType releaseType,
|
||||
int trackNumber,
|
||||
ReleaseMedium medium = ReleaseMedium.Cut,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user