mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-17 23:42:52 +00:00
cleanup package route
This commit is contained in:
parent
e801d53e61
commit
ba12aed572
5 changed files with 42 additions and 77 deletions
|
@ -153,66 +153,10 @@ func CommonRoutes() *web.Route {
|
|||
})
|
||||
}, reqPackageAccess(perm.AccessModeRead))
|
||||
r.Group("/arch", func() {
|
||||
r.Group("/repository.key", func() {
|
||||
r.Head("", arch.GetRepositoryKey)
|
||||
r.Get("", arch.GetRepositoryKey)
|
||||
})
|
||||
|
||||
r.Methods("HEAD,GET,PUT,DELETE", "*", func(ctx *context.Context) {
|
||||
pathGroups := strings.Split(strings.Trim(ctx.Params("*"), "/"), "/")
|
||||
groupLen := len(pathGroups)
|
||||
isGetHead := ctx.Req.Method == "HEAD" || ctx.Req.Method == "GET"
|
||||
isPut := ctx.Req.Method == "PUT"
|
||||
isDelete := ctx.Req.Method == "DELETE"
|
||||
if isGetHead {
|
||||
if groupLen < 2 {
|
||||
ctx.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if groupLen == 2 {
|
||||
ctx.SetParams("group", "")
|
||||
ctx.SetParams("arch", pathGroups[0])
|
||||
ctx.SetParams("file", pathGroups[1])
|
||||
} else {
|
||||
ctx.SetParams("group", strings.Join(pathGroups[:groupLen-2], "/"))
|
||||
ctx.SetParams("arch", pathGroups[groupLen-2])
|
||||
ctx.SetParams("file", pathGroups[groupLen-1])
|
||||
}
|
||||
arch.GetPackageOrDB(ctx)
|
||||
return
|
||||
} else if isPut {
|
||||
ctx.SetParams("group", strings.Join(pathGroups, "/"))
|
||||
reqPackageAccess(perm.AccessModeWrite)(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
arch.PushPackage(ctx)
|
||||
return
|
||||
} else if isDelete {
|
||||
if groupLen < 3 {
|
||||
ctx.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if groupLen == 3 {
|
||||
ctx.SetParams("group", "")
|
||||
ctx.SetParams("package", pathGroups[0])
|
||||
ctx.SetParams("version", pathGroups[1])
|
||||
ctx.SetParams("arch", pathGroups[2])
|
||||
} else {
|
||||
ctx.SetParams("group", strings.Join(pathGroups[:groupLen-3], "/"))
|
||||
ctx.SetParams("package", pathGroups[groupLen-3])
|
||||
ctx.SetParams("version", pathGroups[groupLen-2])
|
||||
ctx.SetParams("arch", pathGroups[groupLen-1])
|
||||
}
|
||||
reqPackageAccess(perm.AccessModeWrite)(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
arch.RemovePackage(ctx)
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNotFound)
|
||||
})
|
||||
r.Methods("HEAD,GET", "/repository.key", arch.GetRepositoryKey)
|
||||
r.Methods("HEAD,GET", "*", arch.GetPackageOrDB)
|
||||
r.Methods("PUT", "*", reqPackageAccess(perm.AccessModeWrite), arch.PushPackage)
|
||||
r.Methods("DELETE", "*", reqPackageAccess(perm.AccessModeWrite), arch.RemovePackage)
|
||||
}, reqPackageAccess(perm.AccessModeRead))
|
||||
r.Group("/cargo", func() {
|
||||
r.Group("/api/v1/crates", func() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue