working commit

This commit is contained in:
2026-02-04 18:17:36 +02:00
parent 219a4cb890
commit 55e8abcdd3
6 changed files with 287 additions and 25 deletions
+44 -3
View File
@@ -3,10 +3,17 @@ package handler
import (
"mstore/app/operator"
"mstore/app/router"
"sigs.k8s.io/yaml"
)
// HEAD /v2/<name>/blobs/<digest> 200 404
func (hand *Handler) DumpHeaders(message string, rctx *router.Context) {
headers := rctx.GetHeaders()
yamlData, _ := yaml.Marshal(headers)
hand.logg.Debugf("%s:\n%s\n", message, string(yamlData))
}
// 1 HEAD /v2/<name>/blobs/<digest> 200 404
func (hand *Handler) BlobExists(rctx *router.Context) {
name, _ := rctx.GetSubpath("name")
digest, _ := rctx.GetSubpath("digest")
@@ -27,7 +34,7 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
rctx.SetStatus(code)
}
// POST /v2/<name>/blobs/uploads/ 202 404
// 2 POST /v2/<name>/blobs/uploads/ 202 404
func (hand *Handler) PostUpload(rctx *router.Context) {
name, _ := rctx.GetSubpath("name")
digest := rctx.GetQuery("digest")
@@ -56,9 +63,11 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
// POST /v2/<name>/blobs/uploads/?digest=<digest> 201/202 404/400
// POST /v2/<name>/blobs/uploads/?mount=<digest>&from=<other_name> 201 404
// PATCH /v2/<name>/blobs/uploads/<reference> 202 404/416
// 3 PATCH /v2/<name>/blobs/uploads/<reference> 202 404/416
func (hand *Handler) PatchUpload(rctx *router.Context) {
hand.DumpHeaders("PatchUpload headers", rctx)
contentLength := rctx.GetHeader("Content-Length")
contentType := rctx.GetHeader("Content-Type")
name, _ := rctx.GetSubpath("name")
@@ -80,3 +89,35 @@ func (hand *Handler) PatchUpload(rctx *router.Context) {
rctx.SetHeader("Location", res.Location)
rctx.SetStatus(code)
}
// 4 PUT /v2/<name>/blobs/uploads/<reference>?digest=<digest> 202 404/416
//
// PUT /v2/<name>/uploads/<reference>?digest=<digest> 202 404/416
func (hand *Handler) PutUpload(rctx *router.Context) {
hand.DumpHeaders("PutUpload headers", rctx)
contentType := rctx.GetHeader("Content-Type")
contentLength := rctx.GetHeader("Content-Length")
contentRange := rctx.GetHeader("Content-Range")
name, _ := rctx.GetSubpath("name")
reference, _ := rctx.GetSubpath("reference")
digest := rctx.GetQuery("digest")
params := &operator.PutUploadParams{
ContentLength: contentLength,
ContentType: contentType,
ContentRange: contentRange,
Name: name,
Reference: reference,
Digest: digest,
}
res, code, err := hand.oper.PutUpload(rctx.Ctx, params)
if err != nil {
hand.logg.Errorf("PutUpload error: %v", err)
}
rctx.SetHeader("Location", res.Location)
rctx.SetStatus(code)
}