Fix thumbs for new uploads to private repos
This commit is contained in:
parent
2d89cc7bfe
commit
2475af1870
@ -30,6 +30,11 @@ export default class API {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isPrivateRepo() {
|
||||||
|
return this.request(this.repoURL)
|
||||||
|
.then(repo => repo.private);
|
||||||
|
}
|
||||||
|
|
||||||
requestHeaders(headers = {}) {
|
requestHeaders(headers = {}) {
|
||||||
const baseHeader = {
|
const baseHeader = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -136,7 +136,18 @@ export default class GitHub {
|
|||||||
const response = await this.api.persistFiles(null, [mediaFile], options);
|
const response = await this.api.persistFiles(null, [mediaFile], options);
|
||||||
const repo = this.repo || this.getRepoFromResponseUrl(response.url);
|
const repo = this.repo || this.getRepoFromResponseUrl(response.url);
|
||||||
const { value, size, path, fileObj } = mediaFile;
|
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, '/') };
|
return { id: mediaFile.sha, name: value, size: fileObj.size, url, path: trimStart(path, '/') };
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user