Skip to content

Commit

Permalink
add support for passing custom headers
Browse files Browse the repository at this point in the history
- also bumped ODD version to v2.1.0.8
  • Loading branch information
Chaphasilor committed Aug 1, 2022
1 parent ae5aa39 commit 7dd2ddc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ indexer.scanUrl(url)
| Wrapper Version | Supported ODD Versions (up to) | Included Version |
| --- | --- | --- |
| **6.1.2** | **2.1.0.0** | **2.1.0.0** |
| **6.2.0** | **2.1.0.8** | **2.1.0.8** |
| 6.1.2 | 2.1.0.0 | 2.1.0.0 |
| 6.1.0 | 2.1.0.0 | 2.1.0.0 |
| 5.1.0 | 2.0.0.6 | 2.0.0.3 |
| 5.0.0 | 2.0.0.2 | 2.0.0.0 |
Expand Down Expand Up @@ -118,6 +119,7 @@ Some intermediary releases might not be fully supported. It is recommended to us
- `auth` (`Object`) (optional) Used to configure (HTTP Basic) auth settings
- `username` (`String`) (optional, default is `""`]) The user name to use for authentication
- `password` (`String`) (optional, default is `""`]) The password to use for authentication
- `auth` (`Object`) (optional) Used to configure additional headers to be sent with each request (cookies, referrers, etc.). Headers are key-value pairs of strings.
- `threads` (`Number`) (optional, default is `5`] Number of threads to use for scanning
- `timeout` (`Number`) (optional, default is `100`] Number of seconds to wait before timing out
- **Returns**: Promise<Resolves to `ScanResult` | Rejects to `Array<Error[,ScanResult]>`>
Expand Down
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module.exports = {}

module.exports.GitHubReleasesUrl = `https://api.github.com/repos/KoalaBear84/OpenDirectoryDownloader/releases`
module.exports.OpenDirectoryDownloaderVersion = {
version: `v2.1.0.0`,
releaseId: `50845174`
version: `v2.1.0.8`,
releaseId: `53442251`
}
module.exports.OpenDirectoryDownloaderFolder = `${__dirname}/ODD`
module.exports.OpenDirectoryDownloaderOutputFolderName = `Scans`
Expand Down
12 changes: 12 additions & 0 deletions open-directory-downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports.OpenDirectoryDownloader = class OpenDirectoryDownloader {
* @param {Object} [options.auth] Used to configure (HTTP Basic) auth settings
* @param {String} [options.auth.username=""] The user name to use for authentication
* @param {String} [options.auth.password=""] The password to use for authentication
* @param {Object} [options.headers] Object containing additional headers to use for all HTTP requests
* @param {Number} [options.threads=5] Number of threads to use for scanning
* @param {Number} [options.timeout=100] Number of seconds to wait before timing out
*/
Expand All @@ -71,6 +72,7 @@ module.exports.OpenDirectoryDownloader = class OpenDirectoryDownloader {
options.uploadUrlFile = options.uploadUrlFile || false
options.fastScan = options.fastScan || false
options.exactSizes = options.exactSizes || false
options.headers = options.headers || {}

// both String and URL implement the toString() method, so just use that instead of detecting the type
let processArgs = [`-u "${url}"`, `--quit`, `--json`, ]
Expand Down Expand Up @@ -116,6 +118,16 @@ module.exports.OpenDirectoryDownloader = class OpenDirectoryDownloader {
processArgs.push(`"${options.auth.password}"`)
}

if (options.headers !== {}) {
Object.entries(options.headers).forEach(([headerName, headerValue]) => {
if (typeof headerValue !== `string`) {
throw new ODDWrapperError(`Header value for ${headerName} is not a string!`)
}
processArgs.push(`--header`)
processArgs.push(`"${headerName}: ${headerValue}"`)
})
}

const oddProcess = spawn(this.executable, processArgs, {
shell: true,
cwd: this.outputDir,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open-directory-downloader",
"version": "6.1.2",
"version": "6.2.0",
"description": "A NodeJS wrapper around KoalaBear84/OpenDirectoryDownloader",
"main": "open-directory-downloader.js",
"scripts": {
Expand Down

0 comments on commit 7dd2ddc

Please sign in to comment.