diff --git a/XLWebServices/Controllers/Dalamud/ReleaseController.cs b/XLWebServices/Controllers/Dalamud/ReleaseController.cs index 89e8bec..93cc696 100644 --- a/XLWebServices/Controllers/Dalamud/ReleaseController.cs +++ b/XLWebServices/Controllers/Dalamud/ReleaseController.cs @@ -39,6 +39,8 @@ public ReleaseController(FallibleService releaseCache [HttpGet] public IActionResult VersionInfo([FromQuery] string? track = "", [FromQuery] string? appId = "", [FromQuery] string? bucket = "Control") { + var releases = this.releaseCache.Get()!; + if (string.IsNullOrEmpty(track)) track = "release"; @@ -51,27 +53,49 @@ public IActionResult VersionInfo([FromQuery] string? track = "", [FromQuery] str if (appId != "goat" && appId != "xom" && appId != "helpy") return BadRequest("Invalid appId"); + string? keyOverride = null; + if (releases.DeclarativeAliases.TryGetValue(track, out var aliasTrack)) + { + track = aliasTrack; + keyOverride = releases.DalamudVersions[track].Key; + } + + DalamudReleaseDataService.DalamudVersion? resultVersion = null; switch (track) { case "release": { DownloadsOverTime.WithLabels(appId, bucket == "Canary" ? "Canary" : "Control").Inc(); - + if (bucket == "Canary" && this.releaseCache.Get()!.DalamudVersions.ContainsKey("canary") && isUseCanary) - return new JsonResult(this.releaseCache.Get()!.DalamudVersions["canary"]); - - return new JsonResult(this.releaseCache.Get()!.DalamudVersions["release"]); + { + resultVersion = this.releaseCache.Get()!.DalamudVersions["canary"]; + } + else + { + resultVersion = this.releaseCache.Get()!.DalamudVersions["release"]; + } } + break; default: { - if (!this.releaseCache.Get()!.DalamudVersions.TryGetValue(track, out var release)) - return new JsonResult(this.releaseCache.Get()!.DalamudVersions["release"]); + if (!this.releaseCache.Get()!.DalamudVersions.TryGetValue(track, out resultVersion)) + { + resultVersion = this.releaseCache.Get()!.DalamudVersions["release"]; + track = "release"; // Normalize track name for stat counting + } DownloadsOverTime.WithLabels(appId, track).Inc(); - return new JsonResult(release); } + break; } + + // Patch in the key of the aliased version + if (keyOverride != null) + resultVersion.Key = keyOverride; + + return new JsonResult(resultVersion); } [HttpGet] diff --git a/XLWebServices/Services/DalamudReleaseDataService.cs b/XLWebServices/Services/DalamudReleaseDataService.cs index 14f3e23..4a5d40d 100644 --- a/XLWebServices/Services/DalamudReleaseDataService.cs +++ b/XLWebServices/Services/DalamudReleaseDataService.cs @@ -23,7 +23,10 @@ public DalamudReleaseDataAvailabilityFilter(FallibleService DalamudVersions { get; private set; } + public IReadOnlyDictionary DeclarativeAliases { get; private set; } + public DalamudReleaseDataService(IConfiguration config, FileCacheService cache, ILogger logger, GitHubService github, DiscordHookService discord, ConfigMasterService configMaster) @@ -83,6 +88,11 @@ public async Task ClearCache() var declarative = await GetDeclarative(shaDeclarative); if (declarative == null) throw new Exception("Declarative was null"); + + // Go through declaratives and map aliases + this.DeclarativeAliases = declarative.Tracks + .Where(track => !string.IsNullOrEmpty(track.Value.Alias)) + .ToDictionary(track => track.Key, track => track.Value.Alias!); // Get tree var tree = await this.github.Client.Repository.Content.GetAllContentsByRef(repoOwner, repoName, shaDistrib); @@ -342,6 +352,8 @@ public class DalamudDeclarativeTrack public string ApplicableGameVersion { get; set; } = null!; public string RuntimeVersion { get; set; } = null!; + + public string? Alias { get; set; } } public Dictionary Tracks { get; set; } = new();