diff --git a/CHANGELOG.md b/CHANGELOG.md index a46257ac5d0403522fbca600097484585153d297..a622b9d6aec6b8aaa9a475f482673ba6235ac4d0 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 db3ec77fb99dd1337526e75b998887f4ff631dd5..673407e7540a28580fc465d63f598784155316f3 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 0e99a7236087b95e7a2ddfb725c5ec003f390b5d..f13370fbf8f0421f3b1124c600fcf42777523ecc 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 ff6b1a198b0a12ef5dd618d573e8f5ea863fcd07..e3e6d81b434c979090d84709eb26fd3dbf61bbf9 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 dfaf5239d17f0882ae2cba13acfbe84376c02ec8..0000000000000000000000000000000000000000 --- 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 -}