go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
43.32k stars 5.33k forks source link

API for direct cargo's crates upload #27105

Open podsvirov opened 10 months ago

podsvirov commented 10 months ago

Feature Description

As described in documentation, if I have *.deb package - I can upload it via API:

PUT https://gitea.example.com/api/packages/{owner}/debian/pool/{distribution}/{component}/upload

I want similar api for cargo packages (*.crate):

PUT https://gitea.example.com/api/packages/{owner}/cargo/upload

Screenshots

No response

KN4CK3R commented 10 months ago

The endpoint is /cargo/api/v1/crates/new.

podsvirov commented 10 months ago

@KN4CK3R can you write example of usage like for debian?

curl --user your_username:your_password_or_token \
     --upload-file path/to/file.deb \
     https://gitea.example.com/api/packages/testuser/debian/pool/bionic/main/upload
KN4CK3R commented 10 months ago

This endpoint intended to be called by cargo publish but you can just send a PUT request with curl if you want to do that.

podsvirov commented 10 months ago

I'm trying type:

curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate \
    https://gitea.example.com{xxx}/cargo/api/v1/crates/new

with diffirent {xxx} path variants (for example: empty, /{user}, /{organization}...) but allways get:

Not found.

UPDATE: Right path in https://gitea.example.com/{owner}/_cargo-index/config.json.

UPDATE2: Now I'm learning Web API from The Cargo Book.

KN4CK3R commented 10 months ago

curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate https://gitea.example.com/api/packages/{user}/cargo/api/v1/crates/new

podsvirov commented 9 months ago

curl --user {user}:{password or token} --upload-file mypackage-0.1.0.crate https://gitea.example.com/api/packages/{user}/cargo/api/v1/crates/new

Unfortunately It's not work, because:

The body of the data sent by Cargo is:

  • 32-bit unsigned little-endian integer of the length of JSON data.
  • Metadata of the package as a JSON object.
  • 32-bit unsigned little-endian integer of the length of the .crate file.
  • The .crate file.