CMS -> API refactor part 1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
@page "/cms"
|
@page "/cms"
|
||||||
@attribute [HierarchicalRoleAuthorize([SystemRoleConstants.Admin])]
|
@attribute [Authorize]
|
||||||
|
|
||||||
<PageTitle>DeepDrft CMS</PageTitle>
|
<PageTitle>DeepDrft CMS</PageTitle>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
@page "/cms/tracks/{Id:long}"
|
@page "/cms/tracks/{Id:long}"
|
||||||
@using DeepDrftManager.Services
|
@using DeepDrftManager.Services
|
||||||
@attribute [HierarchicalRoleAuthorize([SystemRoleConstants.Admin])]
|
@attribute [Authorize]
|
||||||
@inject ITrackService TrackService
|
@inject ITrackService TrackService
|
||||||
@inject ICmsTrackService CmsTrackService
|
@inject ICmsTrackService CmsTrackService
|
||||||
@inject ISnackbar Snackbar
|
@inject ISnackbar Snackbar
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@page "/cms/tracks"
|
@page "/cms/tracks"
|
||||||
@using System.Net
|
@using System.Net
|
||||||
@using DeepDrftManager.Services
|
@using DeepDrftManager.Services
|
||||||
@attribute [HierarchicalRoleAuthorize([SystemRoleConstants.Admin])]
|
@attribute [Authorize]
|
||||||
@inject ITrackService TrackService
|
@inject ITrackService TrackService
|
||||||
@inject ICmsTrackService CmsTrackService
|
@inject ICmsTrackService CmsTrackService
|
||||||
@inject IDialogService DialogService
|
@inject IDialogService DialogService
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@page "/cms/tracks/new"
|
@page "/cms/tracks/new"
|
||||||
@using System.Security.Claims
|
@using System.Security.Claims
|
||||||
@using DeepDrftManager.Services
|
@using DeepDrftManager.Services
|
||||||
@attribute [HierarchicalRoleAuthorize([SystemRoleConstants.Admin])]
|
@attribute [Authorize]
|
||||||
|
|
||||||
@inject ICmsTrackService CmsTrackService
|
@inject ICmsTrackService CmsTrackService
|
||||||
@inject AuthenticationStateProvider AuthStateProvider
|
@inject AuthenticationStateProvider AuthStateProvider
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
// Required credential files — must exist before the app will start.
|
// Required credential files — must exist before the app will start.
|
||||||
// Production secrets stay gitignored; the *.example.json templates at the project root show the shape.
|
// Production secrets stay gitignored; the *.example.json templates at the project root show the shape.
|
||||||
// - environment/apikey.json: { "DeepDrftContent": { "ApiKey": "..." } }
|
// - environment/api.json: { "Api": { "ContentApiUrl": "...", "ContentApiKey": "..." } }
|
||||||
// - environment/connections.json: { "ConnectionStrings": { "DefaultConnection": "...", "Auth": "..." } }
|
// - environment/connections.json: { "ConnectionStrings": { "DefaultConnection": "...", "Auth": "..." } }
|
||||||
// - environment/authblocks.json: { "AuthBlocks": { "Jwt": {...}, "Email": {...}, "Admin": {...} } }
|
// - environment/authblocks.json: { "AuthBlocks": { "Jwt": {...}, "Email": {...}, "Admin": {...} } }
|
||||||
// Content API key — consumed by CmsTrackService for the upload proxy and the vault-delete client.
|
// Content API key — consumed by CmsTrackService for the upload proxy and the vault-delete client.
|
||||||
var apiKeyPath = CredentialTools.ResolvePathOrThrow("apikey", "environment/apikey.json");
|
var apiPath = CredentialTools.ResolvePathOrThrow("api", "environment/api.json");
|
||||||
builder.Configuration.AddJsonFile(apiKeyPath, optional: false, reloadOnChange: false);
|
builder.Configuration.AddJsonFile(apiPath, optional: false, reloadOnChange: false);
|
||||||
|
|
||||||
var connectionsPath = CredentialTools.ResolvePathOrThrow("connections", "environment/connections.json");
|
var connectionsPath = CredentialTools.ResolvePathOrThrow("connections", "environment/connections.json");
|
||||||
builder.Configuration.AddJsonFile(connectionsPath, optional: false, reloadOnChange: false);
|
builder.Configuration.AddJsonFile(connectionsPath, optional: false, reloadOnChange: false);
|
||||||
@@ -84,8 +84,8 @@ AuthBlocksWeb.Startup.ConfigureAuthServices(builder.Services, baseUrl);
|
|||||||
|
|
||||||
// Named HttpClient for unauthenticated Content API calls (CmsTrackService proxying WAV data
|
// Named HttpClient for unauthenticated Content API calls (CmsTrackService proxying WAV data
|
||||||
// to DeepDrftContent's POST api/track/upload). API key added per-request by the service.
|
// to DeepDrftContent's POST api/track/upload). API key added per-request by the service.
|
||||||
var contentApiUrl = builder.Configuration["ApiUrls:ContentApi"]
|
var contentApiUrl = builder.Configuration["Api:ContentApiUrl"]
|
||||||
?? throw new InvalidOperationException("ApiUrls:ContentApi is required");
|
?? throw new InvalidOperationException("Api:ContentApiUrl is required");
|
||||||
builder.Services.AddHttpClient("DeepDrft.Content", client =>
|
builder.Services.AddHttpClient("DeepDrft.Content", client =>
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri(contentApiUrl);
|
client.BaseAddress = new Uri(contentApiUrl);
|
||||||
@@ -93,8 +93,8 @@ builder.Services.AddHttpClient("DeepDrft.Content", client =>
|
|||||||
|
|
||||||
// Named HttpClient for ApiKey-protected Content API calls (CmsTrackService's vault delete).
|
// Named HttpClient for ApiKey-protected Content API calls (CmsTrackService's vault delete).
|
||||||
// API key baked into the default request headers so callers need not add it manually.
|
// API key baked into the default request headers so callers need not add it manually.
|
||||||
var contentApiKey = builder.Configuration["DeepDrftContent:ApiKey"]
|
var contentApiKey = builder.Configuration["Api:ContentApiKey"]
|
||||||
?? throw new InvalidOperationException("DeepDrftContent:ApiKey is required");
|
?? throw new InvalidOperationException("Api:ContentApiKey is required");
|
||||||
builder.Services.AddHttpClient("DeepDrft.Content.Cms", client =>
|
builder.Services.AddHttpClient("DeepDrft.Content.Cms", client =>
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri(contentApiUrl);
|
client.BaseAddress = new Uri(contentApiUrl);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ public class CmsTrackService : ICmsTrackService
|
|||||||
private const string UploadPath = "api/track/upload";
|
private const string UploadPath = "api/track/upload";
|
||||||
|
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ITrackService _trackService;
|
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly ILogger<CmsTrackService> _logger;
|
private readonly ILogger<CmsTrackService> _logger;
|
||||||
|
|
||||||
@@ -47,13 +46,6 @@ public class CmsTrackService : ICmsTrackService
|
|||||||
long createdByUserId,
|
long createdByUserId,
|
||||||
CancellationToken ct = default)
|
CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var apiKey = _configuration["DeepDrftContent:ApiKey"];
|
|
||||||
if (string.IsNullOrWhiteSpace(apiKey))
|
|
||||||
{
|
|
||||||
_logger.LogError("DeepDrftContent:ApiKey is not configured");
|
|
||||||
return ResultContainer<TrackEntity>.CreateFailResult("Content API key is not configured.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild the multipart container so the boundary is owned by HttpClient and the
|
// 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.
|
// caller-supplied stream (already buffered by the SignalR upload) is the source.
|
||||||
using var multipart = new MultipartFormDataContent();
|
using var multipart = new MultipartFormDataContent();
|
||||||
@@ -67,10 +59,9 @@ public class CmsTrackService : ICmsTrackService
|
|||||||
if (!string.IsNullOrWhiteSpace(genre)) multipart.Add(new StringContent(genre), "genre");
|
if (!string.IsNullOrWhiteSpace(genre)) multipart.Add(new StringContent(genre), "genre");
|
||||||
if (!string.IsNullOrWhiteSpace(releaseDate)) multipart.Add(new StringContent(releaseDate), "releaseDate");
|
if (!string.IsNullOrWhiteSpace(releaseDate)) multipart.Add(new StringContent(releaseDate), "releaseDate");
|
||||||
|
|
||||||
var client = _httpClientFactory.CreateClient(ContentClientName);
|
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Post, UploadPath) { Content = multipart };
|
using var request = new HttpRequestMessage(HttpMethod.Post, UploadPath) { Content = multipart };
|
||||||
request.Headers.Add("ApiKey", apiKey);
|
|
||||||
|
|
||||||
HttpResponseMessage response;
|
HttpResponseMessage response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,9 +6,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ApiUrls": {
|
|
||||||
"ContentApi": "https://content.deepdrft.com"
|
|
||||||
},
|
|
||||||
"ForwardedHeaders": {
|
"ForwardedHeaders": {
|
||||||
"DisableHttpsRedirection": false
|
"DisableHttpsRedirection": false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user