From 65f64341d2307d7ec2a3d201effec65c1ece5d24 Mon Sep 17 00:00:00 2001 From: Travis Ralston <travpc@gmail.com> Date: Mon, 20 Jul 2020 21:30:41 -0600 Subject: [PATCH] Remove deprecated support for forUploads --- CHANGELOG.md | 1 + common/config/models_domain.go | 1 - config.sample.yaml | 5 ++--- storage/datastore/datastore.go | 5 ----- util/mime.go | 38 ---------------------------------- 5 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 util/mime.go diff --git a/CHANGELOG.md b/CHANGELOG.md index a46257ac..a622b9d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed * Remove deprecated support for restricting uploads to certain mime types. +* Remove deprecated support for `forUploads`. ### Fixed diff --git a/common/config/models_domain.go b/common/config/models_domain.go index db3ec77f..673407e7 100644 --- a/common/config/models_domain.go +++ b/common/config/models_domain.go @@ -15,7 +15,6 @@ type UploadsConfig struct { type DatastoreConfig struct { Type string `yaml:"type"` Enabled bool `yaml:"enabled"` - ForUploads bool `yaml:"forUploads"` // deprecated MediaKinds []string `yaml:"forKinds,flow"` Options map[string]string `yaml:"opts,flow"` } diff --git a/config.sample.yaml b/config.sample.yaml index 0e99a723..f13370fb 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -125,9 +125,8 @@ sharedSecretAuth: token: "PutSomeRandomSecureValueHere" # Datastores are places where media should be persisted. This isn't dedicated for just uploads: -# thumbnails and other misc data is also stored in these places. When the media repo is looking -# to store new media (such as user uploads, thumbnails, etc) it will look for a datastore which -# is flagged as forUploads. It will try to use the smallest datastore first. +# thumbnails and other misc data is also stored in these places. The media repo, when looking +# for a datastore to use, will always use the smallest datastore first. datastores: - type: file enabled: false # Enable this to set up data storage. diff --git a/storage/datastore/datastore.go b/storage/datastore/datastore.go index ff6b1a19..e3e6d81b 100644 --- a/storage/datastore/datastore.go +++ b/storage/datastore/datastore.go @@ -106,11 +106,6 @@ func PickDatastore(forKind string, ctx rcontext.RequestContext) (*DatastoreRef, continue } - if len(dsConf.MediaKinds) == 0 && dsConf.ForUploads { - ctx.Log.Warnf("Datastore of type %s is using a deprecated flag (forUploads) - please use forKinds instead", dsConf.Type) - dsConf.MediaKinds = common.AllKinds - } - allowed := common.HasKind(dsConf.MediaKinds, forKind) if !allowed { continue diff --git a/util/mime.go b/util/mime.go deleted file mode 100644 index dfaf5239..00000000 --- a/util/mime.go +++ /dev/null @@ -1,38 +0,0 @@ -package util - -import ( - "io" - "net/http" - "strings" - - "github.com/h2non/filetype" - "github.com/turt2live/matrix-media-repo/util/cleanup" -) - -func GetMimeType(stream io.ReadCloser) (string, error) { - defer cleanup.DumpAndCloseStream(stream) - - // We only need the first 512 bytes at most to determine the file type - buf := make([]byte, 512) - _, err := stream.Read(buf) - if err != nil && err != io.EOF { - return "", err - } - - // Try identifying through the filetype repo first - kind, err := filetype.Match(buf) - if err != nil || kind == filetype.Unknown { - // It's unknown or had a problem reading - try against the http lib - contentType := http.DetectContentType(buf) - contentType = strings.Split(contentType, ";")[0] - - // This shouldn't happen, but we'll check anyways. The http lib should return application/octet-stream - // if it can't figure it out. - if contentType == "" { - contentType = "application/x-binary" - } - return contentType, nil - } - - return kind.MIME.Value, nil -} -- GitLab