Skip to content

Commit 3c7454f

Browse files
committed
appprovider: changed JSON marshalling to send Target as string
1 parent 8db8720 commit 3c7454f

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

docs/content/en/docs/config/http/services/appprovider/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: >
99
# _struct: Config_
1010

1111
{{% dir name="insecure" type="bool" default=false %}}
12-
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/appprovider/appprovider.go#L55)
12+
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/appprovider/appprovider.go#L56)
1313
{{< highlight toml >}}
1414
[http.services.appprovider]
1515
insecure = false

internal/http/services/appprovider/appprovider.go

+35-14
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import (
2424
"net/http"
2525
"path"
2626

27+
apppb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
2728
appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
2829
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
2930
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
30-
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
31+
storagepb "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
3132
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
3233
"github.com/cs3org/reva/internal/http/services/datagateway"
3334
"github.com/cs3org/reva/pkg/appctx"
@@ -158,8 +159,8 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
158159
return
159160
}
160161

161-
statParentContainerReq := &provider.StatRequest{
162-
Ref: &provider.Reference{
162+
statParentContainerReq := &storagepb.StatRequest{
163+
Ref: &storagepb.Reference{
163164
ResourceId: parentContainerRef,
164165
},
165166
}
@@ -174,16 +175,16 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
174175
return
175176
}
176177

177-
if parentContainer.Info.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
178+
if parentContainer.Info.Type != storagepb.ResourceType_RESOURCE_TYPE_CONTAINER {
178179
writeError(w, r, appErrorInvalidParameter, "the parent container id does not point to a container", nil)
179180
return
180181
}
181182

182-
fileRef := &provider.Reference{
183+
fileRef := &storagepb.Reference{
183184
Path: path.Join(parentContainer.Info.Path, utils.MakeRelativePath(filename)),
184185
}
185186

186-
statFileReq := &provider.StatRequest{
187+
statFileReq := &storagepb.StatRequest{
187188
Ref: fileRef,
188189
}
189190
statFileRes, err := client.Stat(ctx, statFileReq)
@@ -202,7 +203,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
202203
}
203204

204205
// Create empty file via storageprovider
205-
createReq := &provider.InitiateFileUploadRequest{
206+
createReq := &storagepb.InitiateFileUploadRequest{
206207
Ref: fileRef,
207208
Opaque: &typespb.Opaque{
208209
Map: map[string]*typespb.OpaqueEntry{
@@ -269,7 +270,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
269270
return
270271
}
271272

272-
if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE {
273+
if statRes.Info.Type != storagepb.ResourceType_RESOURCE_TYPE_FILE {
273274
writeError(w, r, appErrorInvalidParameter, "the given file id does not point to a file", nil)
274275
return
275276
}
@@ -339,7 +340,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
339340

340341
fileID := r.Form.Get("file_id")
341342

342-
var fileRef provider.Reference
343+
var fileRef storagepb.Reference
343344
if fileID == "" {
344345
path := r.Form.Get("path")
345346
if path == "" {
@@ -356,7 +357,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
356357
fileRef.ResourceId = resourceID
357358
}
358359

359-
statRes, err := client.Stat(ctx, &provider.StatRequest{Ref: &fileRef})
360+
statRes, err := client.Stat(ctx, &storagepb.StatRequest{Ref: &fileRef})
360361
if err != nil {
361362
writeError(w, r, appErrorServerError, "Internal error accessing the file, please try again later", err)
362363
return
@@ -370,7 +371,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
370371
return
371372
}
372373

373-
if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE {
374+
if statRes.Info.Type != storagepb.ResourceType_RESOURCE_TYPE_FILE {
374375
writeError(w, r, appErrorInvalidParameter, "the given file id does not point to a file", nil)
375376
return
376377
}
@@ -417,7 +418,16 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
417418
return
418419
}
419420

420-
js, err := json.Marshal(openRes.AppUrl)
421+
// recreate the structure to be able to marshal the AppUrl.Target as a string
422+
js, err := json.Marshal(
423+
map[string]interface{}{
424+
"app_url": openRes.AppUrl.AppUrl,
425+
"method": openRes.AppUrl.Method,
426+
"form_parameters": openRes.AppUrl.FormParameters,
427+
"headers": openRes.AppUrl.Headers,
428+
"target": appTargetToString(openRes.AppUrl.Target),
429+
},
430+
)
421431
if err != nil {
422432
writeError(w, r, appErrorServerError, "Internal error with JSON payload",
423433
errors.Wrap(err, "error marshalling JSON response"))
@@ -442,7 +452,7 @@ func (s *svc) handleNotify(w http.ResponseWriter, r *http.Request) {
442452
}
443453

444454
fileID := r.Form.Get("file_id")
445-
var fileRef provider.Reference
455+
var fileRef storagepb.Reference
446456
if fileID == "" {
447457
path := r.Form.Get("path")
448458
if path == "" {
@@ -488,7 +498,7 @@ func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent stri
488498
return res
489499
}
490500

491-
func resolveViewMode(res *provider.ResourceInfo, vm string) gateway.OpenInAppRequest_ViewMode {
501+
func resolveViewMode(res *storagepb.ResourceInfo, vm string) gateway.OpenInAppRequest_ViewMode {
492502
var viewMode gateway.OpenInAppRequest_ViewMode
493503
if vm != "" {
494504
viewMode = utils.GetViewMode(vm)
@@ -512,3 +522,14 @@ func resolveViewMode(res *provider.ResourceInfo, vm string) gateway.OpenInAppReq
512522
}
513523
return viewMode
514524
}
525+
526+
func appTargetToString(t apppb.Target) string {
527+
switch t {
528+
case apppb.Target_TARGET_IFRAME:
529+
return "iframe"
530+
case apppb.Target_TARGET_BLANK:
531+
return "blank"
532+
default:
533+
return "iframe"
534+
}
535+
}

0 commit comments

Comments
 (0)