diff --git a/registry/v2/registry.go b/registry/v2/registry.go index 754b9e7a..6a7795e3 100644 --- a/registry/v2/registry.go +++ b/registry/v2/registry.go @@ -551,52 +551,21 @@ func (r *registry) PullLayer(ctx echo.Context) error { } } - if layerRef.Skylink == "" { - detail := map[string]interface{}{ - "error": "skylink is empty", - } - e := fmt.Errorf("skylink is empty").Error() - errMsg := r.errorResponse(RegistryErrorCodeBlobUnknown, e, detail) - ctx.Set(types.HttpEndpointErrorKey, errMsg) - return ctx.JSONBlob(http.StatusNotFound, errMsg) - } - - resp, err := r.skynet.Download(layerRef.Skylink) - if err != nil { - detail := map[string]interface{}{ - "error": err.Error(), - } - errMsg := r.errorResponse(RegistryErrorCodeBlobUnknown, err.Error(), detail) - ctx.Set(types.HttpEndpointErrorKey, errMsg) - return ctx.JSONBlob(http.StatusNotFound, errMsg) - } - - bz, err := io.ReadAll(resp) - if err != nil { - errMsg := r.errorResponse(RegistryErrorCodeBlobUploadInvalid, err.Error(), nil) - ctx.Set(types.HttpEndpointErrorKey, errMsg) - return ctx.JSONBlob(http.StatusInternalServerError, errMsg) + size, ok := r.skynet.Metadata(layerRef.Skylink) + if ok { + url := fmt.Sprintf("https://siasky.net/%s",strings.Replace(layerRef.Skylink,"sia://","",1)) + ctx.Response().Header().Set("Content-Length", fmt.Sprintf("%d", size)) + http.Redirect(ctx.Response(), ctx.Request(), url, http.StatusTemporaryRedirect) + return nil } - _ = resp.Close() - dig := digest(bz) - if dig != clientDigest { - details := map[string]interface{}{ - "clientDigest": clientDigest, - "computedDigest": dig, - } - errMsg := r.errorResponse( - RegistryErrorCodeBlobUploadUnknown, - "client digest is different than computed digest", - details, - ) - ctx.Set(types.HttpEndpointErrorKey, errMsg) - return ctx.JSONBlob(http.StatusNotFound, errMsg) + detail := map[string]interface{}{ + "error": "skylink is empty", } - - ctx.Response().Header().Set("Content-Length", fmt.Sprintf("%d", len(bz))) - ctx.Response().Header().Set("Docker-Content-Digest", dig) - return ctx.Blob(http.StatusOK, "application/octet-stream", bz) + e := fmt.Errorf("skylink is empty").Error() + errMsg := r.errorResponse(RegistryErrorCodeBlobUnknown, e, detail) + ctx.Set(types.HttpEndpointErrorKey, errMsg) + return ctx.JSONBlob(http.StatusNotFound, errMsg) } //BlobMount to be implemented by guacamole at a later stage