private async Task IndexFromSourceAsync(string id, NuGetVersion version, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); _logger.LogInformation( "Attempting to mirror package {PackageId} {PackageVersion}...", id, version); Stream packageStream = null; try { using (var stream = await _upstreamContent.GetPackageContentStreamOrNullAsync(id, version, cancellationToken)) { if (stream == null) { _logger.LogWarning( "Failed to download package {PackageId} {PackageVersion}", id, version); return; } packageStream = await stream.AsTemporaryFileStreamAsync(); } _logger.LogInformation( "Downloaded package {PackageId} {PackageVersion}, indexing...", id, version); var result = await _indexer.IndexAsync(packageStream, cancellationToken); _logger.LogInformation( "Finished indexing package {PackageId} {PackageVersion} with result {Result}", id, version, result); } catch (Exception e) { _logger.LogError( e, "Failed to mirror package {PackageId} {PackageVersion}", id, version); packageStream?.Dispose(); } }
public async Task <IActionResult> DownloadPackageAsync(string id, string version, CancellationToken cancellationToken) { if (!NuGetVersion.TryParse(version, out var nugetVersion)) { return(NotFound()); } var packageStream = await _content.GetPackageContentStreamOrNullAsync(id, nugetVersion, cancellationToken); if (packageStream == null) { return(NotFound()); } return(File(packageStream, "application/octet-stream")); }
public async Task <IActionResult> DownloadPackageAsync(string id, string version, [FromServices] IPackageContext packageContext, CancellationToken cancellationToken) { if (!NuGetVersion.TryParse(version, out var nugetVersion)) { return(NotFound()); } using var packageStream = await _content.GetPackageContentStreamOrNullAsync(id, nugetVersion, cancellationToken); if (packageStream == null) { return(NotFound()); } packageContext.PackageId = id; packageContext.PackageVersion = version; return(new FileContentResult(packageStream.AsMemoryStream().ToArray(), "application/octet-stream") { FileDownloadName = $"{id}.nupkg" }); }