-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clipper: Add capability of limiting downloads #9788
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e5b4811
add downloadController classes
pedr 11d2be7
implementing downloadLimiter to extractNote
pedr 67f5020
add tests
pedr d602b72
commiting yarn lock
pedr 305ae73
moving bytesToHuman to its a bytes module
pedr 7cf098a
improving grammar
pedr e3fb948
moving downloadController to fetchBlob options
pedr 816fafb
renaming
pedr 4f9b646
removing dummy and checking before using download controller
pedr 0398f56
Removing third party dependency
pedr 6823ab5
fixing tests
pedr 4bbb561
Merge remote-tracking branch 'upstream/dev' into download-controller
pedr a7c89b5
update yarn lock
pedr 1aa1c9b
fix fetchOptions being a optional argument
pedr f72323d
replacing urls length with infinity
pedr cfcad1e
removing unnecessary code
pedr f568ede
moving utility function to correct package
pedr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
implementing downloadLimiter to extractNote
- Loading branch information
commit 11d2be78e367b22a716327c1f4c07a425f25fae2
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import * as fs from 'fs-extra'; | |
import * as pdfJsNamespace from 'pdfjs-dist'; | ||
import { writeFile } from 'fs/promises'; | ||
import { ResourceEntity } from './services/database/types'; | ||
import { DownloadController, DummyDownloadController } from './downloadController'; | ||
|
||
const { FileApiDriverLocal } = require('./file-api-driver-local'); | ||
const mimeUtils = require('./mime-utils.js').mime; | ||
|
@@ -471,9 +472,10 @@ function shimInit(options: ShimInitOptions = null) { | |
}, options); | ||
}; | ||
|
||
shim.fetchBlob = async function(url: any, options) { | ||
shim.fetchBlob = async function(url: any, options: any, downloadController?: DownloadController) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
if (!options || !options.path) throw new Error('fetchBlob: target file path is missing'); | ||
if (!options.method) options.method = 'GET'; | ||
if (!downloadController) downloadController = new DummyDownloadController(); | ||
// if (!('maxRetry' in options)) options.maxRetry = 5; | ||
|
||
// 21 maxRedirects is the default amount from follow-redirects library | ||
|
@@ -549,6 +551,9 @@ function shimInit(options: ShimInitOptions = null) { | |
}); | ||
|
||
const request = http.request(requestOptions, (response: any) => { | ||
|
||
response.on('data', downloadController.handleNewChunk(request)); | ||
|
||
response.pipe(file); | ||
|
||
const isGzipped = response.headers['content-encoding'] === 'gzip'; | ||
|
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the downloadController optional.
I know we have this rule to avoid optional parameters, but when it means having to create a dummy object on each call it's better to make it optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also why do we need this dummy controller? Isn't it possible to make the code work with a simple
null
controller? I guess there will be a few null checks here and there.Especially since
fetchBlob
is heavily used for sync it's better to avoid creating unnecessary objects on each call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if it's optional, make it part of the "fetchOptions" object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I move the downloadController to be a property of the other options object and instead of creating a dummy class I'm checking before using downloadController like you suggested.