API Connection Cleanup & Bugfixes

This commit is contained in:
daniel-c-harvey
2025-09-08 11:10:23 -04:00
parent c6f4ffc1fe
commit bf054f3d1b
10 changed files with 44 additions and 18 deletions
+23 -5
View File
@@ -10,25 +10,43 @@ namespace DeepDrftContent.Controllers;
public class TrackController : ControllerBase
{
private readonly DeepDrftContent.Services.FileDatabase.Services.FileDatabase _fileDatabase;
private readonly ILogger<TrackController> _logger;
public TrackController(DeepDrftContent.Services.FileDatabase.Services.FileDatabase fileDatabase)
public TrackController(DeepDrftContent.Services.FileDatabase.Services.FileDatabase fileDatabase, ILogger<TrackController> logger)
{
_fileDatabase = fileDatabase;
_logger = logger;
}
[HttpGet("{trackId}")]
public async Task<ActionResult> GetTrack(string trackId)
{
var file = await _fileDatabase.LoadResourceAsync<AudioBinary>(VaultConstants.Tracks, trackId);
if (file == null) { return NotFound(); }
_logger.LogInformation("GetTrack called with trackId: {TrackId}", trackId);
return File(file.Buffer, MimeTypeExtensions.GetMimeType(file.Extension), enableRangeProcessing: true);
try
{
var file = await _fileDatabase.LoadResourceAsync<AudioBinary>(VaultConstants.Tracks, trackId);
if (file == null)
{
_logger.LogWarning("Track not found: {TrackId}", trackId);
return NotFound();
}
_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<ActionResult> PutTrack([FromQuery] string trackId, [FromBody] AudioBinaryDto track)
public async Task<ActionResult> 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");
+5 -4
View File
@@ -47,9 +47,11 @@ builder.Services.Configure<ForwardedHeadersOptions>(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();
+2 -1
View File
@@ -2,7 +2,8 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"DeepDrftContent.Controllers.TrackController": "Information"
}
},
"AllowedHosts": "*",
@@ -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;
@@ -25,7 +25,7 @@ public class TrackMediaClient
public async Task<TrackMediaResponse> 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;
@@ -52,7 +52,14 @@ public partial class TracksView : ComponentBase
{
if (track == null && _selectedTrack == null || track?.Id == _selectedTrack?.Id) return;
if (track is null)
{
await AudioPlaybackEngine.Stop();
}
else
{
await AudioPlaybackEngine.LoadTrack(track);
}
StateHasChanged();
}
}
@@ -6,6 +6,6 @@
}
},
"ApiUrls": {
"ContentApi": "http://localhost:54493/api/"
"ContentApi": "http://localhost:54494/"
}
}
+1 -1
View File
@@ -6,6 +6,6 @@
}
},
"ApiUrls": {
"ContentApi": "https://media.deepdrft.com/api/"
"ContentApi": "https://media.deepdrft.com/"
}
}
+1 -1
View File
@@ -7,6 +7,6 @@
},
"DetailedErrors": true,
"ApiUrls": {
"ContentApi": "http://localhost:54493/api/"
"ContentApi": "http://localhost:54494/"
}
}
+1 -1
View File
@@ -10,7 +10,7 @@
"DefaultConnection": "Data Source=../Database/deepdrft.db"
},
"ApiUrls": {
"ContentApi": "http://localhost:12777/api/"
"ContentApi": "http://localhost:12777/"
},
"ForwardedHeaders": {
"DisableHttpsRedirection": "true"