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 jastack committed Jan 24, 2018
1 parent 925e6d6 commit 8ac5f18
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Today, the team and the city scored a huge victory when Amazon announced that Bo

![Amazon Boston homepage](./amazon-boston.jpg "Boston city")

When Amazon announced in September that it was looking to build a new headquarters, bringing 50,000 jobs and billions of investment to the chosen city, Boston’s city government jumped to throw their hat in the ring.
When Amazon announced in September that it was looking to build a new headquarters, bringing 50,000 jobs and billions of investment to the chosen city, Boston’s city government jumped to throw their hat in the ring.

As a technology hub, the city wanted to put their best digital foot forward, so they turned to the Boston.gov team to build a website as the city’s application — [amazon.boston.gov](http://amazon.boston.gov) .

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/building-apps-with-gatsby.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Building apps with Gatsby"
---

Gatsby can be used to create fully dynamic apps. The default Gatsby app is made up of statically rendered pages. On this foundation, you can build what we call "hybrid" sites which adds dynamically rendered sections of pages and if needed, client-only routes.
Gatsby can be used to create fully dynamic apps. The default Gatsby app is made up of statically rendered pages. On this foundation, you can build what we call "hybrid" sites which adds dynamically rendered sections of pages and if needed, client-only routes.

## Statically rendered pages

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/gatsby-starters.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Community:
* Basic components: SiteNavi, SitePost, SitePage

* [gatsby-blog-starter-kit](https://github.com/dschau/gatsby-blog-starter-kit)
[(demo)](https://dschau.github.io/gatsby-blog-starter-kit/)
[(demo)](https://dschau.github.io/gatsby-blog-starter-kit/)

Features:

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/querying-with-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ the browser when needed by your components.
## Why is GraphQL so cool?

* Eliminate frontend data boilerplate — no need to worry about requesting & waiting for data. Just ask for the data you need with a GraphQL query and it'll show up when you need it
* Push frontend complexity into queries — many data transformations can be done at *build-time* within your GraphQL queries
* Push frontend complexity into queries — many data transformations can be done at _build-time_ within your GraphQL queries
* It's the perfect data querying language for the often complex/nested data dependencies of modern applications
* Improve performance by removing data bloat — GraphQL is a big part of why Gatsby is so fast as it enables lazy-loading the exact data in the exact form each view needs

Expand Down
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
1 change: 1 addition & 0 deletions packages/gatsby-source-wordpress/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ exports.sourceNodes = async (
store,
cache,
createNode,
_auth,
})

// Search and replace Content Urls
Expand Down
9 changes: 8 additions & 1 deletion packages/gatsby-source-wordpress/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,13 @@ exports.mapEntitiesToMedia = entities => {
}

// Downloads media files and removes "sizes" data as useless in Gatsby context.
exports.downloadMediaFiles = async ({ entities, store, cache, createNode }) =>
exports.downloadMediaFiles = async ({
entities,
store,
cache,
createNode,
_auth,
}) =>
Promise.all(
entities.map(async e => {
let fileNode
Expand All @@ -401,6 +407,7 @@ exports.downloadMediaFiles = async ({ entities, store, cache, createNode }) =>
store,
cache,
createNode,
_auth,
})
} catch (e) {
// Ignore
Expand Down
7 changes: 5 additions & 2 deletions www/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class HTML extends React.Component {
href={`/safari-pinned-tab.svg`}
color="#5bbad5"
/>
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js" />
{css}
</head>
<body {...this.props.bodyAttributes}>
Expand All @@ -81,7 +81,10 @@ export default class HTML extends React.Component {
dangerouslySetInnerHTML={{ __html: this.props.body }}
/>
{this.props.postBodyComponents}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css"
/>
</body>
</html>
)
Expand Down

0 comments on commit 8ac5f18

Please sign in to comment.