diff options
Diffstat (limited to 'routers/api/packages')
-rw-r--r-- | routers/api/packages/api.go | 6 | ||||
-rw-r--r-- | routers/api/packages/cargo/cargo.go | 30 |
2 files changed, 36 insertions, 0 deletions
diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go index 04b0c0ab08..ee1feb1414 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -119,6 +119,12 @@ func CommonRoutes(ctx gocontext.Context) *web.Route { r.Get("/owners", cargo.ListOwners) }) }) + r.Get("/config.json", cargo.RepositoryConfig) + r.Get("/1/{package}", cargo.EnumeratePackageVersions) + r.Get("/2/{package}", cargo.EnumeratePackageVersions) + // Use dummy placeholders because these parts are not of interest + r.Get("/3/{_}/{package}", cargo.EnumeratePackageVersions) + r.Get("/{_}/{__}/{package}", cargo.EnumeratePackageVersions) }, reqPackageAccess(perm.AccessModeRead)) r.Group("/chef", func() { r.Group("/api/v1", func() { diff --git a/routers/api/packages/cargo/cargo.go b/routers/api/packages/cargo/cargo.go index 18c93d328a..b666bdde6c 100644 --- a/routers/api/packages/cargo/cargo.go +++ b/routers/api/packages/cargo/cargo.go @@ -4,6 +4,7 @@ package cargo import ( + "errors" "fmt" "net/http" "strconv" @@ -45,6 +46,35 @@ func apiError(ctx *context.Context, status int, obj interface{}) { }) } +// https://rust-lang.github.io/rfcs/2789-sparse-index.html +func RepositoryConfig(ctx *context.Context) { + ctx.JSON(http.StatusOK, cargo_service.BuildConfig(ctx.Package.Owner)) +} + +func EnumeratePackageVersions(ctx *context.Context) { + p, err := packages_model.GetPackageByName(ctx, ctx.Package.Owner.ID, packages_model.TypeCargo, ctx.Params("package")) + if err != nil { + if errors.Is(err, util.ErrNotExist) { + apiError(ctx, http.StatusNotFound, err) + } else { + apiError(ctx, http.StatusInternalServerError, err) + } + return + } + + b, err := cargo_service.BuildPackageIndex(ctx, p) + if err != nil { + apiError(ctx, http.StatusInternalServerError, err) + return + } + if b == nil { + apiError(ctx, http.StatusNotFound, nil) + return + } + + ctx.PlainTextBytes(http.StatusOK, b.Bytes()) +} + type SearchResult struct { Crates []*SearchResultCrate `json:"crates"` Meta SearchResultMeta `json:"meta"` |