Connect: Fix progress reporting for empty file uploads (#67885)

* Do not divide by zero

* Prevent `TerminalAddonsContainer` from taking more than 500px width
This commit is contained in:
Grzegorz Zdunek
2026-06-18 09:35:06 +00:00
committed by GitHub
parent 1f6f9abcba
commit 6f5524afcc
4 changed files with 14 additions and 4 deletions
@@ -122,7 +122,7 @@ func (p *fileTransferProgress) maybeUpdateProgress(bytes []byte) (int, error) {
defer p.lock.Unlock()
p.sentSize += int64(bytesLength)
percentage := uint32(p.sentSize * 100 / p.fileSize)
percentage := calculatePercentage(p.sentSize, p.fileSize)
if p.shouldSendProgress(percentage) {
err := p.sendProgress(api.FileTransferProgress_builder{Percentage: percentage}.Build())
@@ -136,6 +136,13 @@ func (p *fileTransferProgress) maybeUpdateProgress(bytes []byte) (int, error) {
return bytesLength, nil
}
func calculatePercentage(part, total int64) uint32 {
if total <= 0 {
return 100
}
return uint32(part * 100 / total)
}
func (p *fileTransferProgress) shouldSendProgress(percentage uint32) bool {
hasIntervalPassed := time.Since(p.lastSentAt).Milliseconds() > 100
hasPercentageChanged := percentage != p.lastSentPercentage
@@ -153,7 +153,8 @@ const TerminalAddonsContainer = styled.div`
flex-direction: column;
align-items: flex-end;
gap: 8px;
min-width: 500px;
width: 100%;
max-width: 500px;
`;
export interface TerminalRef {
@@ -143,5 +143,6 @@ const TerminalAddonsContainer = styled.div`
flex-direction: column;
align-items: flex-end;
gap: ${p => p.theme.space[2]}px;
min-width: 500px;
width: 100%;
max-width: 500px;
`;
@@ -166,7 +166,8 @@ const TerminalAddonsContainer = styled.div`
flex-direction: column;
align-items: flex-end;
gap: 8px;
min-width: 500px;
width: 100%;
max-width: 500px;
`;
const StyledXterm = styled(Box)`