@@ -17,53 +17,54 @@ public async Task<ActionResult> DownloadCustom(
1717 [ FromQuery ] string arch ,
1818 [ FromQuery ] string rc = Constants . StableRoute ,
1919 [ FromQuery ] string version = Constants . RouteName_Latest
20- )
20+ )
2121 {
2222 if ( os == string . Empty )
2323 return BadRequest ( "os was empty." ) ;
24-
24+
2525 if ( arch == string . Empty )
2626 return BadRequest ( "arch was empty." ) ;
2727
2828 if ( rc == string . Empty )
2929 return BadRequest ( "rc was empty." ) ;
30-
30+
3131 if ( ! os . TryParseAsSupportedPlatform ( out var supportedPlatform ) )
3232 return BadRequest ( $ "Unknown platform '{ os } '") ;
33-
33+
3434 if ( ! arch . TryParseAsSupportedArchitecture ( out var supportedArch ) )
3535 return BadRequest ( $ "Unknown architecture '{ arch } '") ;
36-
36+
3737 if ( ! rc . TryParseAsReleaseChannel ( out var releaseChannel ) )
38- return BadRequest ( $ "Unknown release channel '{ rc } '; valid are '{ Constants . StableRoute } ' and '{ Constants . CanaryRoute } '") ;
39-
38+ return BadRequest (
39+ $ "Unknown release channel '{ rc } '; valid are '{ Constants . StableRoute } ' and '{ Constants . CanaryRoute } '") ;
40+
4041 var release = await HttpContext . RequestServices
4142 . GetCacheFor ( releaseChannel )
42- . GetReleaseAsync ( c =>
43- version is Constants . RouteName_Latest ? c . Latest : c [ version ]
43+ . GetReleaseAsync ( c =>
44+ version is Constants . RouteName_Latest ? c . GetLatest ( supportedPlatform , supportedArch ) : c [ version ]
4445 ) ;
45-
46+
4647 if ( release is null )
4748 return NotFound ( ) ;
48-
49+
4950 return Redirect ( release . GetUrlFor ( supportedPlatform , supportedArch ) ) ;
5051 }
51-
52+
5253 [ HttpGet ]
5354 [ HttpGet ( Constants . StableRoute ) ]
5455 [ ProducesResponseType ( StatusCodes . Status302Found ) ]
5556 [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
5657 public async Task < ActionResult > DownloadLatestStable (
57- [ FromKeyedServices ( "stableCache" ) ] VersionCache vcache ,
58+ [ FromKeyedServices ( "stableCache" ) ] VersionCache vcache ,
5859 [ FromServices ] ILogger < DownloadController > logger
5960 )
6061 {
61- if ( await vcache . GetReleaseAsync ( c => c . Latest ) is not { } latest )
62+ if ( await vcache . GetReleaseAsync ( c => c . Latest ) is not { } latest )
6263 return NotFound ( ) ;
63-
64+
6465 return RedirectOrProblem ( latest , logger , HttpContext . Request . Headers . UserAgent . ToString ( ) ) ;
6566 }
66-
67+
6768 [ HttpGet ( Constants . CanaryRoute ) ]
6869 [ ProducesResponseType ( StatusCodes . Status302Found ) ]
6970 [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
@@ -72,26 +73,29 @@ public async Task<ActionResult> DownloadLatestCanary(
7273 [ FromServices ] ILogger < DownloadController > logger
7374 )
7475 {
75- if ( await vcache . GetReleaseAsync ( c => c . Latest ) is not { } latest )
76+ if ( await vcache . GetReleaseAsync ( c => c . Latest ) is not { } latest )
7677 return NotFound ( ) ;
77-
78+
7879 return RedirectOrProblem ( latest , logger , HttpContext . Request . Headers . UserAgent . ToString ( ) ) ;
7980 }
80-
81- private ActionResult RedirectOrProblem ( VersionCacheEntry cacheEntry , ILogger < DownloadController > logger , string userAgent )
81+
82+ private ActionResult RedirectOrProblem ( VersionCacheEntry cacheEntry , ILogger < DownloadController > logger ,
83+ string userAgent )
8284 {
8385 var ( platform , arch ) = VersionCacheEntry . GetVersionTupleForUserAgent ( userAgent ) ;
84-
86+
8587 // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
8688 // I was still getting occasional errors for passing null into a Redirect, so idk
8789 if ( cacheEntry . GetUrlFor ( platform , arch ) is not { } url )
8890 {
89- logger . LogError ( new EventId ( 1 ) , "Requested download URL was null: Version: {ver}; User-Agent: '{userAgent}'" , cacheEntry . Tag , userAgent ) ;
90-
91+ logger . LogError ( new EventId ( 1 ) ,
92+ "Requested download URL was null: Version: {ver}; User-Agent: '{userAgent}'" , cacheEntry . Tag ,
93+ userAgent ) ;
94+
9195 return Problem ( statusCode : 500 ,
9296 detail : $ "The requested download's url was null. Version: { cacheEntry . Tag } ; User-Agent: '{ userAgent } '") ;
9397 }
94-
98+
9599 return Redirect ( url ) ;
96100 }
97101}
0 commit comments