Skip to content
Snippets Groups Projects
Commit 65f64341 authored by Travis Ralston's avatar Travis Ralston
Browse files

Remove deprecated support for forUploads

parent fbd1a2b7
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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"`
}
......
......@@ -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.
......
......@@ -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
......
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment