mediaapi: Remove unnecessary ContentDisposition

Content-Disposition is only used for communicating the filename. It does
not need to be stored in the database as we have upload_name anyway. It
does not need to be in types.MediaMetadata and does not need to be
logged.
This commit is contained in:
Robert Swain 2017-05-26 17:24:13 +02:00
parent 731c10a418
commit d83359dd51
3 changed files with 25 additions and 42 deletions

View file

@ -34,8 +34,6 @@ CREATE TABLE IF NOT EXISTS media_repository (
media_origin TEXT NOT NULL, media_origin TEXT NOT NULL,
-- The MIME-type of the media file as specified when uploading. -- The MIME-type of the media file as specified when uploading.
content_type TEXT NOT NULL, content_type TEXT NOT NULL,
-- The HTTP Content-Disposition header for the media file as specified when uploading.
content_disposition TEXT NOT NULL,
-- Size of the media file in bytes. -- Size of the media file in bytes.
file_size_bytes BIGINT NOT NULL, file_size_bytes BIGINT NOT NULL,
-- When the content was uploaded in UNIX epoch ms. -- When the content was uploaded in UNIX epoch ms.
@ -51,12 +49,12 @@ CREATE UNIQUE INDEX IF NOT EXISTS media_repository_index ON media_repository (me
` `
const insertMediaSQL = ` const insertMediaSQL = `
INSERT INTO media_repository (media_id, media_origin, content_type, content_disposition, file_size_bytes, creation_ts, upload_name, base64hash, user_id) INSERT INTO media_repository (media_id, media_origin, content_type, file_size_bytes, creation_ts, upload_name, base64hash, user_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
` `
const selectMediaSQL = ` const selectMediaSQL = `
SELECT content_type, content_disposition, file_size_bytes, creation_ts, upload_name, base64hash, user_id FROM media_repository WHERE media_id = $1 AND media_origin = $2 SELECT content_type, file_size_bytes, creation_ts, upload_name, base64hash, user_id FROM media_repository WHERE media_id = $1 AND media_origin = $2
` `
type mediaStatements struct { type mediaStatements struct {
@ -82,7 +80,6 @@ func (s *mediaStatements) insertMedia(mediaMetadata *types.MediaMetadata) error
mediaMetadata.MediaID, mediaMetadata.MediaID,
mediaMetadata.Origin, mediaMetadata.Origin,
mediaMetadata.ContentType, mediaMetadata.ContentType,
mediaMetadata.ContentDisposition,
mediaMetadata.FileSizeBytes, mediaMetadata.FileSizeBytes,
mediaMetadata.CreationTimestamp, mediaMetadata.CreationTimestamp,
mediaMetadata.UploadName, mediaMetadata.UploadName,
@ -101,7 +98,6 @@ func (s *mediaStatements) selectMedia(mediaID types.MediaID, mediaOrigin gomatri
mediaMetadata.MediaID, mediaMetadata.Origin, mediaMetadata.MediaID, mediaMetadata.Origin,
).Scan( ).Scan(
&mediaMetadata.ContentType, &mediaMetadata.ContentType,
&mediaMetadata.ContentDisposition,
&mediaMetadata.FileSizeBytes, &mediaMetadata.FileSizeBytes,
&mediaMetadata.CreationTimestamp, &mediaMetadata.CreationTimestamp,
&mediaMetadata.UploadName, &mediaMetadata.UploadName,

View file

@ -20,9 +20,6 @@ import (
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
// ContentDisposition is an HTTP Content-Disposition header string
type ContentDisposition string
// FileSizeBytes is a file size in bytes // FileSizeBytes is a file size in bytes
type FileSizeBytes int64 type FileSizeBytes int64
@ -52,15 +49,14 @@ type UnixMs int64
// MediaMetadata is metadata associated with a media file // MediaMetadata is metadata associated with a media file
type MediaMetadata struct { type MediaMetadata struct {
MediaID MediaID MediaID MediaID
Origin gomatrixserverlib.ServerName Origin gomatrixserverlib.ServerName
ContentType ContentType ContentType ContentType
ContentDisposition ContentDisposition FileSizeBytes FileSizeBytes
FileSizeBytes FileSizeBytes CreationTimestamp UnixMs
CreationTimestamp UnixMs UploadName Filename
UploadName Filename Base64Hash Base64Hash
Base64Hash Base64Hash UserID MatrixUserID
UserID MatrixUserID
} }
// ActiveRemoteRequests is a lockable map of media URIs requested from remote homeservers // ActiveRemoteRequests is a lockable map of media URIs requested from remote homeservers

View file

@ -57,11 +57,10 @@ func Upload(req *http.Request, cfg *config.MediaAPI, db *storage.Database) util.
} }
r.Logger.WithFields(log.Fields{ r.Logger.WithFields(log.Fields{
"Origin": r.MediaMetadata.Origin, "Origin": r.MediaMetadata.Origin,
"UploadName": r.MediaMetadata.UploadName, "UploadName": r.MediaMetadata.UploadName,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"Content-Type": r.MediaMetadata.ContentType, "Content-Type": r.MediaMetadata.ContentType,
"Content-Disposition": r.MediaMetadata.ContentDisposition,
}).Info("Uploading file") }).Info("Uploading file")
// The file data is hashed and the hash is used as the MediaID. The hash is useful as a // The file data is hashed and the hash is used as the MediaID. The hash is useful as a
@ -89,13 +88,12 @@ func Upload(req *http.Request, cfg *config.MediaAPI, db *storage.Database) util.
r.MediaMetadata.MediaID = types.MediaID(hash) r.MediaMetadata.MediaID = types.MediaID(hash)
r.Logger.WithFields(log.Fields{ r.Logger.WithFields(log.Fields{
"MediaID": r.MediaMetadata.MediaID, "MediaID": r.MediaMetadata.MediaID,
"Origin": r.MediaMetadata.Origin, "Origin": r.MediaMetadata.Origin,
"Base64Hash": r.MediaMetadata.Base64Hash, "Base64Hash": r.MediaMetadata.Base64Hash,
"UploadName": r.MediaMetadata.UploadName, "UploadName": r.MediaMetadata.UploadName,
"FileSizeBytes": r.MediaMetadata.FileSizeBytes, "FileSizeBytes": r.MediaMetadata.FileSizeBytes,
"Content-Type": r.MediaMetadata.ContentType, "Content-Type": r.MediaMetadata.ContentType,
"Content-Disposition": r.MediaMetadata.ContentDisposition,
}).Info("File uploaded") }).Info("File uploaded")
// check if we already have a record of the media in our database and if so, we can remove the temporary directory // check if we already have a record of the media in our database and if so, we can remove the temporary directory
@ -141,11 +139,10 @@ func parseAndValidateRequest(req *http.Request, cfg *config.MediaAPI) (*uploadRe
r := &uploadRequest{ r := &uploadRequest{
MediaMetadata: &types.MediaMetadata{ MediaMetadata: &types.MediaMetadata{
Origin: cfg.ServerName, Origin: cfg.ServerName,
ContentDisposition: types.ContentDisposition(req.Header.Get("Content-Disposition")), FileSizeBytes: types.FileSizeBytes(req.ContentLength),
FileSizeBytes: types.FileSizeBytes(req.ContentLength), ContentType: types.ContentType(req.Header.Get("Content-Type")),
ContentType: types.ContentType(req.Header.Get("Content-Type")), UploadName: types.Filename(url.PathEscape(req.FormValue("filename"))),
UploadName: types.Filename(url.PathEscape(req.FormValue("filename"))),
}, },
Logger: util.GetLogger(req.Context()), Logger: util.GetLogger(req.Context()),
} }
@ -154,12 +151,6 @@ func parseAndValidateRequest(req *http.Request, cfg *config.MediaAPI) (*uploadRe
return nil, resErr return nil, resErr
} }
if len(r.MediaMetadata.UploadName) > 0 {
r.MediaMetadata.ContentDisposition = types.ContentDisposition(
"inline; filename*=utf-8''" + string(r.MediaMetadata.UploadName),
)
}
return r, nil return r, nil
} }