diff --git a/cmd/reva/open-file-in-app-provider.go b/cmd/reva/open-file-in-app-provider.go index 9e5c8c1bd3..d3f280d969 100644 --- a/cmd/reva/open-file-in-app-provider.go +++ b/cmd/reva/open-file-in-app-provider.go @@ -31,9 +31,9 @@ func openFileInAppProviderCommand() *command { cmd := newCommand("open-file-in-app-provider") cmd.Description = func() string { return "Open a file in an external app provider" } cmd.Usage = func() string { - return "Usage: open-file-in-app-provider [-flags] " + return "Usage: open-file-in-app-provider [-flags] [-viewmode view|read|write] " } - viewMode := cmd.String("viewMode", "view", "the view permissions, defaults to view") + viewMode := cmd.String("viewmode", "view", "the view permissions, defaults to view") cmd.Action = func() error { ctx := getAuthContext() @@ -43,7 +43,7 @@ func openFileInAppProviderCommand() *command { } path := cmd.Args()[0] - viewMode := getViewMode(*viewMode) + vm := getViewMode(*viewMode) client, err := getClient() if err != nil { @@ -54,7 +54,7 @@ func openFileInAppProviderCommand() *command { Spec: &provider.Reference_Path{Path: path}, } - openRequest := &gateway.OpenFileInAppProviderRequest{Ref: ref, ViewMode: viewMode} + openRequest := &gateway.OpenFileInAppProviderRequest{Ref: ref, ViewMode: vm} openRes, err := client.OpenFileInAppProvider(ctx, openRequest) if err != nil { diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index 6f1ce001bc..26d7f155c9 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -128,7 +128,6 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope } appsRes, err := httpClient.Do(appsReq) if err != nil { - log.Error().Err(err).Msg("error performing http request") res := &providerpb.OpenFileInAppProviderResponse{ Status: status.NewInternal(ctx, err, "error performing http request"), } @@ -136,7 +135,6 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope } defer appsRes.Body.Close() if appsRes.StatusCode != http.StatusOK { - log.Error().Err(err).Msg("error performing http request") res := &providerpb.OpenFileInAppProviderResponse{ Status: status.NewInternal(ctx, err, "error performing http request, status code: "+strconv.Itoa(appsRes.StatusCode)), } @@ -195,6 +193,7 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope openResBody := buf.String() + // TODO this could be done once every ~week, no need to do it at every request appsBodyMap := make(map[string]interface{}) err2 := json.Unmarshal(appsBody, &appsBodyMap) if err2 != nil { @@ -207,30 +206,27 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope viewOptionsMap, ok := viewOptions.(map[string]interface{}) if !ok { - log.Error().Msg("error typecasting to map") res := &providerpb.OpenFileInAppProviderResponse{ - Status: status.NewInternal(ctx, nil, "error typecasting to map"), + Status: status.NewInvalid(ctx, "Incorrect parsing of the App URLs map from the WOPI server"), } return res, nil } var viewmode string - if req.ViewMode == providerpb.OpenFileInAppProviderRequest_VIEW_MODE_READ_WRITE { viewmode = "edit" } else { viewmode = "view" } - providerURL := fmt.Sprintf("%v", viewOptionsMap[viewmode]) - - if strings.Contains(providerURL, "?") { - providerURL += "&" + appProviderURL := fmt.Sprintf("%v", viewOptionsMap[viewmode]) + if strings.Contains(appProviderURL, "?") { + appProviderURL += "&" } else { - providerURL += "?" + appProviderURL += "?" } - - appProviderURL := fmt.Sprintf("%sWOPISrc=%s\n", providerURL, openResBody) + appProviderURL = fmt.Sprintf("%sWOPISrc=%s", appProviderURL, openResBody) + log.Info().Msg(fmt.Sprintf("Returning app provider URL %s", appProviderURL)) return &providerpb.OpenFileInAppProviderResponse{ Status: status.NewOK(ctx), diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index d8e73cf916..aa4c0933a1 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -20,6 +20,7 @@ package gateway import ( "context" + "fmt" providerpb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" registry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1" @@ -27,6 +28,7 @@ import ( rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" @@ -96,6 +98,10 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn } // build the appProvider specific request with the required extra info that has been obtained + + log := appctx.GetLogger(ctx) + log.Debug().Msg(fmt.Sprintf("request: %s", req)) + appProviderReq := &providerpb.OpenFileInAppProviderRequest{ ResourceInfo: fileInfo, ViewMode: providerpb.OpenFileInAppProviderRequest_ViewMode(req.ViewMode),