From aa6ef98e2a1c3d619631144afd1b4b3d0ef6ba27 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 11 Sep 2020 14:55:51 +0200 Subject: [PATCH 1/5] Added support for a custom CodiMD mimetype This is for now hardcoded, still have to parse the appropriate config section. --- examples/ocmd/ocmd-server-1.toml | 4 ++++ pkg/mime/mime.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/examples/ocmd/ocmd-server-1.toml b/examples/ocmd/ocmd-server-1.toml index 7d4fb4f56b..39b856a0cd 100644 --- a/examples/ocmd/ocmd-server-1.toml +++ b/examples/ocmd/ocmd-server-1.toml @@ -76,6 +76,7 @@ driver = "static" [grpc.services.appregistry.static.rules] "text/plain" = "localhost:19000" "text/markdown" = "localhost:19000" +"application/compressed-markdown" = "localhost:19000" "application/vnd.oasis.opendocument.text" = "localhost:19000" "application/vnd.oasis.opendocument.spreadsheet" = "localhost:19000" "application/vnd.oasis.opendocument.presentation" = "localhost:19000" @@ -132,3 +133,6 @@ prefix = "ocs" [http.services.ocdav] [http.middlewares.cors] + +[mime.mapping] +".zmd" = "application/compressed-markdown" diff --git a/pkg/mime/mime.go b/pkg/mime/mime.go index d1bd356311..99dbfa4739 100644 --- a/pkg/mime/mime.go +++ b/pkg/mime/mime.go @@ -29,6 +29,9 @@ var mimes map[string]string func init() { mimes = map[string]string{} + // TODO Load [mime.mapping] configuration section + // for now, the following is hardcoded + mimes[".zmd"] = "application/compressed-markdown" } // RegisterMime is a package level function that registers From 76144fc7693720d458ecb7971f7eda7e2cb58e4f Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 8 Oct 2020 14:10:42 +0200 Subject: [PATCH 2/5] Moved the registration of the new mime type where it "belongs" to --- internal/grpc/services/appprovider/appprovider.go | 4 ++++ pkg/mime/mime.go | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index a3bc5463bb..be034bc5ff 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -35,6 +35,7 @@ import ( "github.com/cs3org/reva/pkg/app" "github.com/cs3org/reva/pkg/app/provider/demo" "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/mime" "github.com/cs3org/reva/pkg/rgrpc" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rhttp" @@ -45,6 +46,9 @@ import ( func init() { rgrpc.Register("appprovider", New) + // TODO Load [mime.mapping] configuration section + // for now, the following is hardcoded + mime.RegisterMime(".zmd", "application/compressed-markdown") } type service struct { diff --git a/pkg/mime/mime.go b/pkg/mime/mime.go index 99dbfa4739..d1bd356311 100644 --- a/pkg/mime/mime.go +++ b/pkg/mime/mime.go @@ -29,9 +29,6 @@ var mimes map[string]string func init() { mimes = map[string]string{} - // TODO Load [mime.mapping] configuration section - // for now, the following is hardcoded - mimes[".zmd"] = "application/compressed-markdown" } // RegisterMime is a package level function that registers From de034f6162df765e29d4707911083cf4fc96bb92 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 8 Oct 2020 14:14:41 +0200 Subject: [PATCH 3/5] Renamed config section --- examples/ocmd/ocmd-server-1.toml | 2 +- internal/grpc/services/appprovider/appprovider.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ocmd/ocmd-server-1.toml b/examples/ocmd/ocmd-server-1.toml index 39b856a0cd..b2a432094d 100644 --- a/examples/ocmd/ocmd-server-1.toml +++ b/examples/ocmd/ocmd-server-1.toml @@ -134,5 +134,5 @@ prefix = "ocs" [http.middlewares.cors] -[mime.mapping] +[appprovider.mimetypes] ".zmd" = "application/compressed-markdown" diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index be034bc5ff..5ac1408dea 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -46,7 +46,7 @@ import ( func init() { rgrpc.Register("appprovider", New) - // TODO Load [mime.mapping] configuration section + // TODO Load [appprovider.mimetypes] configuration section // for now, the following is hardcoded mime.RegisterMime(".zmd", "application/compressed-markdown") } From ad1708e08ae8b5f47156bff17ec4fffbe43e222e Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 8 Oct 2020 14:22:03 +0200 Subject: [PATCH 4/5] Added changelog and updated doc --- changelog/unreleased/zmd-mimetype.md | 5 +++++ .../en/docs/config/grpc/services/appprovider/_index.md | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/zmd-mimetype.md diff --git a/changelog/unreleased/zmd-mimetype.md b/changelog/unreleased/zmd-mimetype.md new file mode 100644 index 0000000000..1ac29c28d8 --- /dev/null +++ b/changelog/unreleased/zmd-mimetype.md @@ -0,0 +1,5 @@ +Enhancement: add support for custom CodiMD mimetype + +The new mimetype is associated with the `.zmd` file extension. + +https://github.com/cs3org/reva/pull/1233 diff --git a/docs/content/en/docs/config/grpc/services/appprovider/_index.md b/docs/content/en/docs/config/grpc/services/appprovider/_index.md index 69b18917b6..52bed33ef3 100644 --- a/docs/content/en/docs/config/grpc/services/appprovider/_index.md +++ b/docs/content/en/docs/config/grpc/services/appprovider/_index.md @@ -9,7 +9,7 @@ description: > # _struct: config_ {{% dir name="iopsecret" type="string" default="" %}} -The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L58) +The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L62) {{< highlight toml >}} [grpc.services.appprovider] iopsecret = "" @@ -17,7 +17,7 @@ iopsecret = "" {{% /dir %}} {{% dir name="wopiurl" type="string" default="" %}} -The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L59) +The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L63) {{< highlight toml >}} [grpc.services.appprovider] wopiurl = "" From 9ca5ee4d76cbb673ffeb038b3d2a3cf2c089c07d Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 8 Oct 2020 15:00:25 +0200 Subject: [PATCH 5/5] Read mimetypes config for appprovider --- examples/ocmd/ocmd-server-1.toml | 6 +++--- internal/grpc/services/appprovider/appprovider.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/ocmd/ocmd-server-1.toml b/examples/ocmd/ocmd-server-1.toml index b2a432094d..b37a9b2e62 100644 --- a/examples/ocmd/ocmd-server-1.toml +++ b/examples/ocmd/ocmd-server-1.toml @@ -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" @@ -133,6 +136,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 5ac1408dea..2aa825f480 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 }