Skip to content

Commit

Permalink
add as default app while registering and skip unset mimetypes (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek authored Sep 28, 2021
1 parent 48d4872 commit 92a7795
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/app-registry-defaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Add as default app while registering and skip unset mimetypes

We fixed that app providers will be set as default app while registering if configured.
Also we changed the behaviour that listing supported mimetypes only displays allowed / configured mimetypes.

https://github.com/cs3org/reva/pull/2114
https://github.com/cs3org/reva/pull/2095
20 changes: 13 additions & 7 deletions pkg/app/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ func (b *reg) AddProvider(ctx context.Context, p *registrypb.ProviderInfo) error
} else {
b.mimetypes[m] = &mimeTypeIndex{apps: []string{p.Address}}
}
// set as default app if configured
if mimetypeConfig, ok := b.config.MimeTypes[m]; ok {
if mimetypeConfig.DefaultApp == p.Address || mimetypeConfig.DefaultApp == p.Name {
b.mimetypes[m].defaultApp = p.Address
}
}
}
return nil
}
Expand All @@ -175,13 +181,13 @@ func (b *reg) ListSupportedMimeTypes(ctx context.Context) ([]*registrypb.MimeTyp
t := *p
t.MimeTypes = nil
for _, m := range p.MimeTypes {
mime, ok := b.config.MimeTypes[m]
if !ok {
continue // skip mimetype if not on allow list
}
if _, ok := mtmap[m]; ok {
mtmap[m].AppProviders = append(mtmap[m].AppProviders, &t)
} else {
mime, ok := b.config.MimeTypes[m]
if !ok {
return nil, errtypes.NotFound(fmt.Sprintf("mimetype %s not found in the configuration", m))
}
mtmap[m] = &registrypb.MimeTypeInfo{
MimeType: m,
AppProviders: []*registrypb.ProviderInfo{&t},
Expand Down Expand Up @@ -225,12 +231,12 @@ func (b *reg) GetDefaultProviderForMimeType(ctx context.Context, mimeType string
b.RLock()
defer b.RUnlock()

_, ok := b.mimetypes[mimeType]
m, ok := b.mimetypes[mimeType]
if ok {
p, ok := b.providers[b.mimetypes[mimeType].defaultApp]
if ok {
if p, ok := b.providers[m.defaultApp]; ok {
return p, nil
}
}

return nil, errtypes.NotFound("default application provider not set for mime type " + mimeType)
}

0 comments on commit 92a7795

Please sign in to comment.