Skip to content

Commit

Permalink
WordPress Media Download Basic Auth Fix (gatsbyjs#3614)
Browse files Browse the repository at this point in the history
* WordPress Media Download Basic Auth Fix

* format
  • Loading branch information
flmuel authored and KyleAMathews committed Jan 20, 2018
1 parent 08332b7 commit 10c27c4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/create-remote-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { isWebUri } = require(`valid-url`)
const { createFileNode } = require(`./create-file-node`)
const cacheId = url => `create-remote-file-node-${url}`

module.exports = ({ url, store, cache, createNode }) =>
module.exports = ({ url, store, cache, createNode, _auth }) =>
new Promise(async (resolve, reject) => {
if (!url || isWebUri(url) === undefined) {
resolve()
Expand All @@ -26,7 +26,9 @@ module.exports = ({ url, store, cache, createNode }) =>
// See if there's response headers for this url
// from a previous request.
const cachedHeaders = await cache.get(cacheId(url))
const headers = {}
const headers = {
auth: _auth.htaccess_user + `:` + _auth.htaccess_pass,
}
if (cachedHeaders && cachedHeaders.etag) {
headers[`If-None-Match`] = cachedHeaders.etag
}
Expand All @@ -53,7 +55,7 @@ module.exports = ({ url, store, cache, createNode }) =>
let statusCode
let responseHeaders
let responseError = false
const responseStream = got.stream(url, { headers })
const responseStream = got.stream(url, headers)
responseStream.pipe(fs.createWriteStream(tmpFilename))
responseStream.on(`downloadProgress`, pro => console.log(pro))

Expand Down

0 comments on commit 10c27c4

Please sign in to comment.