From 497ebd8c4e9db9a1351b841cc7fe04c960fb7987 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:15:53 +0000 Subject: [bugfix] fix media limit reader check (#3363) * return nicer errors for frontend when media / emoji upload limit reached * fix reader limit check * add code comment --- internal/media/util.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'internal/media') diff --git a/internal/media/util.go b/internal/media/util.go index 22121a546..538d6f572 100644 --- a/internal/media/util.go +++ b/internal/media/util.go @@ -29,6 +29,7 @@ import ( "codeberg.org/gruf/go-bytesize" "codeberg.org/gruf/go-iotools" "codeberg.org/gruf/go-mimetypes" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" ) // file represents one file @@ -143,8 +144,9 @@ func drainToTmp(rc io.ReadCloser) (string, error) { // Check to see if limit was reached, // (produces more useful error messages). - if lr != nil && !iotools.AtEOF(lr.R) { - return path, fmt.Errorf("reached read limit %s", bytesize.Size(limit)) + if lr != nil && lr.N <= 0 { + err := fmt.Errorf("reached read limit %s", bytesize.Size(limit)) + return path, gtserror.SetLimitReached(err) } return path, nil -- cgit v1.3