From ac2bdbbc62e8e3fec16497df05d01999ec7597f0 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Tue, 7 Feb 2023 08:51:15 +0000 Subject: [PATCH] [bugfix] fix file range length calculation being off by 1 (#1448) * small formatting change * fix range handling new length calculation --------- Signed-off-by: kim --- internal/api/fileserver/servefile.go | 5 +++-- internal/processing/media/delete.go | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/api/fileserver/servefile.go b/internal/api/fileserver/servefile.go index d9fc99b5..cdd42a17 100644 --- a/internal/api/fileserver/servefile.go +++ b/internal/api/fileserver/servefile.go @@ -218,8 +218,9 @@ func serveFileRange(rw http.ResponseWriter, src io.Reader, rng string, size int6 return } - // Determine content len - length := end - start + // Determine new content length + // after slicing to given range. + length := end - start + 1 if end < size-1 { // Range end < file end, limit the reader diff --git a/internal/processing/media/delete.go b/internal/processing/media/delete.go index c0f8aa94..31e733bc 100644 --- a/internal/processing/media/delete.go +++ b/internal/processing/media/delete.go @@ -39,10 +39,8 @@ func (p *processor) Delete(ctx context.Context, mediaAttachmentID string) gtserr } // delete the attachment - if err := p.db.DeleteByID(ctx, mediaAttachmentID, attachment); err != nil { - if err != db.ErrNoEntries { - errs = append(errs, fmt.Sprintf("remove attachment: %s", err)) - } + if err := p.db.DeleteByID(ctx, mediaAttachmentID, attachment); err != nil && !errors.Is(err, db.ErrNoEntries) { + errs = append(errs, fmt.Sprintf("remove attachment: %s", err)) } if len(errs) != 0 {