Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix #140
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Apr 25, 2018
1 parent f4acdee commit 395d5bc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/util/url-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ module.exports = (send) => {
const validUrl = (url) => typeof url === 'string' && url.startsWith('http')

const requestWithRedirect = (url, opts, sendOneFile, callback) => {
const req = request(parseUrl(url).protocol)(url, (res) => {
const parsedUrl = parseUrl(url)

const req = request(parsedUrl.protocol)(url, (res) => {
if (res.statusCode >= 400) {
return callback(new Error(`Failed to download with ${res.statusCode}`))
}
Expand All @@ -46,13 +48,18 @@ const requestWithRedirect = (url, opts, sendOneFile, callback) => {
if (!validUrl(redirection)) {
return callback(new Error('redirection url must be an http(s) url'))
}

requestWithRedirect(redirection, opts, sendOneFile, callback)
} else {
const requestOpts = {
qs: opts,
converter: FileResultStreamConverter
}
sendOneFile(res, requestOpts, callback)

sendOneFile({
content: res,
path: parsedUrl.pathname.split('/').pop()
}, requestOpts, callback)
}
})

Expand Down

0 comments on commit 395d5bc

Please sign in to comment.