Improve API base URL handling for downloads and logging

Refactored API and Blazor client to dynamically construct download URLs using the configured API base URL instead of hardcoded localhost addresses. Enhanced root endpoint and startup logs to reflect environment-specific URLs. Added GetBaseUrl() to ITuneRipperApiService for consistent URL generation.
This commit is contained in:
Michal Vrba
2025-12-16 14:46:05 +01:00
parent 879fbd4a53
commit 471010c536
3 changed files with 100 additions and 58 deletions
+16 -8
View File
@@ -428,8 +428,9 @@
Logger.LogInformation("Downloading session ZIP for session: {SessionId}", currentSessionId);
// Create the download URL for the ZIP file
var zipDownloadUrl = $"https://localhost:7160/api/download/zip/{currentSessionId}";
// Create the download URL for the ZIP file using the configured API base URL
var baseUrl = ApiService.GetBaseUrl();
var zipDownloadUrl = $"{baseUrl}/api/download/zip/{currentSessionId}";
// Use browser to download the ZIP file
await JSRuntime.InvokeVoidAsync("open", zipDownloadUrl, "_blank");
@@ -628,17 +629,24 @@
// Use the actual video title from API
string title = currentVideoDetails?.Title ?? result.VideoDetails?.Title ?? ExtractTitleFromUrl(youtubeUrl);
// Create the session-aware download URL
// Create the session-aware download URL using the configured API base URL
string downloadUrl;
if (!string.IsNullOrEmpty(result.DownloadUrl) && result.DownloadUrl.Contains(sessionId))
if (!string.IsNullOrEmpty(result.DownloadUrl) && result.DownloadUrl.StartsWith("http"))
{
// Server provided a session-aware download URL
downloadUrl = result.DownloadUrl.StartsWith("http") ? result.DownloadUrl : $"https://localhost:7160{result.DownloadUrl}";
// Server provided a full download URL
downloadUrl = result.DownloadUrl;
}
else if (!string.IsNullOrEmpty(result.DownloadUrl) && result.DownloadUrl.StartsWith("/"))
{
// Server provided a relative URL, make it absolute using the API base URL
var baseUrl = ApiService.GetBaseUrl();
downloadUrl = $"{baseUrl}{result.DownloadUrl}";
}
else
{
// Construct session-aware download URL
downloadUrl = $"https://localhost:7160/api/download/{sessionId}/{jobId}";
// Construct session-aware download URL using the API base URL
var baseUrl = ApiService.GetBaseUrl();
downloadUrl = $"{baseUrl}/api/download/{sessionId}/{jobId}";
}
downloadLinks.Add(new DownloadItem