Skip to content

Commit

Permalink
Fix #5 about use access token on Headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
KinoLien committed Feb 6, 2020
1 parent 33ec2d0 commit 2fe9cbc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions js/content/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var zipContents = function(filename, contents){
});
};

function callAjax(url){
function callAjax(url, token){
return new Promise(function(resolve, reject){
var xmlhttp;
// compatible with IE7+, Firefox, Chrome, Opera, Safari
Expand All @@ -73,6 +73,7 @@ function callAjax(url){
};
xmlhttp.responseType = "json";
xmlhttp.open("GET", url, true);
if ( token ) xmlhttp.setRequestHeader("Authorization", "token " + token);
xmlhttp.send();
});
}
Expand Down Expand Up @@ -200,8 +201,8 @@ var Pool = {
.then(function(key){
currentKey = key || "";
var promises = treeAjaxItems.map(function(item){
var fetchedUrl = item.url + "?recursive=1" + (currentKey? ("&access_token=" + currentKey) : "");
return callAjax(fetchedUrl).then(function(treeRes){
var fetchedUrl = item.url + "?recursive=1";
return callAjax(fetchedUrl, currentKey).then(function(treeRes){
treeRes.tree.forEach(function(blobItem){
if(blobItem.type == "blob"){
var path = item.title + "/" + blobItem.path;
Expand All @@ -216,8 +217,8 @@ var Pool = {
.then(function(){
self.log("Collect blob contents...");
var promises = blobAjaxCollection.map(function(item){
var fetchedUrl = item.blobUrl + (currentKey? ("?access_token=" + currentKey) : "");
return callAjax(fetchedUrl).then(function(blobRes){
var fetchedUrl = item.blobUrl;
return callAjax(fetchedUrl, currentKey).then(function(blobRes){
fileContents.push({ path: item.path, content: blobRes.content });
self.log(item.path + " content has collected.");
});
Expand Down

0 comments on commit 2fe9cbc

Please sign in to comment.