Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add as default app while registering and skip unset mimetypes #2114

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}