Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/processing-endpoint-embedded-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add processing endpoint for an embedded share

- For now this only changes the state to accepted (or pending if you want to "unprocess" the share)
- Eventually we want the downloaded content to arrive in the target folder, the target is just logged for now.

https://github.com/cs3org/reva/pull/5489
42 changes: 42 additions & 0 deletions internal/http/services/sciencemesh/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cs3org/reva/v3/pkg/trace"
"google.golang.org/grpc/codes"
rpcstatus "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/fieldmaskpb"

ocmconversions "github.com/cs3org/reva/v3/pkg/ocm/conversions"
"github.com/cs3org/reva/v3/pkg/rgrpc/todo/pool"
Expand All @@ -54,6 +55,47 @@ func (h *embeddedHandler) init(c *config) error {
return nil
}

func (h *embeddedHandler) ProcessEmbeddedShare(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := appctx.GetLogger(ctx)
queryParams := r.URL.Query()

dest_path := queryParams.Get("destination")
share_id := queryParams.Get("share_id")
process := queryParams.Get("process")

// For now we just log the destination path, but we don't use it yet.
log.Debug().Str("share_id", share_id).Str("dest_path", dest_path).Msg("processing embedded share")

req := ocm.UpdateReceivedOCMShareRequest{
Share: &ocm.ReceivedShare{
Id: &ocm.ShareId{
OpaqueId: share_id,
},
},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state"}},
}

// Accept the embedded share or set it back to pending
// depending on the "process" query parameter
switch process {
case "true":
req.Share.State = ocm.ShareState_SHARE_STATE_ACCEPTED
case "false":
req.Share.State = ocm.ShareState_SHARE_STATE_PENDING
}

_, err := h.gatewayClient.UpdateReceivedOCMShare(ctx, &req)

if err != nil {
log.Error().Err(err).Msg("error accepting embedded share")
reqres.WriteError(w, r, reqres.APIErrorServerError, "error accepting embedded share", err)
return
}

w.WriteHeader(http.StatusOK)
}

// ListEmbeddedShares lists all embedded ocm shares for the current user.
func (h *embeddedHandler) ListEmbeddedShares(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand Down
1 change: 1 addition & 0 deletions internal/http/services/sciencemesh/sciencemesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (s *svc) routerInit() error {
s.router.Get("/federations", wayfHandler.GetFederations)
s.router.Post("/discover", wayfHandler.DiscoverProvider)
s.router.Get("/embedded-shares", embeddedHandler.ListEmbeddedShares)
s.router.Post("/process-embedded-share", embeddedHandler.ProcessEmbeddedShare)
return nil
}

Expand Down