diff --git a/changelog/unreleased/zmd-mimetype.md b/changelog/unreleased/zmd-mimetype.md index 1ac29c28d8..0ab998b624 100644 --- a/changelog/unreleased/zmd-mimetype.md +++ b/changelog/unreleased/zmd-mimetype.md @@ -1,5 +1,7 @@ Enhancement: add support for custom CodiMD mimetype The new mimetype is associated with the `.zmd` file extension. +The corresponding configuration is associated with the storageprovider. https://github.com/cs3org/reva/pull/1233 +https://github.com/cs3org/reva/pull/1284 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 6bc4020f34..bf8b14fec4 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#L59) +The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L58) {{< 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#L60) +The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L59) {{< highlight toml >}} [grpc.services.appprovider] wopiurl = "" @@ -25,18 +25,10 @@ wopiurl = "" {{% /dir %}} {{% dir name="wopibridgeurl" type="string" default="" %}} -The wopibridge's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L61) +The wopibridge's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L60) {{< highlight toml >}} [grpc.services.appprovider] wopibridgeurl = "" {{< /highlight >}} {{% /dir %}} -{{% dir name="mimetypes" type="map[string]string" default=nil %}} -List of supported mime types and corresponding file extensions. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L62) -{{< highlight toml >}} -[grpc.services.appprovider] -mimetypes = nil -{{< /highlight >}} -{{% /dir %}} - diff --git a/docs/content/en/docs/config/grpc/services/storageprovider/_index.md b/docs/content/en/docs/config/grpc/services/storageprovider/_index.md index 5f1d2d126a..923de103ae 100644 --- a/docs/content/en/docs/config/grpc/services/storageprovider/_index.md +++ b/docs/content/en/docs/config/grpc/services/storageprovider/_index.md @@ -9,7 +9,7 @@ description: > # _struct: config_ {{% dir name="mount_path" type="string" default="/" %}} -The path where the file system would be mounted. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L51) +The path where the file system would be mounted. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L53) {{< highlight toml >}} [grpc.services.storageprovider] mount_path = "/" @@ -17,7 +17,7 @@ mount_path = "/" {{% /dir %}} {{% dir name="mount_id" type="string" default="-" %}} -The ID of the mounted file system. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L52) +The ID of the mounted file system. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L54) {{< highlight toml >}} [grpc.services.storageprovider] mount_id = "-" @@ -25,7 +25,7 @@ mount_id = "-" {{% /dir %}} {{% dir name="driver" type="string" default="localhome" %}} -The storage driver to be used. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L53) +The storage driver to be used. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L55) {{< highlight toml >}} [grpc.services.storageprovider] driver = "localhome" @@ -33,7 +33,7 @@ driver = "localhome" {{% /dir %}} {{% dir name="drivers" type="map[string]map[string]interface{}" default="localhome" %}} - [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L54) + [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L56) {{< highlight toml >}} [grpc.services.storageprovider.drivers.localhome] root = "/var/tmp/reva/" @@ -44,7 +44,7 @@ user_layout = "{{.Username}}" {{% /dir %}} {{% dir name="tmp_folder" type="string" default="/var/tmp" %}} -Path to temporary folder. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L55) +Path to temporary folder. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L57) {{< highlight toml >}} [grpc.services.storageprovider] tmp_folder = "/var/tmp" @@ -52,7 +52,7 @@ tmp_folder = "/var/tmp" {{% /dir %}} {{% dir name="data_server_url" type="string" default="http://localhost/data" %}} -The URL for the data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L56) +The URL for the data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L58) {{< highlight toml >}} [grpc.services.storageprovider] data_server_url = "http://localhost/data" @@ -60,7 +60,7 @@ data_server_url = "http://localhost/data" {{% /dir %}} {{% dir name="expose_data_server" type="bool" default=false %}} -Whether to expose data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L57) +Whether to expose data server. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L59) {{< highlight toml >}} [grpc.services.storageprovider] expose_data_server = false @@ -68,7 +68,7 @@ expose_data_server = false {{% /dir %}} {{% dir name="disable_tus" type="bool" default=false %}} -Whether to disable TUS uploads. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L58) +Whether to disable TUS uploads. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L60) {{< highlight toml >}} [grpc.services.storageprovider] disable_tus = false @@ -76,10 +76,18 @@ disable_tus = false {{% /dir %}} {{% dir name="available_checksums" type="map[string]uint32" default=nil %}} -List of available checksums. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L59) +List of available checksums. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L61) {{< highlight toml >}} [grpc.services.storageprovider] available_checksums = nil {{< /highlight >}} {{% /dir %}} +{{% dir name="mimetypes" type="map[string]string" default=nil %}} +List of supported mime types and corresponding file extensions. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/storageprovider/storageprovider.go#L62) +{{< highlight toml >}} +[grpc.services.storageprovider] +mimetypes = nil +{{< /highlight >}} +{{% /dir %}} + diff --git a/examples/ocmd/ocmd-server-1.toml b/examples/ocmd/ocmd-server-1.toml index 7b549c24f9..e65b8233dd 100644 --- a/examples/ocmd/ocmd-server-1.toml +++ b/examples/ocmd/ocmd-server-1.toml @@ -69,10 +69,7 @@ driver = "memory" driver = "demo" iopsecret = "testsecret" wopiurl = "http://0.0.0.0:8880/" -wopibridgeurl = "http://localhost:8000/" - -[grpc.services.appprovider.mimetypes] -".zmd" = "application/compressed-markdown" +wopibridgeurl = "http://localhost:8000/wopib" [grpc.services.appregistry] driver = "static" @@ -93,6 +90,9 @@ expose_data_server = true data_server_url = "http://localhost:19001/data" enable_home_creation = true +[grpc.services.storageprovider.mimetypes] +".zmd" = "application/compressed-markdown" + [grpc.services.storageprovider.drivers.localhome] user_layout = "{{.Username}}" diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index c6284af2e0..3755b552c4 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -35,7 +35,6 @@ 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" @@ -60,7 +59,6 @@ type config struct { IopSecret string `mapstructure:"iopsecret" docs:";The iopsecret used to connect to the wopiserver."` WopiURL string `mapstructure:"wopiurl" docs:";The wopiserver's URL."` WopiBrURL string `mapstructure:"wopibridgeurl" docs:";The wopibridge's URL."` - MimeTypes map[string]string `mapstructure:"mimetypes" docs:"nil;List of supported mime types and corresponding file extensions."` } // New creates a new AppProviderService @@ -70,8 +68,6 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) { return nil, err } - registerMimeTypes(c.MimeTypes) - provider, err := getProvider(c) if err != nil { return nil, err @@ -96,12 +92,6 @@ 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 } @@ -253,7 +243,7 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope // In case of applications served by the WOPI bridge, resolve the URL and go to the app // Note that URL matching is performed via string matching, not via IP resolution: may need to fix this - if strings.Contains(appProviderURL, s.conf.WopiBrURL) { + if len(s.conf.WopiBrURL) > 0 && strings.Contains(appProviderURL, s.conf.WopiBrURL) { httpClient := rhttp.GetHTTPClient( rhttp.Context(ctx), rhttp.Timeout(time.Duration(5*int64(time.Second))), diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 39eaa9f2e7..7457670e2f 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -33,6 +33,8 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" + "github.com/cs3org/reva/pkg/logger" + "github.com/cs3org/reva/pkg/mime" "github.com/cs3org/reva/pkg/rgrpc" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/storage" @@ -57,6 +59,7 @@ type config struct { 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 DisableTus bool `mapstructure:"disable_tus" docs:"false;Whether to disable TUS uploads."` AvailableXS map[string]uint32 `mapstructure:"available_checksums" docs:"nil;List of available checksums."` + MimeTypes map[string]string `mapstructure:"mimetypes" docs:"nil;List of supported mime types and corresponding file extensions."` } func (c *config) init() { @@ -173,6 +176,8 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) { return nil, fmt.Errorf("no available checksum, please set in config") } + registerMimeTypes(c.MimeTypes) + service := &service{ conf: c, storage: fs, @@ -186,6 +191,15 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) { return service, nil } +func registerMimeTypes(mimes map[string]string) { + tlog := logger.New().With().Int("pid", os.Getpid()).Logger() + + for k, v := range mimes { + tlog.Debug().Str("Registering mime type: ", "'"+fmt.Sprintf("%s -> %s", k, v)+"' ").Msg("") + mime.RegisterMime(k, v) + } +} + func (s *service) SetArbitraryMetadata(ctx context.Context, req *provider.SetArbitraryMetadataRequest) (*provider.SetArbitraryMetadataResponse, error) { newRef, err := s.unwrap(ctx, req.Ref) if err != nil {