more logging

This commit is contained in:
rootdarkarchon
2024-01-13 10:57:23 +01:00
parent 71dd103dea
commit ba96fd2d5e
2 changed files with 21 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
sb.AppendLine($"{nameof(CacheDirectory)} => {CacheDirectory}"); sb.AppendLine($"{nameof(CacheDirectory)} => {CacheDirectory}");
sb.AppendLine($"{nameof(DownloadQueueSize)} => {DownloadQueueSize}"); sb.AppendLine($"{nameof(DownloadQueueSize)} => {DownloadQueueSize}");
sb.AppendLine($"{nameof(DownloadQueueReleaseSeconds)} => {DownloadQueueReleaseSeconds}"); sb.AppendLine($"{nameof(DownloadQueueReleaseSeconds)} => {DownloadQueueReleaseSeconds}");
sb.AppendLine($"{nameof(CdnShardConfiguration)} => {string.Join(", ", CdnShardConfiguration.ToString())}");
return sb.ToString(); return sb.ToString();
} }
} }

View File

@@ -83,25 +83,29 @@ public class ServerFilesController : ControllerBase
foreach (var file in cacheFile) foreach (var file in cacheFile)
{ {
var forbiddenFile = forbiddenFiles.SingleOrDefault(f => string.Equals(f.Hash, file.Hash, StringComparison.OrdinalIgnoreCase)); var forbiddenFile = forbiddenFiles.SingleOrDefault(f => string.Equals(f.Hash, file.Hash, StringComparison.OrdinalIgnoreCase));
Uri? baseUrl = null;
List<CdnShardConfiguration> selectedShards = new(); if (forbiddenFile == null)
var matchingShards = allFileShards.Where(f => new Regex(f.FileMatch).IsMatch(file.Hash)).ToList();
if (string.Equals(Continent, "*", StringComparison.Ordinal))
{ {
selectedShards = matchingShards; List<CdnShardConfiguration> selectedShards = new();
} var matchingShards = allFileShards.Where(f => new Regex(f.FileMatch).IsMatch(file.Hash)).ToList();
else
{
selectedShards = matchingShards.Where(c => c.Continents.Contains(Continent, StringComparer.OrdinalIgnoreCase)).ToList();
if (!selectedShards.Any()) selectedShards = matchingShards;
}
var shard = selectedShards if (string.Equals(Continent, "*", StringComparison.Ordinal))
.OrderBy(s => s.Continents.Contains("*", StringComparer.Ordinal) ? 0 : 1) {
.ThenBy(g => Guid.NewGuid()).FirstOrDefault(); selectedShards = matchingShards;
}
else
{
selectedShards = matchingShards.Where(c => c.Continents.Contains(Continent, StringComparer.OrdinalIgnoreCase)).ToList();
if (!selectedShards.Any()) selectedShards = matchingShards;
}
var baseUrl = shard?.CdnFullUrl ?? _configuration.GetValue<Uri>(nameof(StaticFilesServerConfiguration.CdnFullUrl)); var shard = selectedShards
.OrderBy(s => s.Continents.Contains("*", StringComparer.Ordinal) ? 0 : 1)
.ThenBy(g => Guid.NewGuid()).FirstOrDefault();
baseUrl = shard?.CdnFullUrl ?? _configuration.GetValue<Uri>(nameof(StaticFilesServerConfiguration.CdnFullUrl));
}
response.Add(new DownloadFileDto response.Add(new DownloadFileDto
{ {
@@ -110,7 +114,7 @@ public class ServerFilesController : ControllerBase
IsForbidden = forbiddenFile != null, IsForbidden = forbiddenFile != null,
Hash = file.Hash, Hash = file.Hash,
Size = file.Size, Size = file.Size,
Url = baseUrl.ToString(), Url = baseUrl?.ToString() ?? string.Empty,
}); });
} }