API Connection Cleanup & Bugfixes
This commit is contained in:
@@ -10,25 +10,43 @@ namespace DeepDrftContent.Controllers;
|
|||||||
public class TrackController : ControllerBase
|
public class TrackController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly DeepDrftContent.Services.FileDatabase.Services.FileDatabase _fileDatabase;
|
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;
|
_fileDatabase = fileDatabase;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{trackId}")]
|
[HttpGet("{trackId}")]
|
||||||
public async Task<ActionResult> GetTrack(string trackId)
|
public async Task<ActionResult> GetTrack(string trackId)
|
||||||
{
|
{
|
||||||
var file = await _fileDatabase.LoadResourceAsync<AudioBinary>(VaultConstants.Tracks, trackId);
|
_logger.LogInformation("GetTrack called with trackId: {TrackId}", trackId);
|
||||||
if (file == null) { return NotFound(); }
|
|
||||||
|
|
||||||
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]
|
[ApiKeyAuthorize]
|
||||||
[HttpPut("{trackId}")]
|
[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 audioBinary = AudioBinary.From(track);
|
||||||
var success = await _fileDatabase.RegisterResourceAsync(VaultConstants.Tracks, trackId, audioBinary);
|
var success = await _fileDatabase.RegisterResourceAsync(VaultConstants.Tracks, trackId, audioBinary);
|
||||||
return success ? Ok() : BadRequest("Failed to store audio track");
|
return success ? Ok() : BadRequest("Failed to store audio track");
|
||||||
|
|||||||
@@ -47,9 +47,11 @@ builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
if (app.Environment.IsProduction())
|
||||||
// Use forwarded headers before other middleware
|
{
|
||||||
app.UseForwardedHeaders();
|
// Use forwarded headers before other middleware
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@@ -58,7 +60,6 @@ if (app.Environment.IsDevelopment())
|
|||||||
|
|
||||||
app.UseCors("ContentApiPolicy");
|
app.UseCors("ContentApiPolicy");
|
||||||
app.UseApiKeyAuthentication(apiKeySettings.ApiKey);
|
app.UseApiKeyAuthentication(apiKeySettings.ApiKey);
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"DeepDrftContent.Controllers.TrackController": "Information"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using NetBlocks.Models;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace DeepDrftWeb.Client.Clients;
|
namespace DeepDrftWeb.Client.Clients;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class TrackMediaClient
|
|||||||
|
|
||||||
public async Task<TrackMediaResponse> GetTrackMedia(string trackId)
|
public async Task<TrackMediaResponse> GetTrackMedia(string trackId)
|
||||||
{
|
{
|
||||||
var response = await _http.GetAsync($"track/{trackId}");
|
var response = await _http.GetAsync($"api/track/{trackId}");
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var contentLength = response.Content.Headers.ContentLength ?? 0;
|
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 == null && _selectedTrack == null || track?.Id == _selectedTrack?.Id) return;
|
||||||
|
|
||||||
|
if (track is null)
|
||||||
|
{
|
||||||
|
await AudioPlaybackEngine.Stop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
await AudioPlaybackEngine.LoadTrack(track);
|
await AudioPlaybackEngine.LoadTrack(track);
|
||||||
|
}
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ApiUrls": {
|
"ApiUrls": {
|
||||||
"ContentApi": "http://localhost:54493/api/"
|
"ContentApi": "http://localhost:54494/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ApiUrls": {
|
"ApiUrls": {
|
||||||
"ContentApi": "https://media.deepdrft.com/api/"
|
"ContentApi": "https://media.deepdrft.com/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
},
|
},
|
||||||
"DetailedErrors": true,
|
"DetailedErrors": true,
|
||||||
"ApiUrls": {
|
"ApiUrls": {
|
||||||
"ContentApi": "http://localhost:54493/api/"
|
"ContentApi": "http://localhost:54494/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"DefaultConnection": "Data Source=../Database/deepdrft.db"
|
"DefaultConnection": "Data Source=../Database/deepdrft.db"
|
||||||
},
|
},
|
||||||
"ApiUrls": {
|
"ApiUrls": {
|
||||||
"ContentApi": "http://localhost:12777/api/"
|
"ContentApi": "http://localhost:12777/"
|
||||||
},
|
},
|
||||||
"ForwardedHeaders": {
|
"ForwardedHeaders": {
|
||||||
"DisableHttpsRedirection": "true"
|
"DisableHttpsRedirection": "true"
|
||||||
|
|||||||
Reference in New Issue
Block a user