コード例 #1
0
        public async Task <Stream> GetPackageManifestStreamOrNullAsync(string id, NuGetVersion version, CancellationToken cancellationToken = default)
        {
            if (!await _packages.ExistsAsync(id, version, cancellationToken))
            {
                return(null);
            }

            return(await _storage.GetNuspecStreamAsync(id, version, cancellationToken));
        }
コード例 #2
0
        public async Task <Stream> GetPackageManifestStreamOrNullAsync(string id, NuGetVersion version, CancellationToken cancellationToken = default)
        {
            // Allow read-through caching if it is configured.
            await _mirror.MirrorAsync(id, version, cancellationToken);

            if (!await _packages.ExistsAsync(id, version, cancellationToken))
            {
                return(null);
            }

            return(await _storage.GetNuspecStreamAsync(id, version, cancellationToken));
        }
コード例 #3
0
        public async Task <IActionResult> DownloadNuspec(string id, string version)
        {
            if (!NuGetVersion.TryParse(version, out var nugetVersion))
            {
                return(NotFound());
            }

            if (!await _packages.ExistsAsync(id, nugetVersion))
            {
                return(NotFound());
            }

            var identity = new PackageIdentity(id, nugetVersion);

            return(File(await _storage.GetNuspecStreamAsync(identity), "text/xml"));
        }
コード例 #4
0
ファイル: PackageController.cs プロジェクト: nimrodolev/BaGet
        public async Task <IActionResult> DownloadNuspec(string id, string version, CancellationToken cancellationToken)
        {
            if (!NuGetVersion.TryParse(version, out var nugetVersion))
            {
                return(NotFound());
            }

            // Allow read-through caching if it is configured.
            await _mirror.MirrorAsync(id, nugetVersion, cancellationToken);

            if (!await _packages.ExistsAsync(id, nugetVersion))
            {
                return(NotFound());
            }

            var nuspecStream = await _storage.GetNuspecStreamAsync(id, nugetVersion, cancellationToken);

            return(File(nuspecStream, "text/xml"));
        }
コード例 #5
0
        public PackageModule(IPackageService packageService, IPackageStorageService storage)
            : base("v3/package")
        {
            _packages = packageService ?? throw new ArgumentNullException(nameof(packageService));
            _storage  = storage ?? throw new ArgumentNullException(nameof(storage));

            this.Get("/{id}/index.json", async(req, res, routeData) => {
                string id    = routeData.As <string>("id");
                var packages = await _packages.FindAsync(id);

                if (!packages.Any())
                {
                    res.StatusCode = 404;
                    return;
                }

                await res.AsJson(new
                {
                    Versions = packages.Select(p => p.VersionString).ToList()
                });
            });

            this.Get("/{id}/{version}/{idVersion}.nupkg", async(req, res, routeData) => {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                var identity = new PackageIdentity(id, nugetVersion);
                if (!await _packages.IncrementDownloadCountAsync(identity))
                {
                    res.StatusCode = 404;
                    return;
                }


                var packageStream = await _storage.GetPackageStreamAsync(identity);

                await res.FromStream(packageStream, "application/octet-stream");
            });

            this.Get("/{id}/{version}/{id2}.nuspec", async(req, res, routeData) => {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                var identity = new PackageIdentity(id, nugetVersion);

                if (!await _packages.ExistsAsync(identity))
                {
                    res.StatusCode = 404;
                    return;
                }

                await res.FromStream(await _storage.GetNuspecStreamAsync(identity), "text/xml");
            });

            this.Get("/{id}/{version}/readme", async(req, res, routeData) => {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                var identity = new PackageIdentity(id, nugetVersion);

                if (!await _packages.ExistsAsync(identity))
                {
                    res.StatusCode = 404;
                    return;
                }

                await res.FromStream(await _storage.GetReadmeStreamAsync(identity), "text/markdown");
            });
        }