@@ -94,6 +94,7 @@ public partial class PackagesController
9494 private readonly IContentObjectService _contentObjectService ;
9595 private readonly ISymbolPackageUploadService _symbolPackageUploadService ;
9696 private readonly IDiagnosticsSource _trace ;
97+ private readonly IFlatContainerService _flatContainerService ;
9798
9899 public PackagesController (
99100 IPackageService packageService ,
@@ -118,7 +119,8 @@ public PackagesController(
118119 IPackageOwnershipManagementService packageOwnershipManagementService ,
119120 IContentObjectService contentObjectService ,
120121 ISymbolPackageUploadService symbolPackageUploadService ,
121- IDiagnosticsService diagnosticsService )
122+ IDiagnosticsService diagnosticsService ,
123+ IFlatContainerService flatContainerService )
122124 {
123125 _packageService = packageService ;
124126 _uploadFileService = uploadFileService ;
@@ -143,6 +145,7 @@ public PackagesController(
143145 _contentObjectService = contentObjectService ;
144146 _symbolPackageUploadService = symbolPackageUploadService ;
145147 _trace = diagnosticsService ? . SafeGetSource ( nameof ( PackagesController ) ) ?? throw new ArgumentNullException ( nameof ( diagnosticsService ) ) ;
148+ _flatContainerService = flatContainerService ;
146149 }
147150
148151 [ HttpGet ]
@@ -663,6 +666,36 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
663666 return View ( model ) ;
664667 }
665668
669+ public virtual async Task < ActionResult > License ( string id , string version )
670+ {
671+ var package = _packageService . FindPackageByIdAndVersionStrict ( id , version ) ;
672+ if ( package == null )
673+ {
674+ return HttpNotFound ( ) ;
675+ }
676+
677+ if ( package . EmbeddedLicenseType == EmbeddedLicenseFileType . Absent )
678+ {
679+ return HttpNotFound ( ) ;
680+ }
681+
682+ if ( ! _config . AsynchronousPackageValidationEnabled )
683+ {
684+ try
685+ {
686+ var licenseFileContent = await _packageFileService . DownloadLicenseFileAsync ( package ) ;
687+ return new FileStreamResult ( licenseFileContent , "text/plain" ) ;
688+ }
689+ catch ( Exception ex )
690+ {
691+ _telemetryService . TraceException ( ex ) ;
692+ return HttpNotFound ( ) ;
693+ }
694+ }
695+
696+ return Redirect ( await _flatContainerService . GetLicenseFileFlatContainerUrlAsync ( package . Id , package . NormalizedVersion ) ) ;
697+ }
698+
666699 public virtual async Task < ActionResult > ListPackages ( PackageListSearchViewModel searchAndListModel )
667700 {
668701 var page = searchAndListModel . Page ;
0 commit comments