Return null if MaxFileSizeBytes is 0 (#2409)

* Return "null" if MaxFileSizeBytes is 0

* Add comment and nil check (better save than sorry)

* Simplify config
This commit is contained in:
Till 2022-05-02 10:47:16 +02:00 committed by GitHub
parent bfa344e831
commit 979a551f1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 18 deletions

View file

@ -35,7 +35,7 @@ import (
// configResponse is the response to GET /_matrix/media/r0/config
// https://matrix.org/docs/spec/client_server/latest#get-matrix-media-r0-config
type configResponse struct {
UploadSize config.FileSizeBytes `json:"m.upload.size"`
UploadSize *config.FileSizeBytes `json:"m.upload.size"`
}
// Setup registers the media API HTTP handlers
@ -73,9 +73,13 @@ func Setup(
if r := rateLimits.Limit(req); r != nil {
return *r
}
respondSize := &cfg.MaxFileSizeBytes
if cfg.MaxFileSizeBytes == 0 {
respondSize = nil
}
return util.JSONResponse{
Code: http.StatusOK,
JSON: configResponse{UploadSize: *cfg.MaxFileSizeBytes},
JSON: configResponse{UploadSize: respondSize},
}
})