Skip to content

Added progress bar on package upload function#132

Merged
ravish1729 merged 1 commit intov0.4.1from
feat/upload-on-stream
Aug 12, 2025
Merged

Added progress bar on package upload function#132
ravish1729 merged 1 commit intov0.4.1from
feat/upload-on-stream

Conversation

@ravish1729
Copy link
Copy Markdown
Collaborator

@ravish1729 ravish1729 commented Aug 12, 2025

PR Type

Enhancement


Description

  • Added progress tracking callback to file upload functions

  • Enhanced stream handling with file size tracking

  • Implemented progress calculation for both single files and directories

  • Updated function signatures to support upload progress monitoring


Diagram Walkthrough

flowchart LR
  A["Upload Function"] --> B["Progress Callback"]
  B --> C["Stream Handler"]
  C --> D["File Size Tracking"]
  D --> E["Progress Calculation"]
  E --> F["Progress Updates"]
Loading

File Walkthrough

Relevant files
Enhancement
index.ts
Add progress callback parameter to main upload function   

src/Lighthouse/upload/files/index.ts

  • Added uploadProgressCallback parameter to uploadFiles function
  • Passed progress callback to underlying upload functions
+1/-1     
node.ts
Implement progress tracking in Node.js upload handler       

src/Lighthouse/upload/files/node.ts

  • Added uploadProgressCallback parameter to upload function signature
  • Enhanced file objects with size property for progress tracking
  • Integrated progress callback with stream handling for both files and
    directories
+18/-6   
util.ts
Add progress tracking to stream utility functions               

src/Lighthouse/utils/util.ts

  • Updated DirectStreamOptions interface to accept progress callback with
    data object
  • Added total bytes calculation and progress tracking logic
  • Implemented progress updates during stream data transfer
+29/-2   

@ravish1729 ravish1729 merged commit a138351 into v0.4.1 Aug 12, 2025
@codiumai-pr-agent-free
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Progress Calculation

The progress calculation divides bytes uploaded by total bytes, but doesn't account for HTTP headers and multipart form boundaries in the total size calculation, which could lead to progress values exceeding 100% for large files.

if (onProgress && totalBytesToUpload > 0) {
  totalBytesUploaded += chunk.length
  const progress = Math.min(
    (totalBytesUploaded / totalBytesToUpload) * 100,
    100
  )
  onProgress({ progress })
}
Error Handling

The progress callback is passed directly to the stream handler without any error handling. If the callback throws an exception, it could interrupt the upload process.

onProgress: uploadProgressCallback
  ? (data: { progress: number }) => uploadProgressCallback(data)
  : undefined,

@codiumai-pr-agent-free
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Fix progress calculation accuracy

The progress calculation is inaccurate because it doesn't account for the
overhead of multipart form data boundaries and headers. This can lead to
progress values that don't properly reflect the actual upload status. Add a
buffer to the total size calculation to account for this overhead.

src/Lighthouse/utils/util.ts [234-250]

 const onData = (chunk: any) => {
   // Update progress if callback is provided
   if (onProgress && totalBytesToUpload > 0) {
     totalBytesUploaded += chunk.length
+    // Account for multipart form data overhead by limiting progress to 99% until complete
     const progress = Math.min(
-      (totalBytesUploaded / totalBytesToUpload) * 100,
-      100
+      (totalBytesUploaded / totalBytesToUpload) * 99,
+      99
     )
     onProgress({ progress })
   }
 
   const canWrite = req.write(chunk)
   if (!canWrite) {
     stream.pause()
     req.once('drain', () => stream.resume())
   }
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that multipart form overhead is not accounted for in the progress calculation, and the proposed fix of capping progress at 99% is a reasonable workaround to prevent a misleading premature completion status.

Low
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants