Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v3-flatcontainer as in api.nuget.com #752

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- main

resources:
- repo: self

variables:
tag: '$(Build.BuildId)'

stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: Docker@2
displayName: Build an image
inputs:
command: build
dockerfile: '$(Build.SourcesDirectory)/.devcontainer/Dockerfile'
tags: |
$(tag)
10 changes: 10 additions & 0 deletions src/BaGet.Web/BaGetEndpointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public void MapEndpoints(IEndpointRouteBuilder endpoints)
MapSearchRoutes(endpoints);
MapPackageMetadataRoutes(endpoints);
MapPackageContentRoutes(endpoints);
MapPackageVersionRoutes(endpoints);

}

public void MapServiceIndexRoutes(IEndpointRouteBuilder endpoints)
Expand Down Expand Up @@ -126,5 +128,13 @@ public void MapPackageContentRoutes(IEndpointRouteBuilder endpoints)
pattern: "v3/package/{id}/{version}/icon",
defaults: new { controller = "PackageContent", action = "DownloadIcon" });
}

public void MapPackageVersionRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.PackageVersionsRouteName,
pattern: "v3-flatcontainer/{packageId}/index.json",
defaults: new { controller = "VersionsController", action = "GetVersionsForPackage" });
}
}
}
34 changes: 34 additions & 0 deletions src/BaGet.Web/Controllers/VersionsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using BaGet.Core;
using BaGet.Web.Dtos;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using System.Linq;

namespace BaGet.Web.Controllers
{
[Route("v3-flatcontainer/{packageId}/index.json")]
[ApiController]
public class VersionsController : ControllerBase
{
private readonly IPackageDatabase _packageDatabase;
public VersionsController(IPackageDatabase packageDatabase)
{
_packageDatabase = packageDatabase;
}

[HttpGet]
public async Task<ActionResult<IEnumerable<string>>> GetVersionsForPackage(string packageId)
{
Console.WriteLine($"--> Getting versions for package {packageId} from Automaise nuget");
var exists = await _packageDatabase.ExistsAsync(packageId, new System.Threading.CancellationToken());
if (!exists)
return NotFound();
var retVersions = await _packageDatabase.FindAsync(packageId, true, new System.Threading.CancellationToken());
var versionDto = new VersionDto();
versionDto.versions = retVersions.Select(x => x.Version.ToString()).ToList();
return Ok(versionDto);
}
}
}
9 changes: 9 additions & 0 deletions src/BaGet.Web/Dtos/VersionsDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace BaGet.Web.Dtos
{
public class VersionDto
{
public List<string> versions { get; set; } = new List<string>();
}
}