mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-09 22:42:58 +00:00
Fix unlimitedSize uploads (#2317)
This commit is contained in:
parent
cd8fac152e
commit
a0f5d8e1a5
@ -169,7 +169,7 @@ func (r *uploadRequest) doUpload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if temp file size exceeds max file size configuration
|
// Check if temp file size exceeds max file size configuration
|
||||||
if bytesWritten > types.FileSizeBytes(*cfg.MaxFileSizeBytes) {
|
if *cfg.MaxFileSizeBytes > 0 && bytesWritten > types.FileSizeBytes(*cfg.MaxFileSizeBytes) {
|
||||||
fileutils.RemoveDir(tmpDir, r.Logger) // delete temp file
|
fileutils.RemoveDir(tmpDir, r.Logger) // delete temp file
|
||||||
return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes)
|
return requestEntityTooLargeJSONResponse(*cfg.MaxFileSizeBytes)
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ func Test_uploadRequest_doUpload(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
maxSize := config.FileSizeBytes(8)
|
maxSize := config.FileSizeBytes(8)
|
||||||
|
unlimitedSize := config.FileSizeBytes(0)
|
||||||
logger := log.New().WithField("mediaapi", "test")
|
logger := log.New().WithField("mediaapi", "test")
|
||||||
testdataPath := filepath.Join(wd, "./testdata")
|
testdataPath := filepath.Join(wd, "./testdata")
|
||||||
|
|
||||||
@ -117,6 +118,27 @@ func Test_uploadRequest_doUpload(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: requestEntityTooLargeJSONResponse(maxSize),
|
want: requestEntityTooLargeJSONResponse(maxSize),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "upload ok with unlimited filesize",
|
||||||
|
args: args{
|
||||||
|
ctx: context.Background(),
|
||||||
|
reqReader: strings.NewReader("test test test"),
|
||||||
|
cfg: &config.MediaAPI{
|
||||||
|
MaxFileSizeBytes: &unlimitedSize,
|
||||||
|
BasePath: config.Path(testdataPath),
|
||||||
|
AbsBasePath: config.Path(testdataPath),
|
||||||
|
DynamicThumbnails: false,
|
||||||
|
},
|
||||||
|
db: db,
|
||||||
|
},
|
||||||
|
fields: fields{
|
||||||
|
Logger: logger,
|
||||||
|
MediaMetadata: &types.MediaMetadata{
|
||||||
|
MediaID: "1339",
|
||||||
|
UploadName: "test fail",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user