From a128f5c0c707dc853891c5b212c6deba7e817718 Mon Sep 17 00:00:00 2001 From: Mihai Date: Fri, 6 Nov 2026 20:12:41 +0200 Subject: [PATCH] feat: Link release feed with channels and minimum versions (HCR-014) - GET /api/simracing/link/release?channel=beta reads TurnOneLink:Channels:beta (falls back to stable); the default response is unchanged apart from the new channel, minSupportedVersion and velopackFeedUrl fields. - GET /api/simracing/link/compat?version= tells Link whether it is still supported and may upload (TurnOneLink:MinSupportedVersion / MinUploadVersion). - Website: LinkReleaseInfo gains the new fields; getLinkRelease takes a channel. --- .../Controllers/SimracingLinkController.cs | 83 +++++++++++++++++-- .../Tests/API/SimracingLinkControllerTests.cs | 82 ++++++++++++++++++ turn-one-client/lib/simracing/api.ts | 7 +- 3 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 turn-one-backend/Tests/API/SimracingLinkControllerTests.cs diff --git a/turn-one-backend/API/Controllers/SimracingLinkController.cs b/turn-one-backend/API/Controllers/SimracingLinkController.cs index 5e5790b..bc7082e 100644 --- a/turn-one-backend/API/Controllers/SimracingLinkController.cs +++ b/turn-one-backend/API/Controllers/SimracingLinkController.cs @@ -5,12 +5,15 @@ namespace API.Controllers; /// /// Release metadata for the Turn One Link desktop app, so the download pages can render real -/// version/size/checksum information instead of hardcoding it. +/// version/size/checksum information instead of hardcoding it, plus the release channels and +/// minimum versions Link checks at startup (HCR-014). /// [ApiController] [Route("api/simracing/link")] public class SimracingLinkController : ControllerBase { + private const string DefaultFeedUrl = "https://github.com/MihaiM21/Turn-One-Link"; + private readonly IConfiguration _config; public SimracingLinkController(IConfiguration config) @@ -29,6 +32,11 @@ public class LinkReleaseDto public long? SizeBytes { get; set; } public string MinWindowsBuild { get; set; } = "Windows 10 (build 19041) or later"; public List Changelog { get; set; } = new(); + + // HCR-014 additions (absent from older clients' expectations, so purely additive). + public string Channel { get; set; } = "stable"; + public string? MinSupportedVersion { get; set; } + public string VelopackFeedUrl { get; set; } = DefaultFeedUrl; } public class ChangelogEntry @@ -38,12 +46,32 @@ public class ChangelogEntry public List Changes { get; set; } = new(); } + public class CompatDto + { + public bool Supported { get; set; } + public bool UploadsAccepted { get; set; } + public string? LatestVersion { get; set; } + public string? Message { get; set; } + } + + /// + /// Stable comes from the flat TurnOneLink keys (as before) or TurnOneLink:Channels:stable; + /// beta from TurnOneLink:Channels:beta, falling back to stable when no beta is configured. + /// [HttpGet("release")] [AllowAnonymous] [ResponseCache(Duration = 300, Location = ResponseCacheLocation.Any)] - public ActionResult GetRelease() + public ActionResult GetRelease([FromQuery] string? channel = null) { - var section = _config.GetSection("TurnOneLink"); + var root = _config.GetSection("TurnOneLink"); + var wantBeta = string.Equals(channel, "beta", StringComparison.OrdinalIgnoreCase); + + var beta = root.GetSection("Channels:beta"); + var stable = root.GetSection("Channels:stable"); + var (section, resolved) = wantBeta && beta.Exists() + ? (beta, "beta") + : (stable.Exists() ? stable : root, "stable"); + var downloadUrl = section["DownloadUrl"]; var dto = new LinkReleaseDto @@ -52,7 +80,10 @@ public ActionResult GetRelease() Version = section["Version"], DownloadUrl = string.IsNullOrWhiteSpace(downloadUrl) ? null : downloadUrl, Sha256 = section["Sha256"], - MinWindowsBuild = section["MinWindowsBuild"] ?? "Windows 10 (build 19041) or later" + MinWindowsBuild = root["MinWindowsBuild"] ?? "Windows 10 (build 19041) or later", + Channel = resolved, + MinSupportedVersion = root["MinSupportedVersion"], + VelopackFeedUrl = root["VelopackFeedUrl"] ?? DefaultFeedUrl, }; if (DateTime.TryParse(section["ReleasedAt"], out var released)) @@ -61,8 +92,50 @@ public ActionResult GetRelease() if (long.TryParse(section["SizeBytes"], out var size)) dto.SizeBytes = size; - dto.Changelog = section.GetSection("Changelog").Get>() ?? new List(); + dto.Changelog = root.GetSection("Changelog").Get>() ?? new List(); return Ok(dto); } + + /// Whether a Link build may still run and upload. Link calls this at startup. + [HttpGet("compat")] + [AllowAnonymous] + [ResponseCache(Duration = 300, Location = ResponseCacheLocation.Any)] + public ActionResult Compat([FromQuery] string? version) + { + if (!TryParseVersion(version, out var current)) + return BadRequest(new { message = "version must look like 1.2.3" }); + + var root = _config.GetSection("TurnOneLink"); + var supported = IsAtLeast(current, root["MinSupportedVersion"]); + var uploads = supported && IsAtLeast(current, root["MinUploadVersion"]); + var latest = root.GetSection("Channels:stable")["Version"] ?? root["Version"]; + + return Ok(new CompatDto + { + Supported = supported, + UploadsAccepted = uploads, + LatestVersion = latest, + Message = !supported + ? "This version of Turn One Link is no longer supported. Please update." + : !uploads + ? "Update Turn One Link to keep uploading laps — this version has a known timing bug." + : null, + }); + } + + /// True when is unset or is at least it. + public static bool IsAtLeast(Version current, string? minimum) => + !TryParseVersion(minimum, out var min) || current >= min; + + /// Accepts "1.2", "1.2.3", "v1.2.3" and "1.2.3-beta" (pre-release suffix ignored). + public static bool TryParseVersion(string? value, out Version version) + { + version = new Version(0, 0); + if (string.IsNullOrWhiteSpace(value)) return false; + var core = value.Trim().TrimStart('v', 'V').Split('-', '+')[0]; + if (!Version.TryParse(core, out var parsed)) return false; + version = parsed; + return true; + } } diff --git a/turn-one-backend/Tests/API/SimracingLinkControllerTests.cs b/turn-one-backend/Tests/API/SimracingLinkControllerTests.cs new file mode 100644 index 0000000..a7145ba --- /dev/null +++ b/turn-one-backend/Tests/API/SimracingLinkControllerTests.cs @@ -0,0 +1,82 @@ +using API.Controllers; +using FluentAssertions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; + +namespace Tests.API; + +/// HCR-014: release channels, minimum versions, unchanged default response. +public class SimracingLinkControllerTests +{ + private static SimracingLinkController Controller(Dictionary settings) => + new(new ConfigurationBuilder().AddInMemoryCollection(settings).Build()); + + private static readonly Dictionary Legacy = new() + { + ["TurnOneLink:Version"] = "1.2.0", + ["TurnOneLink:DownloadUrl"] = "https://example.test/TurnOneLink-win-Setup.exe", + ["TurnOneLink:Sha256"] = "abc", + ["TurnOneLink:ReleasedAt"] = "2026-11-06", + }; + + private static T Ok(ActionResult result) => (T)((OkObjectResult)result.Result!).Value!; + + [Fact] + public void Default_Request_Still_Returns_The_Flat_Stable_Release() + { + var dto = Ok(Controller(Legacy).GetRelease()); + + dto.Available.Should().BeTrue(); + dto.Version.Should().Be("1.2.0"); + dto.DownloadUrl.Should().EndWith("Setup.exe"); + dto.Channel.Should().Be("stable"); + dto.VelopackFeedUrl.Should().Contain("Turn-One-Link"); + } + + [Fact] + public void Beta_Channel_Uses_Its_Own_Section_Or_Falls_Back_To_Stable() + { + Ok(Controller(Legacy).GetRelease("beta")).Channel.Should().Be("stable"); + + var withBeta = new Dictionary(Legacy) + { + ["TurnOneLink:Channels:beta:Version"] = "1.3.0", + ["TurnOneLink:Channels:beta:DownloadUrl"] = "https://example.test/beta.exe", + }; + var dto = Ok(Controller(withBeta).GetRelease("beta")); + dto.Channel.Should().Be("beta"); + dto.Version.Should().Be("1.3.0"); + } + + [Theory] + [InlineData("1.1.0", false, false)] + [InlineData("1.2.0", true, false)] + [InlineData("1.2.1", true, true)] + [InlineData("v1.3.0-beta", true, true)] + public void Compat_Applies_Minimum_Versions(string version, bool supported, bool uploads) + { + var settings = new Dictionary(Legacy) + { + ["TurnOneLink:MinSupportedVersion"] = "1.2.0", + ["TurnOneLink:MinUploadVersion"] = "1.2.1", + }; + var dto = Ok(Controller(settings).Compat(version)); + + dto.Supported.Should().Be(supported); + dto.UploadsAccepted.Should().Be(uploads); + } + + [Fact] + public void Compat_Accepts_Everything_When_No_Minimum_Is_Configured() + { + var dto = Ok(Controller(Legacy).Compat("0.0.1")); + dto.Supported.Should().BeTrue(); + dto.UploadsAccepted.Should().BeTrue(); + } + + [Fact] + public void Compat_Rejects_A_Malformed_Version() + { + Controller(Legacy).Compat("latest").Result.Should().BeOfType(); + } +} diff --git a/turn-one-client/lib/simracing/api.ts b/turn-one-client/lib/simracing/api.ts index 308a83e..6439635 100644 --- a/turn-one-client/lib/simracing/api.ts +++ b/turn-one-client/lib/simracing/api.ts @@ -196,6 +196,10 @@ export interface LinkReleaseInfo { sizeBytes: number | null; minWindowsBuild: string; changelog: { version: string; date: string | null; changes: string[] }[]; + /** HCR-014: "stable" or "beta" — the channel this release belongs to. */ + channel?: "stable" | "beta"; + minSupportedVersion?: string | null; + velopackFeedUrl?: string; } // --------------------------------------------------------------------------- @@ -242,7 +246,8 @@ export const setVisibility = (id: string, visibility: number) => export const deleteSession = (id: string) => request(`/api/telemetry/sessions/${id}`, { method: "DELETE" }); -export const getLinkRelease = () => request("/api/simracing/link/release"); +export const getLinkRelease = (channel: "stable" | "beta" = "stable") => + request(`/api/simracing/link/release${channel === "beta" ? "?channel=beta" : ""}`); // --------------------------------------------------------------------------- // Lap-telemetry API v2