Skip to content

Commit

Permalink
[bugfix] fix file range length calculation being off by 1 (#1448)
Browse files Browse the repository at this point in the history
* small formatting change

* fix range handling new length calculation

---------

Signed-off-by: kim <grufwub@gmail.com>
  • Loading branch information
NyaaaWhatsUpDoc committed Feb 7, 2023
1 parent 6a6647d commit ac2bdbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions internal/api/fileserver/servefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions internal/processing/media/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ac2bdbb

Please sign in to comment.