Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/routes/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func getStreamRoute(ctx *gin.Context) {
}
defer pipe.Close()
if _, err := io.CopyN(w, pipe, contentLength); err != nil {
log.Error("Error while copying stream", zap.Error(err))
if !utils.IsClientDisconnectError(err) {
log.Error("Error while copying stream", zap.Error(err))
}
}
}
}
17 changes: 17 additions & 0 deletions internal/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"math/rand"
"strings"

"github.com/celestix/gotgproto"
"github.com/celestix/gotgproto/ext"
Expand All @@ -26,6 +27,22 @@ func Contains[T comparable](s []T, e T) bool {
return false
}

// IsClientDisconnectError checks if the error is due to client disconnecting
// e.g. user seeking in video, stopping playback, or network issues on client side
func IsClientDisconnectError(err error) bool {
if err == nil {
return false
}
errStr := err.Error()
return strings.Contains(errStr, "connection was aborted") ||
strings.Contains(errStr, "connection reset by peer") ||
strings.Contains(errStr, "broken pipe") ||
strings.Contains(errStr, "forcibly closed")
}

// telegram helper functions
// TODO: move these to a separate package if they grow too large

func GetTGMessage(ctx context.Context, client *gotgproto.Client, messageID int) (*tg.Message, error) {
inputMessageID := tg.InputMessageClass(&tg.InputMessageID{ID: messageID})
channel, err := GetLogChannelPeer(ctx, client.API(), client.PeerStorage)
Expand Down