diff --git a/pkg/app/registry/static/static.go b/pkg/app/registry/static/static.go index 4dec4c1105..1e9d34fbd9 100644 --- a/pkg/app/registry/static/static.go +++ b/pkg/app/registry/static/static.go @@ -35,17 +35,17 @@ func init() { } type mimeTypeConfig struct { - Extension string `mapstructure:"extension"` - Name string `mapstructure:"name"` - Description string `mapstructure:"description"` - Icon string `mapstructure:"icon"` - DefaultApp string `mapstructure:"default_app"` + Extension string `mapstructure:"extension"` + Name string `mapstructure:"name"` + Description string `mapstructure:"description"` + Icon string `mapstructure:"icon"` + DefaultApp string `mapstructure:"default_app"` + AllowCreation bool `mapstructure:"allow_creation"` } type mimeTypeIndex struct { - mimeConf mimeTypeConfig - allowCreation bool - apps []string + mimeConf mimeTypeConfig + apps []string } type config struct { @@ -93,9 +93,6 @@ func New(m map[string]interface{}) (app.Registry, error) { } else { mimetypes[m] = &mimeTypeIndex{apps: []string{addr}} if mimeConf, ok := conf.MimeTypes[m]; ok { - // If the mime type is specified in the config, - // it is whitelisted for new file creation - mimetypes[m].allowCreation = true mimetypes[m].mimeConf = mimeConf } } @@ -153,9 +150,6 @@ func (regManager *manager) AddProvider(ctx context.Context, p *registrypb.Provid } else { regManager.mimetypesIdx[m] = &mimeTypeIndex{apps: []string{p.Address}} if mimetypeConfig, ok := regManager.config.MimeTypes[m]; ok { - // If the mime type is specified in the config, - // it is whitelisted for new file creation - regManager.mimetypesIdx[m].allowCreation = true regManager.mimetypesIdx[m].mimeConf = mimetypeConfig } } @@ -193,7 +187,7 @@ func (regManager *manager) ListSupportedMimeTypes(ctx context.Context) ([]*regis Name: mime.mimeConf.Name, Description: mime.mimeConf.Description, Icon: mime.mimeConf.Icon, - AllowCreation: mime.allowCreation, + AllowCreation: mime.mimeConf.AllowCreation, } for _, p := range mime.apps { if provider, ok := regManager.providers[p]; ok { diff --git a/pkg/app/registry/static/static_test.go b/pkg/app/registry/static/static_test.go index d69a1075df..6288dc1d29 100644 --- a/pkg/app/registry/static/static_test.go +++ b/pkg/app/registry/static/static_test.go @@ -56,44 +56,48 @@ var ( MimeTypes: []string{"text/markdown", "application/compressed-markdown"}, } - mimeTypesForCreation = []string{"application/pdf", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", + mimeTypesForCreation = []string{"application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"} testConfig = map[string]interface{}{ "mime_types": map[string]interface{}{ - "application/pdf": map[string]string{ + "application/pdf": map[string]interface{}{ "extension": "pdf", "name": "PDF", "description": "PDF document", "icon": "", }, - "application/vnd.oasis.opendocument.text": map[string]string{ - "extension": "odt", - "name": "Open Document", - "description": "OpenDocument text document", - "icon": "", - "default_app": "Collabora", + "application/vnd.oasis.opendocument.text": map[string]interface{}{ + "extension": "odt", + "name": "Open Document", + "description": "OpenDocument text document", + "icon": "", + "default_app": "Collabora", + "allow_creation": true, }, - "application/vnd.oasis.opendocument.spreadsheet": map[string]string{ - "extension": "ods", - "name": "Open Spreadsheet", - "description": "OpenDocument spreadsheet document", - "icon": "", - "default_app": "Collabora", + "application/vnd.oasis.opendocument.spreadsheet": map[string]interface{}{ + "extension": "ods", + "name": "Open Spreadsheet", + "description": "OpenDocument spreadsheet document", + "icon": "", + "default_app": "Collabora", + "allow_creation": true, }, - "application/vnd.openxmlformats-officedocument.wordprocessingml.document": map[string]string{ - "extension": "docx", - "name": "Word Document", - "description": "Microsoft Word document", - "icon": "", - "default_app": "Microsoft Office", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": map[string]interface{}{ + "extension": "docx", + "name": "Word Document", + "description": "Microsoft Word document", + "icon": "", + "default_app": "Microsoft Office", + "allow_creation": true, }, - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": map[string]string{ - "extension": "xlsx", - "name": "Excel Spreadsheet", - "description": "Microsoft Excel document", - "icon": "", - "default_app": "Microsoft Office", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": map[string]interface{}{ + "extension": "xlsx", + "name": "Excel Spreadsheet", + "description": "Microsoft Excel document", + "icon": "", + "default_app": "Microsoft Office", + "allow_creation": true, }, }, }