From bf054f3d1b0f19fa8159044d8f0738c8a0e6bdc3 Mon Sep 17 00:00:00 2001 From: daniel-c-harvey Date: Mon, 8 Sep 2025 11:10:23 -0400 Subject: [PATCH] API Connection Cleanup & Bugfixes --- .../Controllers/TrackController.cs | 28 +++++++++++++++---- DeepDrftContent/Program.cs | 9 +++--- DeepDrftContent/appsettings.json | 3 +- DeepDrftWeb.Client/Clients/TrackClient.cs | 1 - .../Clients/TrackMediaClient.cs | 2 +- DeepDrftWeb.Client/Pages/TracksView.razor.cs | 11 ++++++-- .../wwwroot/appsettings.Development.json | 2 +- DeepDrftWeb.Client/wwwroot/appsettings.json | 2 +- DeepDrftWeb/appsettings.Development.json | 2 +- DeepDrftWeb/appsettings.json | 2 +- 10 files changed, 44 insertions(+), 18 deletions(-) diff --git a/DeepDrftContent/Controllers/TrackController.cs b/DeepDrftContent/Controllers/TrackController.cs index 2bbfbad..449d0cf 100644 --- a/DeepDrftContent/Controllers/TrackController.cs +++ b/DeepDrftContent/Controllers/TrackController.cs @@ -10,25 +10,43 @@ namespace DeepDrftContent.Controllers; public class TrackController : ControllerBase { private readonly DeepDrftContent.Services.FileDatabase.Services.FileDatabase _fileDatabase; + private readonly ILogger _logger; - public TrackController(DeepDrftContent.Services.FileDatabase.Services.FileDatabase fileDatabase) + public TrackController(DeepDrftContent.Services.FileDatabase.Services.FileDatabase fileDatabase, ILogger logger) { _fileDatabase = fileDatabase; + _logger = logger; } [HttpGet("{trackId}")] public async Task GetTrack(string trackId) { - var file = await _fileDatabase.LoadResourceAsync(VaultConstants.Tracks, trackId); - if (file == null) { return NotFound(); } + _logger.LogInformation("GetTrack called with trackId: {TrackId}", trackId); + + try + { + var file = await _fileDatabase.LoadResourceAsync(VaultConstants.Tracks, trackId); + if (file == null) + { + _logger.LogWarning("Track not found: {TrackId}", trackId); + return NotFound(); + } - return File(file.Buffer, MimeTypeExtensions.GetMimeType(file.Extension), enableRangeProcessing: true); + _logger.LogInformation("Successfully retrieved track: {TrackId}, Size: {Size} bytes", trackId, file.Buffer.Length); + return File(file.Buffer, MimeTypeExtensions.GetMimeType(file.Extension)); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error retrieving track: {TrackId}", trackId); + return StatusCode(500, "Internal server error"); + } } [ApiKeyAuthorize] [HttpPut("{trackId}")] - public async Task PutTrack([FromQuery] string trackId, [FromBody] AudioBinaryDto track) + public async Task PutTrack(string trackId, [FromBody] AudioBinaryDto track) { + _logger.LogInformation("PutTrack called with trackId: {TrackId}", trackId); var audioBinary = AudioBinary.From(track); var success = await _fileDatabase.RegisterResourceAsync(VaultConstants.Tracks, trackId, audioBinary); return success ? Ok() : BadRequest("Failed to store audio track"); diff --git a/DeepDrftContent/Program.cs b/DeepDrftContent/Program.cs index bd50496..a94a828 100644 --- a/DeepDrftContent/Program.cs +++ b/DeepDrftContent/Program.cs @@ -47,9 +47,11 @@ builder.Services.Configure(options => var app = builder.Build(); -// Configure the HTTP request pipeline. -// Use forwarded headers before other middleware -app.UseForwardedHeaders(); +if (app.Environment.IsProduction()) +{ + // Use forwarded headers before other middleware + app.UseForwardedHeaders(); +} if (app.Environment.IsDevelopment()) { @@ -58,7 +60,6 @@ if (app.Environment.IsDevelopment()) app.UseCors("ContentApiPolicy"); app.UseApiKeyAuthentication(apiKeySettings.ApiKey); -app.UseAuthorization(); app.MapControllers(); diff --git a/DeepDrftContent/appsettings.json b/DeepDrftContent/appsettings.json index 81f1929..4046d61 100644 --- a/DeepDrftContent/appsettings.json +++ b/DeepDrftContent/appsettings.json @@ -2,7 +2,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "DeepDrftContent.Controllers.TrackController": "Information" } }, "AllowedHosts": "*", diff --git a/DeepDrftWeb.Client/Clients/TrackClient.cs b/DeepDrftWeb.Client/Clients/TrackClient.cs index 98cfd27..eba3f18 100644 --- a/DeepDrftWeb.Client/Clients/TrackClient.cs +++ b/DeepDrftWeb.Client/Clients/TrackClient.cs @@ -4,7 +4,6 @@ using NetBlocks.Models; using System.Text.Json; using System.Web; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; namespace DeepDrftWeb.Client.Clients; diff --git a/DeepDrftWeb.Client/Clients/TrackMediaClient.cs b/DeepDrftWeb.Client/Clients/TrackMediaClient.cs index dd64bc8..6204fbb 100644 --- a/DeepDrftWeb.Client/Clients/TrackMediaClient.cs +++ b/DeepDrftWeb.Client/Clients/TrackMediaClient.cs @@ -25,7 +25,7 @@ public class TrackMediaClient public async Task GetTrackMedia(string trackId) { - var response = await _http.GetAsync($"track/{trackId}"); + var response = await _http.GetAsync($"api/track/{trackId}"); response.EnsureSuccessStatusCode(); var contentLength = response.Content.Headers.ContentLength ?? 0; diff --git a/DeepDrftWeb.Client/Pages/TracksView.razor.cs b/DeepDrftWeb.Client/Pages/TracksView.razor.cs index 2bf84a0..43b8dc1 100644 --- a/DeepDrftWeb.Client/Pages/TracksView.razor.cs +++ b/DeepDrftWeb.Client/Pages/TracksView.razor.cs @@ -51,8 +51,15 @@ public partial class TracksView : ComponentBase private async Task PlayTrack(TrackEntity? track) { if (track == null && _selectedTrack == null || track?.Id == _selectedTrack?.Id) return; - - await AudioPlaybackEngine.LoadTrack(track); + + if (track is null) + { + await AudioPlaybackEngine.Stop(); + } + else + { + await AudioPlaybackEngine.LoadTrack(track); + } StateHasChanged(); } } \ No newline at end of file diff --git a/DeepDrftWeb.Client/wwwroot/appsettings.Development.json b/DeepDrftWeb.Client/wwwroot/appsettings.Development.json index 53447bc..1f0b218 100644 --- a/DeepDrftWeb.Client/wwwroot/appsettings.Development.json +++ b/DeepDrftWeb.Client/wwwroot/appsettings.Development.json @@ -6,6 +6,6 @@ } }, "ApiUrls": { - "ContentApi": "http://localhost:54493/api/" + "ContentApi": "http://localhost:54494/" } } diff --git a/DeepDrftWeb.Client/wwwroot/appsettings.json b/DeepDrftWeb.Client/wwwroot/appsettings.json index 8ec7c59..e6588d2 100644 --- a/DeepDrftWeb.Client/wwwroot/appsettings.json +++ b/DeepDrftWeb.Client/wwwroot/appsettings.json @@ -6,6 +6,6 @@ } }, "ApiUrls": { - "ContentApi": "https://media.deepdrft.com/api/" + "ContentApi": "https://media.deepdrft.com/" } } diff --git a/DeepDrftWeb/appsettings.Development.json b/DeepDrftWeb/appsettings.Development.json index 7050dd0..cef5f32 100644 --- a/DeepDrftWeb/appsettings.Development.json +++ b/DeepDrftWeb/appsettings.Development.json @@ -7,6 +7,6 @@ }, "DetailedErrors": true, "ApiUrls": { - "ContentApi": "http://localhost:54493/api/" + "ContentApi": "http://localhost:54494/" } } diff --git a/DeepDrftWeb/appsettings.json b/DeepDrftWeb/appsettings.json index 64d821d..cb978c1 100644 --- a/DeepDrftWeb/appsettings.json +++ b/DeepDrftWeb/appsettings.json @@ -10,7 +10,7 @@ "DefaultConnection": "Data Source=../Database/deepdrft.db" }, "ApiUrls": { - "ContentApi": "http://localhost:12777/api/" + "ContentApi": "http://localhost:12777/" }, "ForwardedHeaders": { "DisableHttpsRedirection": "true"