Skip to content

Commit 01c48ce

Browse files
committed
KenjiNX version cache, provider, and pinning support
1 parent d3b3eda commit 01c48ce

6 files changed

Lines changed: 32 additions & 13 deletions

File tree

src/Client/UpdateClient/UpdateClient.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.CompilerServices;
2+
23
// ReSharper disable UnusedMember.Global
34
// ReSharper disable MemberCanBePrivate.Global
45
// ReSharper disable UnusedType.Global
@@ -12,7 +13,7 @@ public partial class UpdateClient : IDisposable
1213
{
1314
private readonly UpdateClientConfig _config;
1415
private readonly HttpClient _http;
15-
16+
1617
/// <summary>
1718
/// Create a new <see cref="UpdateClient"/> with a given configuration
1819
/// </summary>
@@ -36,10 +37,10 @@ void IDisposable.Dispose()
3637
}
3738

3839
private string QualifyUriPath(string path) => $"{_config.ServerEndpoint.TrimEnd('/')}/{path}";
39-
40-
private void Log(string format, IEnumerable<object>? args = null, [CallerMemberName] string caller = null!)
40+
41+
private void Log(string format, IEnumerable<object>? args = null, [CallerMemberName] string caller = null!)
4142
=> _config.Logger(format, args?.ToArray() ?? [], caller);
42-
43+
4344
private void ApplyAuthorization(HttpRequestMessage httpRequest)
4445
{
4546
httpRequest.Headers.Add("Authorization", _config.AdminAccessToken);

src/Common/Enums/ReleaseChannel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public enum ReleaseChannel
44
{
55
Stable,
66
Canary,
7-
Custom1
7+
Custom1,
8+
KenjiNX
89
}
910

1011
public static partial class EnumExtensions
@@ -22,6 +23,7 @@ public static bool TryParseAsReleaseChannel(this string? rawRc, out ReleaseChann
2223
"stable" => ReleaseChannel.Stable,
2324
"canary" => ReleaseChannel.Canary,
2425
"custom1" => ReleaseChannel.Custom1,
26+
"kenjinx" or "kenji" => ReleaseChannel.KenjiNX,
2527
_ => null
2628
};
2729

src/Server/Controllers/Api/v1/Admin/RefreshCacheController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class RefreshCacheController : ControllerBase
1313
{
1414
{ ReleaseChannel.Stable, DateTimeOffset.MinValue },
1515
{ ReleaseChannel.Canary, DateTimeOffset.MinValue },
16-
{ ReleaseChannel.Custom1, DateTimeOffset.MinValue }
16+
{ ReleaseChannel.Custom1, DateTimeOffset.MinValue },
17+
{ ReleaseChannel.KenjiNX, DateTimeOffset.MinValue }
1718
};
1819

1920
[HttpPatch]

src/Server/Initialization/VersionProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class VersionProvider
2222
public Entry Stable { get; set; } = new();
2323
public Entry Canary { get; set; } = new();
2424
public Entry Custom1 { get; set; } = new();
25+
public Entry KenjiNX { get; set; } = new();
2526

2627
public void IncrementAndReset(ReleaseChannel rc = ReleaseChannel.Stable)
2728
{
@@ -38,6 +39,9 @@ public void IncrementAndReset(ReleaseChannel rc = ReleaseChannel.Stable)
3839
case ReleaseChannel.Custom1:
3940
Custom1 = Custom1.NextMajor();
4041
break;
42+
case ReleaseChannel.KenjiNX:
43+
KenjiNX = KenjiNX.NextMajor();
44+
break;
4145
default:
4246
return;
4347
}

src/Server/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
builder.Services.AddKeyedSingleton<VersionCache>("stableCache");
2929
builder.Services.AddKeyedSingleton<VersionCache>("canaryCache");
3030
builder.Services.AddKeyedSingleton<VersionCache>("custom1Cache");
31+
builder.Services.AddKeyedSingleton<VersionCache>("kenjinxCache");
3132

3233
Swagger.TrySetup(builder);
3334

src/Server/Services/GitLab/VersionCache.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void Init(ProjectId projectId, PinnedVersions pinnedVersions) => Executor
100100

101101
_logger.LogInformation("Refreshing version cache for {project} every {timePeriod} minutes.",
102102
ProjectName, _refreshTimer.Period.TotalMinutes);
103-
103+
104104
while (await _refreshTimer.WaitForNextTickAsync())
105105
{
106106
await RefreshAsync();
@@ -116,7 +116,8 @@ public void Init(ProjectId projectId, PinnedVersions pinnedVersions) => Executor
116116
if (!HasProjectInfo)
117117
return null;
118118

119-
if (PinnedVersions.Find(platform, arch) is { } pinnedVersion && TryGetValue(pinnedVersion, out var pinnedLatest))
119+
if (PinnedVersions.Find(platform, arch) is { } pinnedVersion &&
120+
TryGetValue(pinnedVersion, out var pinnedLatest))
120121
return pinnedLatest;
121122

122123
return Latest;
@@ -160,7 +161,7 @@ public async Task RefreshAsync()
160161
{
161162
Tag = release.TagName,
162163
ReleaseUrl = ReleaseUrlFormat.Format(release.TagName),
163-
Downloads = new DownloadLinks
164+
Downloads = new DownloadLinks
164165
{
165166
Windows = new DownloadLinks.SupportedPlatform
166167
{
@@ -239,25 +240,34 @@ public static void InitializeVersionCaches(WebApplication app)
239240
var pvLogger = app.Services.Get<ILoggerFactory>().CreateLogger<PinnedVersions>();
240241

241242
var stableCache = app.Services.GetRequiredKeyedService<VersionCache>("stableCache");
242-
stableCache.Init(stableSource,
243+
stableCache.Init(stableSource,
243244
new PinnedVersions(pvLogger, vpSection.GetSection("Stable")));
244245

245246
var canarySource = versionCacheSection.GetValue<string>("Canary");
246247

247248
if (canarySource != null)
248249
{
249250
var canaryCache = app.Services.GetRequiredKeyedService<VersionCache>("canaryCache");
250-
canaryCache.Init(canarySource,
251+
canaryCache.Init(canarySource,
251252
new PinnedVersions(pvLogger, vpSection.GetSection("Canary")));
252253
}
253-
254+
254255
var custom1Source = versionCacheSection.GetValue<string>("Custom1");
255256

256257
if (custom1Source != null)
257258
{
258259
var canaryCache = app.Services.GetRequiredKeyedService<VersionCache>("custom1Cache");
259-
canaryCache.Init(custom1Source,
260+
canaryCache.Init(custom1Source,
260261
new PinnedVersions(pvLogger, vpSection.GetSection("Custom1")));
261262
}
263+
264+
var kenjiNxSource = versionCacheSection.GetValue<string>("KenjiNX");
265+
266+
if (kenjiNxSource != null)
267+
{
268+
var kenjiCache = app.Services.GetRequiredKeyedService<VersionCache>("kenjinxCache");
269+
kenjiCache.Init(custom1Source,
270+
new PinnedVersions(pvLogger, vpSection.GetSection("KenjiNX")));
271+
}
262272
}
263273
}

0 commit comments

Comments
 (0)