Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔊 Debug
Browse files Browse the repository at this point in the history
Danieloni1 committed May 23, 2024
1 parent 3e42165 commit 0c8769f
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
@@ -59,23 +59,29 @@ 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)
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.",
6 changes: 6 additions & 0 deletions api/r0/upload_sync.go
Original file line number Diff line number Diff line change
@@ -35,23 +35,29 @@ 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)
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.",

0 comments on commit 0c8769f

Please sign in to comment.