diff --git a/config.sample.yaml b/config.sample.yaml index 6e7f6292d2e2ad7b1c55fac8a9adce19394c8e43..e68596b1037bb55cb8f22dd93f6044b141e73101 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -50,6 +50,15 @@ uploads: allowedTypes: - "*/*" + # If not all file types are allowed, then you can make an exlusion for some users. So + # that users can upload file types that not allowed to others. + #exclusions: + # "@admin1:matrix.org": + # - "application/pdf" + # - "application/vnd.ms-excel" + # "@admin2:matrix.org": [*/*] + + # Settings related to downloading files from the media repository downloads: # The maximum number of bytes to download from other servers diff --git a/src/github.com/turt2live/matrix-media-repo/common/config/config.go b/src/github.com/turt2live/matrix-media-repo/common/config/config.go index 1c2a7d62e0407d4695655c64ae3bf480d54a98c1..c9dca0b2c0ac486f264f33eed9dfae91defcc251 100644 --- a/src/github.com/turt2live/matrix-media-repo/common/config/config.go +++ b/src/github.com/turt2live/matrix-media-repo/common/config/config.go @@ -32,10 +32,11 @@ type DatabaseConfig struct { } type UploadsConfig struct { - StoragePaths []string `yaml:"storagePaths,flow"` - MaxSizeBytes int64 `yaml:"maxBytes"` - AllowedTypes []string `yaml:"allowedTypes,flow"` - ReportedMaxSizeBytes int64 `yaml:"reportedMaxBytes"` + StoragePaths []string `yaml:"storagePaths,flow"` + MaxSizeBytes int64 `yaml:"maxBytes"` + AllowedTypes []string `yaml:"allowedTypes,flow"` + AllowedExcl map[string][]string `yaml:"exclusions,flow"` + ReportedMaxSizeBytes int64 `yaml:"reportedMaxBytes"` } type DownloadsConfig struct { diff --git a/src/github.com/turt2live/matrix-media-repo/controllers/upload_controller/upload_controller.go b/src/github.com/turt2live/matrix-media-repo/controllers/upload_controller/upload_controller.go index 7e8d5d7426c535df2157c74268dd672c69ba23a1..1b91412f431ee945db5066b2ca1d904521b65afe 100644 --- a/src/github.com/turt2live/matrix-media-repo/controllers/upload_controller/upload_controller.go +++ b/src/github.com/turt2live/matrix-media-repo/controllers/upload_controller/upload_controller.go @@ -75,10 +75,23 @@ func StoreDirect(contents io.Reader, contentType string, filename string, userId } } if !allowed { + exclusion := false + for user, userExcl := range config.Get().Uploads.AllowedExcl { + if user == userId { + for _, exclType := range userExcl { + if glob.Glob(exclType, fileMime){ + exclusion = true + log.Info("Content type " + fileMime +" (reported as " + contentType+") is allowed to be uploaded as exclusion for user "+ userId) + } + } + } + } + if !exclusion { log.Warn("Content type " + fileMime +" (reported as " + contentType+") is not allowed to be uploaded") os.Remove(fileLocation) // delete temp file return nil, common.ErrMediaNotAllowed + } } hash, err := storage.GetFileHash(fileLocation)