Fix thumbs for new uploads to private repos

This commit is contained in:
Luís Miguel 2018-03-23 14:51:15 +00:00 committed by Shawn Erquhart
parent 2d89cc7bfe
commit 2475af1870
2 changed files with 17 additions and 1 deletions

View File

@ -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",

View File

@ -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) {