From 04dce9ab116a854664496af9deaf663358c8d4fb Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 8 Oct 2020 15:00:25 +0200 Subject: [PATCH] Read mimetypes config for appprovider --- examples/ocmd/ocmd-server-1.toml | 7 ++++--- internal/grpc/services/appprovider/appprovider.go | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/ocmd/ocmd-server-1.toml b/examples/ocmd/ocmd-server-1.toml index b2a432094d0..e936a753d46 100644 --- a/examples/ocmd/ocmd-server-1.toml +++ b/examples/ocmd/ocmd-server-1.toml @@ -70,6 +70,10 @@ driver = "demo" iopsecret = "testsecret" wopiurl = "http://0.0.0.0:8880/" +[grpc.services.appprovider.mimetypes] +".zmd" = "application/compressed-markdown" +".xyz" = "application/compressed" + [grpc.services.appregistry] driver = "static" @@ -133,6 +137,3 @@ prefix = "ocs" [http.services.ocdav] [http.middlewares.cors] - -[appprovider.mimetypes] -".zmd" = "application/compressed-markdown" diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index 5ac1408dea3..2aa825f4809 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -46,9 +46,6 @@ import ( func init() { rgrpc.Register("appprovider", New) - // TODO Load [appprovider.mimetypes] configuration section - // for now, the following is hardcoded - mime.RegisterMime(".zmd", "application/compressed-markdown") } type service struct { @@ -61,16 +58,18 @@ type config struct { Demo map[string]interface{} `mapstructure:"demo"` IopSecret string `mapstructure:"iopsecret" docs:";The iopsecret used to connect to the wopiserver."` WopiURL string `mapstructure:"wopiurl" docs:";The wopiserver's URL."` + MimeTypes map[string]string `mapstructure:"mimetypes"` } // New creates a new AppProviderService func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) { - c, err := parseConfig(m) if err != nil { return nil, err } + registerMimeTypes(c.MimeTypes) + provider, err := getProvider(c) if err != nil { return nil, err @@ -92,6 +91,12 @@ func parseConfig(m map[string]interface{}) (*config, error) { return c, nil } +func registerMimeTypes(mimes map[string]string) { + for k, v := range mimes { + mime.RegisterMime(k, v) + } +} + func (s *service) Close() error { return nil }