Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allow_creation parameter to mime type config #2591

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/mime-type-allow-creation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add allow_creation parameter to mime type config

https://github.com/owncloud/ocis/pull/2591
30 changes: 20 additions & 10 deletions storage/config/mimetypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,79 @@
"name": "PDF",
"description": "PDF document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": false
},
"application/vnd.oasis.opendocument.text": {
"extension": "odt",
"name": "OpenDocument",
"description": "OpenDocument text document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/vnd.oasis.opendocument.spreadsheet": {
"extension": "ods",
"name": "OpenSpreadsheet",
"description": "OpenDocument spreadsheet document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/vnd.oasis.opendocument.presentation": {
"extension": "odp",
"name": "OpenPresentation",
"description": "OpenDocument presentation document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
"extension": "docx",
"name": "Microsoft Word",
"description": "Microsoft Word document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
"extension": "xlsx",
"name": "Microsoft Excel",
"description": "Microsoft Excel document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
"extension": "pptx",
"name": "Microsoft PowerPoint",
"description": "Microsoft PowerPoint document",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/vnd.jupyter": {
"extension": "ipynb",
"name": "Jupyter Notebook",
"description": "Jupyter Notebook",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"text/markdown": {
"extension": "md",
"name": "Markdown file",
"description": "Markdown file",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": true
},
"application/compressed-markdown": {
"extension": "zmd",
"name": "Compressed markdown file",
"description": "Compressed markdown file",
"icon": "",
"default_app": ""
"default_app": "",
"allow_creation": false
}
}
69 changes: 37 additions & 32 deletions storage/pkg/command/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,18 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac
}
}

func mimetypes(cfg *config.Config, logger log.Logger) map[string]map[string]string {
func mimetypes(cfg *config.Config, logger log.Logger) map[string]map[string]interface{} {

type mimeTypeConfig struct {
Extension string `json:"extension" mapstructure:"extension"`
Name string `json:"name" mapstructure:"name"`
Description string `json:"description" mapstructure:"description"`
Icon string `json:"icon" mapstructure:"icon"`
DefaultApp string `json:"default_app" mapstructure:"default_app"`
Extension string `json:"extension" mapstructure:"extension"`
Name string `json:"name" mapstructure:"name"`
Description string `json:"description" mapstructure:"description"`
Icon string `json:"icon" mapstructure:"icon"`
DefaultApp string `json:"default_app" mapstructure:"default_app"`
AllowCreation bool `json:"allow_creation" mapstructure:"allow_creation"`
}
type mimetypesConfig map[string]mimeTypeConfig

var mimetypes mimetypesConfig
var mimetypes map[string]mimeTypeConfig
var m map[string]map[string]interface{}

// load default app mimetypes from a json file
if cfg.Reva.AppRegistry.MimetypesJSON != "" {
Expand All @@ -254,7 +254,6 @@ func mimetypes(cfg *config.Config, logger log.Logger) map[string]map[string]stri
logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules")
return nil
}
var m map[string]map[string]string
if err := mapstructure.Decode(mimetypes, &m); err != nil {
logger.Error().Err(err).Msg("Failed to decode defaultapp registry mimetypes to mapstructure")
return nil
Expand All @@ -271,44 +270,51 @@ func mimetypes(cfg *config.Config, logger log.Logger) map[string]map[string]stri
Description: "PDF document",
},
"application/vnd.oasis.opendocument.text": {
Extension: "odt",
Name: "OpenDocument",
Description: "OpenDocument text document",
Extension: "odt",
Name: "OpenDocument",
Description: "OpenDocument text document",
AllowCreation: true,
},
"application/vnd.oasis.opendocument.spreadsheet": {
Extension: "ods",
Name: "OpenSpreadsheet",
Description: "OpenDocument spreadsheet document",
Extension: "ods",
Name: "OpenSpreadsheet",
Description: "OpenDocument spreadsheet document",
AllowCreation: true,
},
"application/vnd.oasis.opendocument.presentation": {
Extension: "odp",
Name: "OpenPresentation",
Description: "OpenDocument presentation document",
Extension: "odp",
Name: "OpenPresentation",
Description: "OpenDocument presentation document",
AllowCreation: true,
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
Extension: "docx",
Name: "Microsoft Word",
Description: "Microsoft Word document",
Extension: "docx",
Name: "Microsoft Word",
Description: "Microsoft Word document",
AllowCreation: true,
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
Extension: "xlsx",
Name: "Microsoft Excel",
Description: "Microsoft Excel document",
Extension: "xlsx",
Name: "Microsoft Excel",
Description: "Microsoft Excel document",
AllowCreation: true,
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
Extension: "pptx",
Name: "Microsoft PowerPoint",
Description: "Microsoft PowerPoint document",
Extension: "pptx",
Name: "Microsoft PowerPoint",
Description: "Microsoft PowerPoint document",
AllowCreation: true,
},
"application/vnd.jupyter": {
Extension: "ipynb",
Name: "Jupyter Notebook",
Description: "Jupyter Notebook",
},
"text/markdown": {
Extension: "md",
Name: "Markdown file",
Description: "Markdown file",
Extension: "md",
Name: "Markdown file",
Description: "Markdown file",
AllowCreation: true,
},
"application/compressed-markdown": {
Extension: "zmd",
Expand All @@ -317,7 +323,6 @@ func mimetypes(cfg *config.Config, logger log.Logger) map[string]map[string]stri
},
}

var m map[string]map[string]string
if err := mapstructure.Decode(mimetypes, &m); err != nil {
logger.Error().Err(err).Msg("Failed to decode defaultapp registry mimetypes to mapstructure")
return nil
Expand Down