mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
fix: decode base64 URLs once at startup in static fields
- Changed from decoding in constructor to static readonly fields - Decode happens once per class initialization, stored in memory - Cleaner implementation, no repeated decoding per instance - All three SquidWTF services updated (Metadata, Download, Validator)
This commit is contained in:
@@ -26,9 +26,14 @@ public class SquidWTFDownloadService : BaseDownloadService
|
|||||||
private DateTime _lastRequestTime = DateTime.MinValue;
|
private DateTime _lastRequestTime = DateTime.MinValue;
|
||||||
private readonly int _minRequestIntervalMs = 200;
|
private readonly int _minRequestIntervalMs = 200;
|
||||||
|
|
||||||
// Base64 encoded to avoid GitHub detection
|
private static readonly string SquidWTFApiBase = DecodeBaseUrl();
|
||||||
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
|
||||||
private readonly string SquidWTFApiBase;
|
private static string DecodeBaseUrl()
|
||||||
|
{
|
||||||
|
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||||
|
var bytes = Convert.FromBase64String(encoded);
|
||||||
|
return Encoding.UTF8.GetString(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
protected override string ProviderName => "squidwtf";
|
protected override string ProviderName => "squidwtf";
|
||||||
|
|
||||||
@@ -45,10 +50,6 @@ public class SquidWTFDownloadService : BaseDownloadService
|
|||||||
{
|
{
|
||||||
_httpClient = httpClientFactory.CreateClient();
|
_httpClient = httpClientFactory.CreateClient();
|
||||||
_squidwtfSettings = SquidWTFSettings.Value;
|
_squidwtfSettings = SquidWTFSettings.Value;
|
||||||
|
|
||||||
// Decode the base URL
|
|
||||||
var bytes = Convert.FromBase64String(EncodedBaseUrl);
|
|
||||||
SquidWTFApiBase = Encoding.UTF8.GetString(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region BaseDownloadService Implementation
|
#region BaseDownloadService Implementation
|
||||||
|
|||||||
@@ -22,9 +22,14 @@ public class SquidWTFMetadataService : IMusicMetadataService
|
|||||||
private readonly ILogger<SquidWTFMetadataService> _logger;
|
private readonly ILogger<SquidWTFMetadataService> _logger;
|
||||||
private readonly RedisCacheService _cache;
|
private readonly RedisCacheService _cache;
|
||||||
|
|
||||||
// Base64 encoded to avoid GitHub detection
|
private static readonly string BaseUrl = DecodeBaseUrl();
|
||||||
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
|
||||||
private readonly string BaseUrl;
|
private static string DecodeBaseUrl()
|
||||||
|
{
|
||||||
|
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||||
|
var bytes = Convert.FromBase64String(encoded);
|
||||||
|
return Encoding.UTF8.GetString(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
public SquidWTFMetadataService(
|
public SquidWTFMetadataService(
|
||||||
IHttpClientFactory httpClientFactory,
|
IHttpClientFactory httpClientFactory,
|
||||||
@@ -38,10 +43,6 @@ public class SquidWTFMetadataService : IMusicMetadataService
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
|
|
||||||
// Decode the base URL
|
|
||||||
var bytes = Convert.FromBase64String(EncodedBaseUrl);
|
|
||||||
BaseUrl = Encoding.UTF8.GetString(bytes);
|
|
||||||
|
|
||||||
// Set up default headers
|
// Set up default headers
|
||||||
_httpClient.DefaultRequestHeaders.Add("User-Agent",
|
_httpClient.DefaultRequestHeaders.Add("User-Agent",
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0");
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0");
|
||||||
|
|||||||
@@ -13,9 +13,14 @@ public class SquidWTFStartupValidator : BaseStartupValidator
|
|||||||
{
|
{
|
||||||
private readonly SquidWTFSettings _settings;
|
private readonly SquidWTFSettings _settings;
|
||||||
|
|
||||||
// Base64 encoded to avoid GitHub detection
|
private static readonly string _apiBase = DecodeBaseUrl();
|
||||||
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
|
||||||
private readonly string _apiBase;
|
private static string DecodeBaseUrl()
|
||||||
|
{
|
||||||
|
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
|
||||||
|
var bytes = Convert.FromBase64String(encoded);
|
||||||
|
return Encoding.UTF8.GetString(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
public override string ServiceName => "SquidWTF";
|
public override string ServiceName => "SquidWTF";
|
||||||
|
|
||||||
@@ -23,10 +28,6 @@ public class SquidWTFStartupValidator : BaseStartupValidator
|
|||||||
: base(httpClient)
|
: base(httpClient)
|
||||||
{
|
{
|
||||||
_settings = settings.Value;
|
_settings = settings.Value;
|
||||||
|
|
||||||
// Decode the base URL
|
|
||||||
var bytes = Convert.FromBase64String(EncodedBaseUrl);
|
|
||||||
_apiBase = Encoding.UTF8.GetString(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<ValidationResult> ValidateAsync(CancellationToken cancellationToken)
|
public override async Task<ValidationResult> ValidateAsync(CancellationToken cancellationToken)
|
||||||
|
|||||||
Reference in New Issue
Block a user