Skip to content

Commit

Permalink
Fixed protocol issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
flowbe committed Aug 4, 2020
1 parent 0e20913 commit 991a197
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions 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": "qbittorrent-api-v2",
"version": "1.2.0",
"version": "1.2.1",
"description": "Wrapper around qBittorrent's Web API v2 to manage your torrents from Node. Documented and everything.",
"main": "src/qbt.js",
"directories": {
Expand Down
13 changes: 7 additions & 6 deletions src/qbt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const https = require('https')
const protocol = { 'https:': require('https'), 'http:': require('http') }

const ENDPOINT = '/api/v2'

Expand All @@ -9,10 +9,11 @@ const ENDPOINT = '/api/v2'
* @param {string} password - Password used to access the WebUI
*/
exports.connect = async (host, username, password) => {
const hostname = new URL(host)
const options = {
hostname: host.replace(/https?:\/\//, '').replace(/:[0-9]*/, ''),
protocol: (host.startsWith('https://')) ? 'https:' : 'http:',
port: parseInt(host.split(':')[2]) || ((host.startsWith('https://')) ? 443 : 80)
hostname: hostname.host,
protocol: hostname.protocol,
port: parseInt(hostname.port) || (hostname.protocol == 'https://' ? 443 : 80)
}

try {
Expand Down Expand Up @@ -954,7 +955,7 @@ async function toggleSpeedLimitsMode(options, cookie) {
}

async function globalDownloadLimit(options, cookie) {
const { res } = await performRequest(options, cookie, '/transfer/downloadLimit', {})
const { res } = await performRequest(options, cookie, '/transfer/downloadLimit', {})
return res
}

Expand Down Expand Up @@ -1299,7 +1300,7 @@ function performRequest(opt, cookie, path, parameters) {
}

return new Promise((resolve, reject) => {
const req = https.request(options, res => {
const req = protocol[options.protocol].request(options, res => {
let data = []

res.on('data', chunk => data.push(chunk))
Expand Down

0 comments on commit 991a197

Please sign in to comment.