mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-29 15:29:52 -05:00
make mimetype allow list configurable and add example config
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
@@ -167,6 +168,11 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg
|
||||
},
|
||||
"appregistry": map[string]interface{}{
|
||||
"driver": "static",
|
||||
"drivers": map[string]interface{}{
|
||||
"static": map[string]interface{}{
|
||||
"mime_types": mimetypes(cfg, logger),
|
||||
},
|
||||
},
|
||||
},
|
||||
"storageregistry": map[string]interface{}{
|
||||
"driver": cfg.Reva.StorageRegistry.Driver,
|
||||
@@ -222,6 +228,118 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac
|
||||
}
|
||||
}
|
||||
|
||||
func mimetypes(cfg *config.Config, logger log.Logger) (m map[string]map[string]string) {
|
||||
|
||||
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"`
|
||||
}
|
||||
type mimetypesConfig map[string]mimeTypeConfig
|
||||
|
||||
var mimetypes mimetypesConfig
|
||||
|
||||
// load default app mimetypes from a json file
|
||||
if cfg.Reva.AppRegistry.MimetypesJSON != "" {
|
||||
data, err := ioutil.ReadFile(cfg.Reva.AppRegistry.MimetypesJSON)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("Failed to read app registry mimetypes from JSON file: " + cfg.Reva.AppRegistry.MimetypesJSON)
|
||||
return nil
|
||||
}
|
||||
if err = json.Unmarshal(data, &mimetypes); err != nil {
|
||||
logger.Error().Err(err).Msg("Failed to unmarshal storage registry rules")
|
||||
return nil
|
||||
}
|
||||
if err := mapstructure.Decode(mimetypes, &m); err != nil {
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
logger.Info().Msg("No app registry mimetypes JSON file provided, loading default configuration")
|
||||
|
||||
mimetypes = map[string]mimeTypeConfig{
|
||||
"application/pdf": {
|
||||
Extension: "pdf",
|
||||
Name: "PDF",
|
||||
Description: "PDF document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.oasis.opendocument.text": {
|
||||
Extension: "odt",
|
||||
Name: "OpenDocument",
|
||||
Description: "OpenDocument text document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.oasis.opendocument.spreadsheet": {
|
||||
Extension: "ods",
|
||||
Name: "OpenSpreadsheet",
|
||||
Description: "OpenDocument spreadsheet document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.oasis.opendocument.presentation": {
|
||||
Extension: "odp",
|
||||
Name: "OpenPresentation",
|
||||
Description: "OpenDocument presentation document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
|
||||
Extension: "docx",
|
||||
Name: "Microsoft Word",
|
||||
Description: "Microsoft Word document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
|
||||
Extension: "xlsx",
|
||||
Name: "Microsoft Excel",
|
||||
Description: "Microsoft Excel document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
|
||||
Extension: "pptx",
|
||||
Name: "Microsoft PowerPoint",
|
||||
Description: "Microsoft PowerPoint document",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/vnd.jupyter": {
|
||||
Extension: "ipynb",
|
||||
Name: "Jupyter Notebook",
|
||||
Description: "Jupyter Notebook",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"text/markdown": {
|
||||
Extension: "md",
|
||||
Name: "Markdown file",
|
||||
Description: "Markdown file",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
"application/compressed-markdown": {
|
||||
Extension: "zmd",
|
||||
Name: "Compressed markdown file",
|
||||
Description: "Compressed markdown file",
|
||||
Icon: "",
|
||||
DefaultApp: "",
|
||||
},
|
||||
}
|
||||
|
||||
if err := mapstructure.Decode(mimetypes, &m); err != nil {
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
|
||||
}
|
||||
|
||||
// GatewaySutureService allows for the storage-gateway command to be embedded and supervised by a suture supervisor tree.
|
||||
type GatewaySutureService struct {
|
||||
cfg *config.Config
|
||||
|
||||
Reference in New Issue
Block a user