Exemplo n.º 1
0
        public async Task <ActionResult <RegistrationIndexResponse> > RegistrationIndexAsync(string id, CancellationToken cancellationToken)
        {
            var index = await _metadata.GetRegistrationIndexOrNullAsync(id, cancellationToken);

            if (index == null)
            {
                return(NotFound());
            }

            return(index);
        }
Exemplo n.º 2
0
        private async Task <IReadOnlyList <PackageMetadata> > FindAllUpstreamMetadataOrNull(string id, CancellationToken cancellationToken)
        {
            var packageIndex = await _upstreamMetadata.GetRegistrationIndexOrNullAsync(id, cancellationToken);

            if (packageIndex == null)
            {
                return(null);
            }

            var result = new List <PackageMetadata>();

            foreach (var page in packageIndex.Pages)
            {
                cancellationToken.ThrowIfCancellationRequested();

                // If the package's registration index is too big, it will be split into registration
                // pages stored at different URLs. We will need to fetch each page's items individually.
                // We can detect this case as the registration index will have "null" items.
                var items = page.ItemsOrNull;

                if (items == null)
                {
                    var externalPage = await _upstreamMetadata.GetRegistrationPageOrNullAsync(id, page.Lower, page.Upper, cancellationToken);

                    if (externalPage == null || externalPage.ItemsOrNull == null)
                    {
                        // This should never happen...
                        _logger.LogError(
                            "Missing or invalid registration page for {PackageId}, versions {Lower} to {Upper}",
                            id,
                            page.Lower,
                            page.Upper);
                        continue;
                    }

                    items = externalPage.ItemsOrNull;
                }

                result.AddRange(items.Select(i => i.PackageMetadata));
            }

            return(result);
        }