Skip to content

Commit

Permalink
Determine req method based on wopiserver response
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Aug 10, 2021
1 parent 07d5c97 commit 2ab1032
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 17 additions & 5 deletions pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
}
defer openRes.Body.Close()

if openRes.StatusCode != http.StatusFound {
return nil, errors.Wrap(err, "wopi: unexpected status from WOPI server: "+openRes.Status)
if openRes.StatusCode != http.StatusOK {
return nil, errtypes.InternalError("wopi: unexpected status from WOPI server: " + openRes.Status)
}

body, err := ioutil.ReadAll(openRes.Body)
Expand All @@ -192,13 +192,25 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
}

appFullURL := result["app-url"].(string)
formParams := result["form-parameters"].(map[string]string)
formParams["access_token_ttl"] = tokenTTL

// Depending on whether wopi server returned any form parameters or not,
// we decide whether the request method is POST or GET
var formParams map[string]string
method := "GET"
if form, ok := result["form-parameters"].(map[string]interface{}); ok {
if tkn, ok := form["access_token"].(string); ok {
formParams = map[string]string{
"access_token": tkn,
"access_token_ttl": tokenTTL,
}
method = "POST"
}
}

log.Info().Msg(fmt.Sprintf("wopi: returning app URL %s", appFullURL))
return &appprovider.OpenInAppURL{
AppUrl: appFullURL,
Method: "POST",
Method: method,
FormParameters: formParams,
}, nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/app/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ func (b *reg) ListSupportedMimeTypes(ctx context.Context) (map[string]*registryp

mimeTypes := make(map[string]*registrypb.AppProviderList)
for _, p := range b.providers {
t := *p
t.MimeTypes = nil
for _, m := range p.MimeTypes {
if _, ok := mimeTypes[m]; ok {
mimeTypes[m].AppProviders = append(mimeTypes[m].AppProviders, p)
mimeTypes[m].AppProviders = append(mimeTypes[m].AppProviders, &t)
} else {
mimeTypes[m] = &registrypb.AppProviderList{AppProviders: []*registrypb.ProviderInfo{p}}
mimeTypes[m] = &registrypb.AppProviderList{AppProviders: []*registrypb.ProviderInfo{&t}}
}
}
}
Expand Down

0 comments on commit 2ab1032

Please sign in to comment.