Skip to content

Commit

Permalink
🔊 Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Danieloni1 committed May 23, 2024
1 parent 3a35bd3 commit 177f16b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/r0/upload_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,30 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
}

// GK-CUSTOMIZATION: Check if the file type is supported
rctx.Log.Error("🔊 Attempting to read file: ", filename)
buf, err := io.ReadAll(r.Body)
r.Body = io.NopCloser(bytes.NewBuffer(buf))
if err != nil {
rctx.Log.Error("🔊 Error reading file: ", err)
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Error reading file.",
InternalCode: common.ErrCodeBadRequest,
}
}
rctx.Log.Error("🔊 Successfully read file: ", buf)
kind, err := filetype.Match(buf)
if err != nil {
rctx.Log.Error("🔊 Error matching file type: ", err)
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Error matching file type.",
InternalCode: common.ErrCodeBadRequest,
}
}
rctx.Log.Error("🔊 File type: ", kind)
if !isSupportedFileType(kind.Extension) {
rctx.Log.Error("🔊 unsupported file type")
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Unsupported file type.",
Expand Down
6 changes: 6 additions & 0 deletions api/r0/upload_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,30 @@ func UploadMediaSync(r *http.Request, rctx rcontext.RequestContext, user _apimet
}

// GK-CUSTOMIZATION: Check if the file type is supported
rctx.Log.Error("🔊 Attempting to read file: ", filename)
buf, err := io.ReadAll(r.Body)
r.Body = io.NopCloser(bytes.NewBuffer(buf))
if err != nil {
rctx.Log.Error("🔊 Error reading file: ", err)
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Error reading file.",
InternalCode: common.ErrCodeBadRequest,
}
}
rctx.Log.Error("🔊 Successfully read file: ", buf)
kind, err := filetype.Match(buf)
if err != nil {
rctx.Log.Error("🔊 Error matching file type: ", err)
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Error matching file type.",
InternalCode: common.ErrCodeBadRequest,
}
}
rctx.Log.Error("🔊 File type: ", kind)
if !isSupportedFileType(kind.Extension) {
rctx.Log.Error("🔊 unsupported file type")
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Unsupported file type.",
Expand Down

0 comments on commit 177f16b

Please sign in to comment.