|
61 | 61 | var uri = _self.api + "users/" + _self.user.login + "/repos?callback=?";
|
62 | 62 | _console.log("fetching: " + uri);
|
63 | 63 | return $.getJSON(uri, function(response) {
|
| 64 | + checkRateLimit(response.meta); |
64 | 65 | _self.repos = response.data;
|
65 | 66 | callback();
|
66 | 67 | });
|
|
73 | 74 | var uri = _self.api + "users/" + user + "?callback=?";
|
74 | 75 | _console.log("fetching: " + uri);
|
75 | 76 | return $.getJSON(uri, function(response) {
|
| 77 | + checkRateLimit(response.meta); |
76 | 78 | _self.user = response.data;
|
77 | 79 | getRepos(function() {
|
78 | 80 | setRepo(repo, function() {
|
|
82 | 84 | });
|
83 | 85 | }
|
84 | 86 |
|
| 87 | + function checkRateLimit(meta) { |
| 88 | + _console.log(response.meta); |
| 89 | + if(response.meta["X-RateLimit-Remaining"] == 0) { |
| 90 | + alert("Whoops, you've hit the github rate limit. You'll need to authenticate to continue"); |
| 91 | + } |
| 92 | + _shell.deactivate(); |
| 93 | + } |
| 94 | + |
85 | 95 | function getDir(path, callback) {
|
86 |
| - var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?ref=" + _self.branch + "&callback=?"; |
| 96 | + if(path && path.length > 1 && path[path.length-1] === '/') { |
| 97 | + path = path.substr(0,path.length-1); |
| 98 | + } |
| 99 | + var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?callback=?"; |
| 100 | + //var uri = _self.api + "repos/" + _self.user.login + "/" + _self.repo.name + "/contents" + path + "?ref=" + _self.branch + "&callback=?"; |
87 | 101 | _console.log("fetching: " + uri);
|
88 | 102 | $.getJSON(uri, function(response) {
|
| 103 | + checkRateLimit(response.meta); |
89 | 104 | if(Object.prototype.toString.call(response.data) !== '[object Array]') {
|
| 105 | + _console.log("path '" + path + "' was a file"); |
90 | 106 | return callback();
|
91 | 107 | }
|
92 | 108 | var node = {
|
|
96 | 112 | path: path,
|
97 | 113 | children: response.data
|
98 | 114 | };
|
| 115 | + _console.log("got node at: " + node.path); |
99 | 116 | return callback(node);
|
100 | 117 | });
|
101 | 118 | }
|
|
126 | 143 | return _.map(children, function(node) {
|
127 | 144 | return {
|
128 | 145 | name: node.name,
|
129 |
| - path: node.path, |
| 146 | + path: "/" + node.path, |
130 | 147 | isFile: node.type === 'file'
|
131 | 148 | };
|
132 | 149 | });
|
|
141 | 158 | if(!path) {
|
142 | 159 | return callback(_pathhandler.current);
|
143 | 160 | }
|
144 |
| - return getDir(path, function(node) { |
145 |
| - callback(node); |
146 |
| - }) |
| 161 | + var parts = _.filter(path.split("/"), function(x) { |
| 162 | + return x; |
| 163 | + }); |
| 164 | + _console.log(parts); |
| 165 | + if(parts[0] === "..") { |
| 166 | + _console.log("looking for parent relative"); |
| 167 | + var parentParts = _.filter(_pathhandler.current.path.split("/"), function(x) { |
| 168 | + return x; |
| 169 | + }); |
| 170 | + if(parentParts.length == 0) { |
| 171 | + return callback(_pathhandler.current); |
| 172 | + } |
| 173 | + path = "/" + parentParts.slice(0, parentParts.length - 1).join('/') + "/" + parts.slice(1).join("/"); |
| 174 | + } else if(path[0] !== '/') { |
| 175 | + _console.log("looking for current relative"); |
| 176 | + if(_pathhandler.current.path === '/') { |
| 177 | + path = '/' + path; |
| 178 | + } else { |
| 179 | + path = _pathhandler.current.path + "/" + path; |
| 180 | + } |
| 181 | + } |
| 182 | + _console.log("path to fetch: " + path); |
| 183 | + return getDir(path, callback); |
147 | 184 | };
|
148 | 185 | _pathhandler.getChildNodes = function(node, callback) {
|
149 | 186 | if(node.isfile) {
|
|
0 commit comments