aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/packages/cargo
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-05-03 22:58:43 +0200
committerGitHub <noreply@github.com>2023-05-03 16:58:43 -0400
commit723598b803919bfc074fee05f830421a99881c3b (patch)
treef220028e75c4815f1286ea24809ef72ca9408b6b /routers/api/packages/cargo
parent48e3e38ee040c9cfec6ea2adea2da49a7f21f2c7 (diff)
downloadgitea-723598b803919bfc074fee05f830421a99881c3b.tar.gz
gitea-723598b803919bfc074fee05f830421a99881c3b.zip
Implement Cargo HTTP index (#24452)
This implements the HTTP index [RFC](https://rust-lang.github.io/rfcs/2789-sparse-index.html) for Cargo registries. Currently this is a preview feature and you need to use the nightly of `cargo`: `cargo +nightly -Z sparse-registry update` See https://github.com/rust-lang/cargo/issues/9069 for more information. --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers/api/packages/cargo')
-rw-r--r--routers/api/packages/cargo/cargo.go30
1 files changed, 30 insertions, 0 deletions
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"`