@@ -2,7 +2,6 @@ package r0
2
2
3
3
import (
4
4
"errors"
5
- "io"
6
5
"net/http"
7
6
"path/filepath"
8
7
@@ -15,6 +14,7 @@ import (
15
14
"github.com/t2bot/matrix-media-repo/common"
16
15
"github.com/t2bot/matrix-media-repo/common/rcontext"
17
16
"github.com/t2bot/matrix-media-repo/pipelines/pipeline_upload"
17
+ "github.com/t2bot/matrix-media-repo/util"
18
18
)
19
19
20
20
var supportedFileTypes = []string {
@@ -59,23 +59,29 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
59
59
}
60
60
61
61
// GK-CUSTOMIZATION: Check if the file type is supported
62
- buf , err := io .ReadAll (r .Body )
62
+ rctx .Log .Error ("🔊 Attempting to read file: " , filename )
63
+ var reqBody interface {}
64
+ b , err := util .DecodeWithBuffer (r .Body , & reqBody )
63
65
if err != nil {
66
+ rctx .Log .Error ("🔊 Error decoding body: " , err )
64
67
return & _responses.ErrorResponse {
65
68
Code : common .ErrCodeBadRequest ,
66
- Message : "Error reading file ." ,
69
+ Message : "Error decoding request ." ,
67
70
InternalCode : common .ErrCodeBadRequest ,
68
71
}
69
72
}
70
- kind , err := filetype .Match (buf )
73
+ kind , err := filetype .Match (b . Bytes () )
71
74
if err != nil {
75
+ rctx .Log .Error ("🔊 Error matching file type: " , err )
72
76
return & _responses.ErrorResponse {
73
77
Code : common .ErrCodeBadRequest ,
74
78
Message : "Error matching file type." ,
75
79
InternalCode : common .ErrCodeBadRequest ,
76
80
}
77
81
}
82
+ rctx .Log .Error ("🔊 File type: " , kind )
78
83
if ! isSupportedFileType (kind .Extension ) {
84
+ rctx .Log .Error ("🔊 unsupported file type" )
79
85
return & _responses.ErrorResponse {
80
86
Code : common .ErrCodeBadRequest ,
81
87
Message : "Unsupported file type." ,
0 commit comments