working commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
)
|
||||
|
||||
// HEAD /v2/<name>/blobs/<digest> 200 404
|
||||
|
||||
func (hand *Handler) BlobExists(rctx *router.Context) {
|
||||
name, _ := rctx.GetSubpath("name")
|
||||
digest, _ := rctx.GetSubpath("digest")
|
||||
|
||||
hand.logg.Debugf("Handle BlobExists with name=[%s] digest=[%s]", name, digest)
|
||||
params := &operator.BlobExistsParams{
|
||||
Name: name,
|
||||
Digest: digest,
|
||||
}
|
||||
ctx := rctx.GetContext()
|
||||
res, code, err := hand.oper.BlobExists(ctx, params)
|
||||
if err != nil {
|
||||
hand.logg.Errorf("BlobExist error: %v", err)
|
||||
} else if res.Exists {
|
||||
rctx.SetHeader("Docker-Content-Digest", res.DockerContentDigest)
|
||||
rctx.SetHeader("Content-Length", res.ContentLength)
|
||||
}
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
|
||||
// POST /v2/<name>/blobs/uploads/ 202 404
|
||||
func (hand *Handler) PostUpload(rctx *router.Context) {
|
||||
name, _ := rctx.GetSubpath("name")
|
||||
digest := rctx.GetQuery("digest")
|
||||
mount := rctx.GetQuery("mount")
|
||||
from := rctx.GetQuery("from")
|
||||
|
||||
hand.logg.Debugf("Handle PostUpload with name=[%s] digest=[%s]", name, digest)
|
||||
params := &operator.PostUploadParams{
|
||||
Name: name,
|
||||
Digest: digest,
|
||||
Mount: mount,
|
||||
From: from,
|
||||
}
|
||||
res, code, err := hand.oper.PostUpload(rctx.Ctx, params)
|
||||
if err != nil {
|
||||
hand.logg.Errorf("PostUpload error: %v", err)
|
||||
} else {
|
||||
hand.logg.Debugf("PostUpload send location=[%s] code=%d", res.Location, code)
|
||||
rctx.SetHeader("Location", res.Location)
|
||||
rctx.SetHeader("Content-Length", res.ContentLength)
|
||||
rctx.SetHeader("Docker-Upload-UUID", res.DockerUploadUUID)
|
||||
}
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
|
||||
// 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
|
||||
func (hand *Handler) PatchUpload(rctx *router.Context) {
|
||||
|
||||
contentLength := rctx.GetHeader("Content-Length")
|
||||
contentType := rctx.GetHeader("Content-Type")
|
||||
name, _ := rctx.GetSubpath("name")
|
||||
reference, _ := rctx.GetSubpath("reference")
|
||||
reader := rctx.Request.Body
|
||||
|
||||
params := &operator.PatchUploadParams{
|
||||
ContentLength: contentLength,
|
||||
ContentType: contentType,
|
||||
Name: name,
|
||||
Reference: reference,
|
||||
Reader: reader,
|
||||
}
|
||||
ctx := rctx.GetContext()
|
||||
res, code, err := hand.oper.PatchUpload(ctx, params)
|
||||
if err != nil {
|
||||
hand.logg.Errorf("PatchUpload error: %v", err)
|
||||
}
|
||||
rctx.SetHeader("Location", res.Location)
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
Reference in New Issue
Block a user