diff --git a/MareSynchronosServer/MareSynchronosShared/Utils/StaticFilesServerConfiguration.cs b/MareSynchronosServer/MareSynchronosShared/Utils/StaticFilesServerConfiguration.cs index 7404e8a..7725929 100644 --- a/MareSynchronosServer/MareSynchronosShared/Utils/StaticFilesServerConfiguration.cs +++ b/MareSynchronosServer/MareSynchronosShared/Utils/StaticFilesServerConfiguration.cs @@ -29,6 +29,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase sb.AppendLine($"{nameof(CacheDirectory)} => {CacheDirectory}"); sb.AppendLine($"{nameof(DownloadQueueSize)} => {DownloadQueueSize}"); sb.AppendLine($"{nameof(DownloadQueueReleaseSeconds)} => {DownloadQueueReleaseSeconds}"); + sb.AppendLine($"{nameof(CdnShardConfiguration)} => {string.Join(", ", CdnShardConfiguration.ToString())}"); return sb.ToString(); } } diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/Controllers/ServerFilesController.cs b/MareSynchronosServer/MareSynchronosStaticFilesServer/Controllers/ServerFilesController.cs index bbef50a..97620f7 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/Controllers/ServerFilesController.cs +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/Controllers/ServerFilesController.cs @@ -83,25 +83,29 @@ public class ServerFilesController : ControllerBase foreach (var file in cacheFile) { var forbiddenFile = forbiddenFiles.SingleOrDefault(f => string.Equals(f.Hash, file.Hash, StringComparison.OrdinalIgnoreCase)); + Uri? baseUrl = null; - List selectedShards = new(); - var matchingShards = allFileShards.Where(f => new Regex(f.FileMatch).IsMatch(file.Hash)).ToList(); - - if (string.Equals(Continent, "*", StringComparison.Ordinal)) + if (forbiddenFile == null) { - selectedShards = matchingShards; - } - else - { - selectedShards = matchingShards.Where(c => c.Continents.Contains(Continent, StringComparer.OrdinalIgnoreCase)).ToList(); - if (!selectedShards.Any()) selectedShards = matchingShards; - } + List selectedShards = new(); + var matchingShards = allFileShards.Where(f => new Regex(f.FileMatch).IsMatch(file.Hash)).ToList(); - var shard = selectedShards - .OrderBy(s => s.Continents.Contains("*", StringComparer.Ordinal) ? 0 : 1) - .ThenBy(g => Guid.NewGuid()).FirstOrDefault(); + if (string.Equals(Continent, "*", StringComparison.Ordinal)) + { + 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(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(nameof(StaticFilesServerConfiguration.CdnFullUrl)); + } response.Add(new DownloadFileDto { @@ -110,7 +114,7 @@ public class ServerFilesController : ControllerBase IsForbidden = forbiddenFile != null, Hash = file.Hash, Size = file.Size, - Url = baseUrl.ToString(), + Url = baseUrl?.ToString() ?? string.Empty, }); }