Add Arch package registry (#32692)

Close #25037
Close #31037

This PR adds a Arch package registry usable with pacman.

![grafik](https://github.com/user-attachments/assets/81cdb0c2-02f9-4733-bee2-e48af6b45224)

Rewrite of #25396 and #31037. You can follow [this
tutorial](https://wiki.archlinux.org/title/Creating_packages) to build a
package for testing.

Docs PR: https://gitea.com/gitea/docs/pulls/111

Co-authored-by: [d1nch8g@ion.lc](mailto:d1nch8g@ion.lc)
Co-authored-by: @ExplodingDragon

---------

Co-authored-by: dancheg97 <dancheg97@fmnx.su>
Co-authored-by: dragon <ExplodingFKL@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
KN4CK3R 2024-12-05 00:09:07 +01:00 committed by GitHub
parent 5ab7aa700f
commit 0c3c041c88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 1687 additions and 91 deletions

View file

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/packages/alpine"
"code.gitea.io/gitea/routers/api/packages/arch"
"code.gitea.io/gitea/routers/api/packages/cargo"
"code.gitea.io/gitea/routers/api/packages/chef"
"code.gitea.io/gitea/routers/api/packages/composer"
@ -135,6 +136,49 @@ func CommonRoutes() *web.Router {
})
})
}, reqPackageAccess(perm.AccessModeRead))
r.Group("/arch", func() {
r.Methods("HEAD,GET", "/repository.key", arch.GetRepositoryKey)
r.Methods("HEAD,GET,PUT,DELETE", "*", func(ctx *context.Context) {
path := strings.Trim(ctx.PathParam("*"), "/")
if ctx.Req.Method == "PUT" {
reqPackageAccess(perm.AccessModeWrite)(ctx)
if ctx.Written() {
return
}
ctx.SetPathParam("repository", path)
arch.UploadPackageFile(ctx)
return
}
pathFields := strings.Split(path, "/")
pathFieldsLen := len(pathFields)
if (ctx.Req.Method == "HEAD" || ctx.Req.Method == "GET") && pathFieldsLen >= 2 {
ctx.SetPathParam("repository", strings.Join(pathFields[:pathFieldsLen-2], "/"))
ctx.SetPathParam("architecture", pathFields[pathFieldsLen-2])
ctx.SetPathParam("filename", pathFields[pathFieldsLen-1])
arch.GetPackageOrRepositoryFile(ctx)
return
}
if ctx.Req.Method == "DELETE" && pathFieldsLen >= 3 {
reqPackageAccess(perm.AccessModeWrite)(ctx)
if ctx.Written() {
return
}
ctx.SetPathParam("repository", strings.Join(pathFields[:pathFieldsLen-3], "/"))
ctx.SetPathParam("name", pathFields[pathFieldsLen-3])
ctx.SetPathParam("version", pathFields[pathFieldsLen-2])
ctx.SetPathParam("architecture", pathFields[pathFieldsLen-1])
arch.DeletePackageVersion(ctx)
return
}
ctx.Status(http.StatusNotFound)
})
}, reqPackageAccess(perm.AccessModeRead))
r.Group("/cargo", func() {
r.Group("/api/v1/crates", func() {
r.Get("", cargo.SearchPackages)