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);
try
{
var file = await _fileDatabase.LoadResourceAsync<AudioBinary>(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<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": "*",