Skip to content

Commit

Permalink
Merge pull request #14 from ishank011/mime
Browse files Browse the repository at this point in the history
Read mimetypes config for appprovider
  • Loading branch information
glpatcern authored Oct 8, 2020
2 parents ad1708e + 9ca5ee4 commit e2d8994
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/ocmd/ocmd-server-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ driver = "demo"
iopsecret = "testsecret"
wopiurl = "http://0.0.0.0:8880/"

[grpc.services.appprovider.mimetypes]
".zmd" = "application/compressed-markdown"

[grpc.services.appregistry]
driver = "static"

Expand Down Expand Up @@ -133,6 +136,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 e2d8994

Please sign in to comment.