Skip to content

Commit

Permalink
Fix thumbs for new uploads to private repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Quicksaver authored and erquhart committed Mar 27, 2018
1 parent 2d89cc7 commit 0d14076
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/backends/github/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export default class API {
});
}

isPrivateRepo() {
return this.request(this.repoURL)
.then(repo => repo.private);
}

requestHeaders(headers = {}) {
const baseHeader = {
"Content-Type": "application/json",
Expand Down
13 changes: 12 additions & 1 deletion src/backends/github/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,18 @@ export default class GitHub {
const response = await this.api.persistFiles(null, [mediaFile], options);
const repo = this.repo || this.getRepoFromResponseUrl(response.url);
const { value, size, path, fileObj } = mediaFile;
const url = `https://raw.githubusercontent.com/${repo}/${this.branch}${path}`;
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) {
const files = await this.api.listFiles(this.config.get('media_folder'));
const file = files.find(f => (f.sha === mediaFile.sha));
if (file) {
url = file.download_url;
}
}

return { id: mediaFile.sha, name: value, size: fileObj.size, url, path: trimStart(path, '/') };
}
catch(error) {
Expand Down

0 comments on commit 0d14076

Please sign in to comment.