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 custom mimetypes config to the app provider #2813

Merged
merged 1 commit into from
May 3, 2022
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
6 changes: 6 additions & 0 deletions changelog/unreleased/custom-mime-appprovider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: support custom mimetypes in the WOPI appprovider driver

Similarly to the storage provider, also the WOPI appprovider driver
now supports custom mime types. Also fixed a small typo.

https://github.com/cs3org/reva/pull/2813
1 change: 1 addition & 0 deletions examples/nextcloud-integration/revad.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ iop_secret = "hello"
wopi_url = "http://0.0.0.0:8880/"
app_name = "Collabora"
app_url = "https://your-collabora-server.org:9980"
custom_mime_types_json = "custom-mime-types-demo.json"

[grpc.services.appregistry]
driver = "static"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type config struct {
DataServerURL string `mapstructure:"data_server_url" docs:"http://localhost/data;The URL for the data server."`
ExposeDataServer bool `mapstructure:"expose_data_server" docs:"false;Whether to expose data server."` // if true the client will be able to upload/download directly to it
AvailableXS map[string]uint32 `mapstructure:"available_checksums" docs:"nil;List of available checksums."`
CustomMimeTypesJSON string `mapstructure:"custom_mimetypes_json" docs:"nil;An optional mapping file with the list of supported custom file extensions and corresponding mime types."`
CustomMimeTypesJSON string `mapstructure:"custom_mime_types_json" docs:"nil;An optional mapping file with the list of supported custom file extensions and corresponding mime types."`
}

func (c *config) init() {
Expand Down
28 changes: 28 additions & 0 deletions pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type config struct {
AppIntURL string `mapstructure:"app_int_url" docs:";The internal app URL in case of dockerized deployments. Defaults to AppURL"`
AppAPIKey string `mapstructure:"app_api_key" docs:";The API key used by the app, if applicable."`
JWTSecret string `mapstructure:"jwt_secret" docs:";The JWT secret to be used to retrieve the token TTL."`
CustomMimeTypesJSON string `mapstructure:"custom_mime_types_json" docs:"nil;An optional mapping file with the list of supported custom file extensions and corresponding mime types."`
AppDesktopOnly bool `mapstructure:"app_desktop_only" docs:"false;Specifies if the app can be opened only on desktop."`
InsecureConnections bool `mapstructure:"insecure_connections"`
}
Expand Down Expand Up @@ -111,6 +112,12 @@ func New(m map[string]interface{}) (app.Provider, error) {
return http.ErrUseLastResponse
}

// read and register custom mime types if configured
err = registerMimeTypes(c.CustomMimeTypesJSON)
if err != nil {
return nil, err
}

return &wopiProvider{
conf: c,
wopiClient: wopiClient,
Expand Down Expand Up @@ -279,6 +286,27 @@ func (p *wopiProvider) GetAppProviderInfo(ctx context.Context) (*appregistry.Pro
}, nil
}

func registerMimeTypes(mappingFile string) error {
// TODO(lopresti) this function also exists in the storage provider, to be seen if we want to factor it out, though a
// fileext <-> mimetype "service" would have to be served by the gateway for it to be accessible both by storage providers and app providers.
if mappingFile != "" {
f, err := ioutil.ReadFile(mappingFile)
if err != nil {
return fmt.Errorf("storageprovider: error reading the custom mime types file: +%v", err)
}
mimeTypes := map[string]string{}
err = json.Unmarshal(f, &mimeTypes)
if err != nil {
return fmt.Errorf("storageprovider: error unmarshalling the custom mime types file: +%v", err)
}
// register all mime types that were read
for e, m := range mimeTypes {
mime.RegisterMime(e, m)
}
}
return nil
}

func getAppURLs(c *config) (map[string]map[string]string, error) {
// Initialize WOPI URLs by discovery
httpcl := rhttp.GetHTTPClient(
Expand Down