mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
GODT-1204: Handle importing too big messages
This commit is contained in:
committed by
Jakub Cuth
parent
1ed8e939b8
commit
e940d9f6fe
@ -27,7 +27,10 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
const MaxImportMessageRequestLength = 10
|
||||
const (
|
||||
MaxImportMessageRequestLength = 10
|
||||
MaxImportMessageRequestSize = 25 * 1024 * 1024 // 25 MB total limit
|
||||
)
|
||||
|
||||
type ImportMsgReq struct {
|
||||
Metadata *ImportMetadata // Metadata about the message to import.
|
||||
@ -91,6 +94,14 @@ func (c *client) Import(ctx context.Context, reqs ImportMsgReqs) ([]*ImportMsgRe
|
||||
return nil, errors.New("request is too long")
|
||||
}
|
||||
|
||||
remainingSize := MaxImportMessageRequestSize
|
||||
for _, req := range reqs {
|
||||
remainingSize -= len(req.Message)
|
||||
if remainingSize < 0 {
|
||||
return nil, errors.New("request size is too big")
|
||||
}
|
||||
}
|
||||
|
||||
fields, err := reqs.buildMultipartFormData()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user