File tree Expand file tree Collapse file tree
Server/Controllers/Api/v1/Admin Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,28 @@ public partial class UpdateClient
2525
2626 return await resp . Content . ReadAsStringAsync ( ) ;
2727 }
28+
29+ /// <summary>
30+ /// Query the current version for a release channel.
31+ /// </summary>
32+ /// <param name="rc">The target release channel.</param>
33+ /// <returns>Plain version string if request success; null if non-200 series HTTP status code or if not configured to support this endpoint.</returns>
34+ public async Task < string ? > GetCurrentVersionAsync ( ReleaseChannel rc )
35+ {
36+ var httpRequest = new HttpRequestMessage ( HttpMethod . Get ,
37+ $ "{ Constants . FullRouteName_Api_Versioning } /{ Constants . RouteName_Api_Versioning_GetCurrentVersion } ?rc={ rc . QueryStringValue } ") ;
38+
39+ var resp = await _http . SendAsync ( httpRequest ) ;
40+
41+ if ( ! resp . IsSuccessStatusCode )
42+ {
43+ Log ( "Getting current version failed: received status code {0}; content body: {1}" ,
44+ [ Enum . GetName ( resp . StatusCode ) ?? $ "{ ( int ) resp . StatusCode } ", await resp . Content . ReadAsStringAsync ( ) ] ) ;
45+ return null ;
46+ }
47+
48+ return await resp . Content . ReadAsStringAsync ( ) ;
49+ }
2850
2951 /// <summary>
3052 /// Requests the configured update server to increment its version for a given release channel.
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ internal static class Constants
2020 public const string RouteName_Api_Version = "version" ;
2121 public const string RouteName_Api_Versioning = "versioning" ;
2222 public const string RouteName_Api_Versioning_GetNextVersion = "next" ;
23+ public const string RouteName_Api_Versioning_GetCurrentVersion = "current" ;
2324 public const string RouteName_Api_Versioning_AdvanceVersion = "advance" ;
2425 public const string RouteName_Api_Versioning_IncrementVersion = "increment" ;
2526 public const string RouteName_Api_Meta = "meta" ;
Original file line number Diff line number Diff line change @@ -34,6 +34,24 @@ public async Task<ActionResult<string>> GetNext([FromQuery] string rc)
3434 return Ok ( versionProviderService . GetNextVersion ( releaseChannel ) ) ;
3535 }
3636
37+ [ HttpGet ( Constants . RouteName_Api_Versioning_GetCurrentVersion ) ]
38+ public async Task < ActionResult < string > > GetCurrent ( [ FromQuery ] string rc )
39+ {
40+ if ( ! rc . TryParseAsReleaseChannel ( out var releaseChannel ) )
41+ return Problem (
42+ $ "Unknown release channel '{ rc } '; valid are '{ Constants . StableRoute } ' and '{ Constants . CanaryRoute } '",
43+ statusCode : 404 ) ;
44+
45+ var versionProviderService = HttpContext . RequestServices
46+ . GetService < VersionProviderService > ( ) ;
47+
48+ if ( versionProviderService is null )
49+ return Problem ( "This instance of Ryubing UpdateServer is not configured to support this endpoint." ,
50+ statusCode : 418 ) ;
51+
52+ return Ok ( versionProviderService . GetCurrentVersion ( releaseChannel ) ) ;
53+ }
54+
3755 [ HttpPatch ( Constants . RouteName_Api_Versioning_IncrementVersion ) ]
3856 [ ProducesResponseType ( StatusCodes . Status401Unauthorized ) ]
3957 [ ProducesResponseType ( StatusCodes . Status418ImATeapot ) ]
You can’t perform that action at this time.
0 commit comments