working commit

This commit is contained in:
2026-03-11 19:47:40 +02:00
parent a81334aedf
commit a064d942e7
56 changed files with 564 additions and 243 deletions
+27 -18
View File
@@ -15,8 +15,10 @@ import (
"net/http"
"strconv"
"mstore/pkg/auxoci"
//"mstore/pkg/auxoci"
"mstore/pkg/descr"
ocidigest "github.com/opencontainers/go-digest"
)
type ManifestExistsParams struct {
@@ -43,35 +45,42 @@ func (oper *Operator) ManifestExists(ctx context.Context, params *ManifestExists
return res, http.StatusBadRequest, err
}
var manifest descr.Manifest
manifests := make([]descr.Manifest, 0)
var exists bool
if stringLikeSHA256Digest(params.Reference) {
digest := fmt.Sprintf("%s:%s", sha256prefix, params.Reference)
exists, manifest, err = oper.mdb.GetManifestByDigest(ctx, params.Name, digest)
var man descr.Manifest
var exist bool
digobj, err := ocidigest.Parse(params.Reference)
if err == nil {
exist, man, err = oper.mdb.GetManifestByDigest(ctx, params.Name, digobj.String())
if err != nil {
return res, http.StatusInternalServerError, err
}
if !exists {
if !exist {
return res, http.StatusNotFound, err
}
size := int64(len(man.Payload))
res.ContentLength = strconv.FormatInt(size, 10)
res.ContentType = man.ContentType
res.DockerContentDigest = man.Digest
res.Exists = exist
} else {
exists, manifests, err = oper.mdb.GetManifestsByReference(ctx, params.Name, params.Reference)
// Create index of manifests
exists, manDescrs, err := oper.mdb.GetManifestsByReference(ctx, params.Name, params.Reference)
if err != nil {
return res, http.StatusInternalServerError, err
}
if !exists {
return res, http.StatusNotFound, err
}
manifest = manifests[0] // TODO: tmp
_, indexdata, err := indexFromManigestDescrs(manDescrs)
if err != nil {
return res, http.StatusInternalServerError, err
}
digobj := ocidigest.SHA256.FromBytes(indexdata)
res.DockerContentDigest = digobj.String()
size := int64(len(indexdata))
res.ContentLength = strconv.FormatInt(size, 10)
res.ContentType = oiiMediaType
res.Exists = true
}
digest := auxoci.SHA256DigestFromString(manifest.Payload)
payloadSize := len(manifest.Payload)
res.ContentLength = strconv.FormatInt(int64(payloadSize), 10)
res.ContentType = manifest.ContentType
res.DockerContentDigest = digest.String()
res.Exists = exists
return res, http.StatusOK, err
}