Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken new media uploads in Git Gateway. #1221

Merged
merged 5 commits into from
Apr 4, 2018

Conversation

tech4him1
Copy link
Contributor

@tech4him1 tech4him1 commented Apr 3, 2018

- Summary

New media uploads do not appear at all until the CMS is reloaded (not the thumbnail or filename) when using the Git Gateway backend after #994. This PR resolves #1220.

- Test plan

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@verythorough
Copy link
Contributor

verythorough commented Apr 3, 2018

Deploy preview for cms-demo ready!

Built with commit e806679

https://deploy-preview-1221--cms-demo.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Apr 3, 2018

Deploy preview for netlify-cms-www ready!

Built with commit e806679

https://deploy-preview-1221--netlify-cms-www.netlify.com

const isPrivateRepo = await this.api.isPrivateRepo();
if (isPrivateRepo) {
if (!this.isPrivateRepo) {
this.isPrivateRepo = await this.api.checkPrivateRepo(`${this.api_root}/repos/${repo}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is cached here since GitHub limits unauthenticated API requests. The only downside is that you need to reload the CMS page if you change the repo from public to private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a fine compromise.

checkPrivateRepo(url) {
const cacheBuster = new Date().getTime();
return fetch(`${url}?ts=${cacheBuster}`)
.then(response => response.ok);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to check if we get a 403 (rate limited) error here, and assume that the repo is private in that case so that thumbnails don't break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

@tech4him1 tech4him1 changed the title WIP: Fix broken new media uploads in Git Gateway. Fix broken new media uploads in Git Gateway. Apr 3, 2018
Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides my one change request, this solution works if we're okay with using unauthenticated requests. I'd really rather not, but I haven't looked into what other options we have. I'll do so now.

@@ -139,8 +139,10 @@ export default class GitHub {
let url = `https://raw.githubusercontent.com/${repo}/${this.branch}${path}`;

// Assets uploaded to private repos will need valid access tokens.
const isPrivateRepo = await this.api.isPrivateRepo();
if (isPrivateRepo) {
if (!this.isPrivateRepo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition would result in an unauthenticated check on every persist for public repos, maybe we should check for the presence of a Boolean instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thank you!

@tech4him1
Copy link
Contributor Author

@erquhart Great, thank you.

@erquhart
Copy link
Contributor

erquhart commented Apr 3, 2018

As bad of a solution as it is, it may be better to always treat Git Gateway repos as private until #990 is in place.

@tech4him1
Copy link
Contributor Author

@erquhart I've created an alternative PR with that fix (#1223). Is that your preferred solution for now?

@tech4him1 tech4him1 requested a review from erquhart April 3, 2018 22:10
@tech4him1
Copy link
Contributor Author

tech4him1 commented Apr 3, 2018

I've updated the PR to use the file contents directly (as a Blob URL) when new media is uploaded. This prevents us from having to infer the GitHub URL. Once the CMS is reloaded, the GitHub URL will be fetched automatically. This is not dependent on deploys at all, since it depends on the repo directly, instead of the website.

It works perfectly for me using GitHub and Git-Gateway backends with a public repo. @erquhart Can you test on a private repo?

@erquhart erquhart merged commit 5e040ee into master Apr 4, 2018
@erquhart erquhart deleted the 1220-git-gateway-uploads branch April 4, 2018 18:30
brianlmacdonald pushed a commit to brianlmacdonald/netlify-cms that referenced this pull request May 23, 2018
* Use file data instead of inferring path for new uploads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Image card with thumbnails not showing after upload
3 participants