API Connection Cleanup & Bugfixes
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,6 @@
|
||||
}
|
||||
},
|
||||
"ApiUrls": {
|
||||
"ContentApi": "http://localhost:54493/api/"
|
||||
"ContentApi": "http://localhost:54494/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
}
|
||||
},
|
||||
"ApiUrls": {
|
||||
"ContentApi": "https://media.deepdrft.com/api/"
|
||||
"ContentApi": "https://media.deepdrft.com/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
},
|
||||
"DetailedErrors": true,
|
||||
"ApiUrls": {
|
||||
"ContentApi": "http://localhost:54493/api/"
|
||||
"ContentApi": "http://localhost:54494/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"DefaultConnection": "Data Source=../Database/deepdrft.db"
|
||||
},
|
||||
"ApiUrls": {
|
||||
"ContentApi": "http://localhost:12777/api/"
|
||||
"ContentApi": "http://localhost:12777/"
|
||||
},
|
||||
"ForwardedHeaders": {
|
||||
"DisableHttpsRedirection": "true"
|
||||
|
||||
Reference in New Issue
Block a user