Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix thumbs for new uploads to private repos #994

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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