Skip to content

Commit

Permalink
Add custom mimetypes config to the app provider (#2813)
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed May 3, 2022
1 parent e62dd05 commit bd0d4ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/custom-mime-appprovider.md
@@ -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
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
2 changes: 1 addition & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
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
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

0 comments on commit bd0d4ea

Please sign in to comment.