diff --git a/changelog/unreleased/appprovider-url-object-fixes.md b/changelog/unreleased/appprovider-url-object-fixes.md new file mode 100644 index 0000000000..375af1cc5a --- /dev/null +++ b/changelog/unreleased/appprovider-url-object-fixes.md @@ -0,0 +1,4 @@ +Bugfix: Fixes for http appprovider endpoints + +https://github.com/cs3org/reva/pull/2024 +https://github.com/cs3org/reva/pull/1968 diff --git a/internal/grpc/services/appregistry/appregistry_test.go b/internal/grpc/services/appregistry/appregistry_test.go index 684a1c3ce6..bf9c330412 100644 --- a/internal/grpc/services/appregistry/appregistry_test.go +++ b/internal/grpc/services/appregistry/appregistry_test.go @@ -85,7 +85,7 @@ func Test_ListAppProviders(t *testing.T) { Providers: []*registrypb.ProviderInfo{ { Address: "", - MimeTypes: []string{"text/plain"}, + MimeTypes: []string{}, }, }, }, @@ -104,7 +104,7 @@ func Test_ListAppProviders(t *testing.T) { Providers: []*registrypb.ProviderInfo{ { Address: "", - MimeTypes: []string{"text/plain"}, + MimeTypes: []string{}, }, }, }, diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index 9b131e64d0..22c0a3e775 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -127,6 +127,12 @@ func (s *svc) handleList(w http.ResponseWriter, r *http.Request) { mimeTypes := listRes.MimeTypes filterAppsByUserAgent(mimeTypes, r.UserAgent()) + filterMimeTypes(mimeTypes) + + if mimeTypes == nil { + mimeTypes = make(map[string]*appregistry.AppProviderList) // ensure array empty object instead of null in json + } + js, err := json.Marshal(map[string]interface{}{"mime-types": mimeTypes}) if err != nil { ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error marshalling JSON response", err) @@ -183,6 +189,24 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { } } +func filterMimeTypes(mimeTypes map[string]*appregistry.AppProviderList) { + for m, providers := range mimeTypes { + apps := []*appregistry.ProviderInfo{} + for _, p := range providers.AppProviders { + p.Address = "" // address is internal only and not needed in the client + // apps are called by name, so if it has no name you cannot call it. Therefore we should not advertise it. + if p.Name != "" { + apps = append(apps, p) + } + } + if len(apps) > 0 { + mimeTypes[m] = &appregistry.AppProviderList{AppProviders: apps} + } else { + delete(mimeTypes, m) + } + } +} + func filterAppsByUserAgent(mimeTypes map[string]*appregistry.AppProviderList, userAgent string) { ua := ua.Parse(userAgent) if ua.Desktop { diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index f687047d98..0f731d76af 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -312,7 +312,8 @@ func (p *wopiProvider) getAccessTokenTTL(ctx context.Context) (string, error) { } if claims, ok := token.Claims.(*jwt.StandardClaims); ok && token.Valid { - return strconv.FormatInt(claims.ExpiresAt, 10), nil + // milliseconds since Jan 1, 1970 UTC as required in https://wopi.readthedocs.io/projects/wopirest/en/latest/concepts.html?highlight=access_token_ttl#term-access-token-ttl + return strconv.FormatInt(claims.ExpiresAt*1000, 10), nil } return "", errtypes.InvalidCredentials("wopi: invalid token present in ctx") diff --git a/pkg/app/registry/static/static.go b/pkg/app/registry/static/static.go index 0d975ba226..6ddb63864a 100644 --- a/pkg/app/registry/static/static.go +++ b/pkg/app/registry/static/static.go @@ -44,7 +44,7 @@ func (c *config) init() { c.Providers = map[string]*registrypb.ProviderInfo{ sharedconf.GetGatewaySVC(""): { Address: sharedconf.GetGatewaySVC(""), - MimeTypes: []string{"text/plain"}, + MimeTypes: []string{}, }, } }