Skip to content

Commit

Permalink
add "alias" feature for dalamud-declarative
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Apr 16, 2024
1 parent 31534ed commit 9fcbdc8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
38 changes: 31 additions & 7 deletions XLWebServices/Controllers/Dalamud/ReleaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public ReleaseController(FallibleService<DalamudReleaseDataService> 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";

Expand All @@ -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]
Expand Down
14 changes: 13 additions & 1 deletion XLWebServices/Services/DalamudReleaseDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public DalamudReleaseDataAvailabilityFilter(FallibleService<DalamudReleaseDataSe

public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
if (_dalamudReleaseData.HasFailed || _dalamudReleaseData.Get()?.DalamudVersions == null)
if (_dalamudReleaseData.HasFailed ||
_dalamudReleaseData.Get()?.DalamudVersions == null ||
_dalamudReleaseData.Get()?.DalamudChangelogs == null ||
_dalamudReleaseData.Get()?.DeclarativeAliases == null)
{
context.Result = new StatusCodeResult(503);
return;
Expand All @@ -44,6 +47,8 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE

public IReadOnlyDictionary<string, DalamudVersion> DalamudVersions { get; private set; }

public IReadOnlyDictionary<string, string> DeclarativeAliases { get; private set; }

public DalamudReleaseDataService(IConfiguration config, FileCacheService cache,
ILogger<DalamudReleaseDataService> logger, GitHubService github, DiscordHookService discord,
ConfigMasterService configMaster)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<string, DalamudDeclarativeTrack> Tracks { get; set; } = new();
Expand Down

0 comments on commit 9fcbdc8

Please sign in to comment.