mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
refactor: pass decoded SquidWTF URL from Program.cs to services
- Decode base64 URL once at startup in Program.cs - Pass decoded URL as constructor parameter to all SquidWTF services - Services receive plain URL, no decoding logic in service classes - Cleaner separation: encoding/decoding only in Program.cs - All service code remains unchanged, just receives decoded URL
This commit is contained in:
@@ -12,9 +12,19 @@ using allstarr.Services.Lyrics;
|
||||
using allstarr.Middleware;
|
||||
using allstarr.Filters;
|
||||
using Microsoft.Extensions.Http;
|
||||
using System.Text;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Decode SquidWTF API base URL once at startup
|
||||
var squidWtfApiBase = DecodeSquidWtfUrl();
|
||||
static string DecodeSquidWtfUrl()
|
||||
{
|
||||
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||
var bytes = Convert.FromBase64String(encoded);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
|
||||
// Determine backend type FIRST
|
||||
var backendType = builder.Configuration.GetValue<BackendType>("Backend:Type");
|
||||
|
||||
@@ -163,9 +173,26 @@ else if (musicService == MusicService.Deezer)
|
||||
}
|
||||
else if (musicService == MusicService.SquidWTF)
|
||||
{
|
||||
// SquidWTF services
|
||||
builder.Services.AddSingleton<IMusicMetadataService, SquidWTFMetadataService>();
|
||||
builder.Services.AddSingleton<IDownloadService, SquidWTFDownloadService>();
|
||||
// SquidWTF services - pass decoded URL
|
||||
builder.Services.AddSingleton<IMusicMetadataService>(sp =>
|
||||
new SquidWTFMetadataService(
|
||||
sp.GetRequiredService<IHttpClientFactory>(),
|
||||
sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<SubsonicSettings>>(),
|
||||
sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<SquidWTFSettings>>(),
|
||||
sp.GetRequiredService<ILogger<SquidWTFMetadataService>>(),
|
||||
sp.GetRequiredService<RedisCacheService>(),
|
||||
squidWtfApiBase));
|
||||
builder.Services.AddSingleton<IDownloadService>(sp =>
|
||||
new SquidWTFDownloadService(
|
||||
sp.GetRequiredService<IHttpClientFactory>(),
|
||||
sp.GetRequiredService<IConfiguration>(),
|
||||
sp.GetRequiredService<ILocalLibraryService>(),
|
||||
sp.GetRequiredService<IMusicMetadataService>(),
|
||||
sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<SubsonicSettings>>(),
|
||||
sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<SquidWTFSettings>>(),
|
||||
sp,
|
||||
sp.GetRequiredService<ILogger<SquidWTFDownloadService>>(),
|
||||
squidWtfApiBase));
|
||||
}
|
||||
|
||||
// Startup validation - register validators based on backend
|
||||
@@ -180,7 +207,11 @@ else
|
||||
|
||||
builder.Services.AddSingleton<IStartupValidator, DeezerStartupValidator>();
|
||||
builder.Services.AddSingleton<IStartupValidator, QobuzStartupValidator>();
|
||||
builder.Services.AddSingleton<IStartupValidator, SquidWTFStartupValidator>();
|
||||
builder.Services.AddSingleton<IStartupValidator>(sp =>
|
||||
new SquidWTFStartupValidator(
|
||||
sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<SquidWTFSettings>>(),
|
||||
sp.GetRequiredService<IHttpClientFactory>().CreateClient(),
|
||||
squidWtfApiBase));
|
||||
|
||||
// Register orchestrator as hosted service
|
||||
builder.Services.AddHostedService<StartupValidationOrchestrator>();
|
||||
|
||||
@@ -26,14 +26,7 @@ public class SquidWTFDownloadService : BaseDownloadService
|
||||
private DateTime _lastRequestTime = DateTime.MinValue;
|
||||
private readonly int _minRequestIntervalMs = 200;
|
||||
|
||||
private static readonly string SquidWTFApiBase = DecodeBaseUrl();
|
||||
|
||||
private static string DecodeBaseUrl()
|
||||
{
|
||||
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||
var bytes = Convert.FromBase64String(encoded);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
private readonly string SquidWTFApiBase;
|
||||
|
||||
protected override string ProviderName => "squidwtf";
|
||||
|
||||
@@ -45,11 +38,13 @@ public class SquidWTFDownloadService : BaseDownloadService
|
||||
IOptions<SubsonicSettings> subsonicSettings,
|
||||
IOptions<SquidWTFSettings> SquidWTFSettings,
|
||||
IServiceProvider serviceProvider,
|
||||
ILogger<SquidWTFDownloadService> logger)
|
||||
ILogger<SquidWTFDownloadService> logger,
|
||||
string apiBase)
|
||||
: base(configuration, localLibraryService, metadataService, subsonicSettings.Value, serviceProvider, logger)
|
||||
{
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
_squidwtfSettings = SquidWTFSettings.Value;
|
||||
SquidWTFApiBase = apiBase;
|
||||
}
|
||||
|
||||
#region BaseDownloadService Implementation
|
||||
|
||||
@@ -21,27 +21,21 @@ public class SquidWTFMetadataService : IMusicMetadataService
|
||||
private readonly SubsonicSettings _settings;
|
||||
private readonly ILogger<SquidWTFMetadataService> _logger;
|
||||
private readonly RedisCacheService _cache;
|
||||
|
||||
private static readonly string BaseUrl = DecodeBaseUrl();
|
||||
|
||||
private static string DecodeBaseUrl()
|
||||
{
|
||||
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||
var bytes = Convert.FromBase64String(encoded);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
private readonly string BaseUrl;
|
||||
|
||||
public SquidWTFMetadataService(
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IOptions<SubsonicSettings> settings,
|
||||
IOptions<SquidWTFSettings> squidwtfSettings,
|
||||
ILogger<SquidWTFMetadataService> logger,
|
||||
RedisCacheService cache)
|
||||
RedisCacheService cache,
|
||||
string baseUrl)
|
||||
{
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
_settings = settings.Value;
|
||||
_logger = logger;
|
||||
_cache = cache;
|
||||
BaseUrl = baseUrl;
|
||||
|
||||
// Set up default headers
|
||||
_httpClient.DefaultRequestHeaders.Add("User-Agent",
|
||||
|
||||
@@ -12,22 +12,15 @@ namespace allstarr.Services.SquidWTF;
|
||||
public class SquidWTFStartupValidator : BaseStartupValidator
|
||||
{
|
||||
private readonly SquidWTFSettings _settings;
|
||||
|
||||
private static readonly string _apiBase = DecodeBaseUrl();
|
||||
|
||||
private static string DecodeBaseUrl()
|
||||
{
|
||||
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||
var bytes = Convert.FromBase64String(encoded);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
private readonly string _apiBase;
|
||||
|
||||
public override string ServiceName => "SquidWTF";
|
||||
|
||||
public SquidWTFStartupValidator(IOptions<SquidWTFSettings> settings, HttpClient httpClient)
|
||||
public SquidWTFStartupValidator(IOptions<SquidWTFSettings> settings, HttpClient httpClient, string apiBase)
|
||||
: base(httpClient)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
_apiBase = apiBase;
|
||||
}
|
||||
|
||||
public override async Task<ValidationResult> ValidateAsync(CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user