Skip to content

Commit 697262e

Browse files
committed
improve GET /api/v1/meta
1 parent ccaa5cd commit 697262e

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Ryujinx.Systems.Update.Common;
4+
5+
public class CacheSourceMapping
6+
{
7+
[JsonPropertyName("stable")]
8+
public required VersionCacheSource Stable { get; set; }
9+
10+
[JsonPropertyName("canary")]
11+
public required VersionCacheSource? Canary { get; set; }
12+
}

src/Common/Models/VersionCacheSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public class VersionCacheSource
66
{
77
internal static VersionCacheSource Empty => new()
88
{
9-
Id = 0,
9+
Id = -1,
1010
Owner = string.Empty,
1111
Project = string.Empty
1212
};
13-
13+
1414
[JsonPropertyName("id")] public required long Id { get; set; }
1515
[JsonPropertyName("owner")] public required string Owner { get; set; }
1616
[JsonPropertyName("project")] public required string Project { get; set; }

src/Server/Controllers/Api/v1/MetaController.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System.Text.Json.Serialization;
2+
using Microsoft.AspNetCore.Mvc;
23
using Ryujinx.Systems.Update.Common;
34
using Ryujinx.Systems.Update.Server.Services.GitLab;
45

@@ -8,36 +9,33 @@ namespace Ryujinx.Systems.Update.Server.Controllers;
89
[ApiController]
910
public class MetaController : ControllerBase
1011
{
11-
private static readonly Dictionary<string, VersionCacheSource> CacheSources =
12-
new(2)
13-
{
14-
{ "stable", VersionCacheSource.Empty },
15-
{ "canary", VersionCacheSource.Empty }
16-
};
17-
12+
private static readonly CacheSourceMapping CacheSources = new()
13+
{
14+
Stable = VersionCacheSource.Empty,
15+
Canary = null
16+
};
17+
1818
[HttpGet]
1919
[ProducesResponseType(StatusCodes.Status200OK)]
2020
[Produces("application/json")]
2121
[EndpointDescription("Query the UpdateServer's internal version caches to determine what GitLab projects back each release channel.")]
22-
public ActionResult<Dictionary<string, VersionCacheSource>> Action()
22+
public ActionResult<CacheSourceMapping> Action(
23+
[FromKeyedServices("stableCache")] VersionCache stableCache,
24+
[FromKeyedServices("canaryCache")] VersionCache canaryCache)
2325
{
24-
var stableCache = HttpContext.RequestServices.GetRequiredKeyedService<VersionCache>("stableCache");
25-
2626
if (!stableCache.HasProjectInfo)
2727
return BadRequest("Stable cache isn't initialized yet.");
28-
29-
CacheSources["stable"] = new VersionCacheSource
28+
29+
CacheSources.Stable = new VersionCacheSource
3030
{
3131
Id = stableCache.ProjectId,
3232
Owner = stableCache.ProjectPath.Split('/')[0],
3333
Project = stableCache.ProjectPath.Split('/')[1]
3434
};
35-
36-
var canaryCache = HttpContext.RequestServices.GetKeyedService<VersionCache>("canaryCache");
3735

38-
if (canaryCache?.HasProjectInfo ?? false)
36+
if (canaryCache.HasProjectInfo)
3937
{
40-
CacheSources["canary"] = new VersionCacheSource
38+
CacheSources.Canary = new VersionCacheSource
4139
{
4240
Id = canaryCache.ProjectId,
4341
Owner = canaryCache.ProjectPath.Split('/')[0],

0 commit comments

Comments
 (0)