Skip to content

Commit

Permalink
Add allow_creation to mime type config
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 7, 2021
1 parent 5b2370e commit c5bf6a8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
24 changes: 9 additions & 15 deletions pkg/app/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down
56 changes: 30 additions & 26 deletions pkg/app/registry/static/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down

0 comments on commit c5bf6a8

Please sign in to comment.