mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 19:33:09 -06:00
Added user id in metadata on file upload
This commit is contained in:
parent
eb5de339f1
commit
b943e73b1c
|
|
@ -61,8 +61,8 @@ func Setup(
|
|||
// TODO: Add AS support
|
||||
r0mux.Handle("/upload", common.MakeAuthAPI(
|
||||
"upload", authData,
|
||||
func(req *http.Request, _ *authtypes.Device) util.JSONResponse {
|
||||
return Upload(req, cfg, db, activeThumbnailGeneration)
|
||||
func(req *http.Request, dev *authtypes.Device) util.JSONResponse {
|
||||
return Upload(req, cfg, dev, db, activeThumbnailGeneration, )
|
||||
},
|
||||
)).Methods(http.MethodPost, http.MethodOptions)
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import (
|
|||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
"github.com/matrix-org/dendrite/mediaapi/fileutils"
|
||||
|
|
@ -53,8 +55,8 @@ type uploadResponse struct {
|
|||
// This implementation supports a configurable maximum file size limit in bytes. If a user tries to upload more than this, they will receive an error that their upload is too large.
|
||||
// Uploaded files are processed piece-wise to avoid DoS attacks which would starve the server of memory.
|
||||
// TODO: We should time out requests if they have not received any data within a configured timeout period.
|
||||
func Upload(req *http.Request, cfg *config.Dendrite, db storage.Database, activeThumbnailGeneration *types.ActiveThumbnailGeneration) util.JSONResponse {
|
||||
r, resErr := parseAndValidateRequest(req, cfg)
|
||||
func Upload(req *http.Request, cfg *config.Dendrite, dev *authtypes.Device, db storage.Database, activeThumbnailGeneration *types.ActiveThumbnailGeneration) util.JSONResponse {
|
||||
r, resErr := parseAndValidateRequest(req, cfg, dev)
|
||||
if resErr != nil {
|
||||
return *resErr
|
||||
}
|
||||
|
|
@ -74,13 +76,14 @@ func Upload(req *http.Request, cfg *config.Dendrite, db storage.Database, active
|
|||
// parseAndValidateRequest parses the incoming upload request to validate and extract
|
||||
// all the metadata about the media being uploaded.
|
||||
// Returns either an uploadRequest or an error formatted as a util.JSONResponse
|
||||
func parseAndValidateRequest(req *http.Request, cfg *config.Dendrite) (*uploadRequest, *util.JSONResponse) {
|
||||
func parseAndValidateRequest(req *http.Request, cfg *config.Dendrite, device *authtypes.Device) (*uploadRequest, *util.JSONResponse) {
|
||||
r := &uploadRequest{
|
||||
MediaMetadata: &types.MediaMetadata{
|
||||
Origin: cfg.Matrix.ServerName,
|
||||
FileSizeBytes: types.FileSizeBytes(req.ContentLength),
|
||||
ContentType: types.ContentType(req.Header.Get("Content-Type")),
|
||||
UploadName: types.Filename(url.PathEscape(req.FormValue("filename"))),
|
||||
UserID: types.MatrixUserID(device.UserID),
|
||||
},
|
||||
Logger: util.GetLogger(req.Context()).WithField("Origin", cfg.Matrix.ServerName),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue