Skip to content

Commit

Permalink
Read mimetypes config for appprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 8, 2020
1 parent ad1708e commit 04dce9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions examples/ocmd/ocmd-server-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -133,6 +137,3 @@ prefix = "ocs"
[http.services.ocdav]

[http.middlewares.cors]

[appprovider.mimetypes]
".zmd" = "application/compressed-markdown"
13 changes: 9 additions & 4 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 04dce9a

Please sign in to comment.