You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
File Walkthrough
index.ts
Add progress callback parameter to main upload functionsrc/Lighthouse/upload/files/index.ts
uploadProgressCallbackparameter touploadFilesfunctionnode.ts
Implement progress tracking in Node.js upload handlersrc/Lighthouse/upload/files/node.ts
uploadProgressCallbackparameter to upload function signaturedirectories
util.ts
Add progress tracking to stream utility functionssrc/Lighthouse/utils/util.ts
DirectStreamOptionsinterface to accept progress callback withdata object