Skip to content

Commit

Permalink
Moved custom mime types registration to storageprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Oct 28, 2020
1 parent c74de0e commit 0008c2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions examples/ocmd/ocmd-server-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}}"

Expand Down
10 changes: 0 additions & 10 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -59,7 +58,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
Expand All @@ -69,8 +67,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
Expand All @@ -92,12 +88,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
}
Expand Down
14 changes: 14 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 0008c2d

Please sign in to comment.