Skip to content

Commit 85c81c1

Browse files
committed
Use RAW MIME type for blobs to overcome Base64 decoding issues.
1 parent a500fc6 commit 85c81c1

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

github.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Github.js 0.5.0
1+
// Github.js 0.5.1
22
// (c) 2012 Michael Aufreiter, Development Seed
33
// Github.js is freely distributable under the MIT license.
44
// For all details and documentation:
@@ -13,13 +13,13 @@
1313
// Util
1414
// =======
1515

16-
function _request(method, path, data, cb) {
17-
function headers() {
18-
return options.auth == 'oauth'
19-
? { Authorization: 'Token '+ options.token }
20-
: { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password) }
21-
}
16+
function headers() {
17+
return options.auth == 'oauth'
18+
? { Authorization: 'token '+ options.token, Accept: 'application/vnd.github.raw' }
19+
: { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password) }
20+
}
2221

22+
function _request(method, path, data, cb) {
2323
$.ajax({
2424
type: method,
2525
url: API_URL + path,
@@ -32,6 +32,18 @@
3232
});
3333
}
3434

35+
function _raw_request(method, path, data, cb) {
36+
$.ajax({
37+
type: method,
38+
url: API_URL + path,
39+
data: JSON.stringify(data),
40+
contentType: 'application/x-www-form-urlencoded',
41+
success: function(res) { cb(null, res); },
42+
error: function(err) { cb(err); },
43+
headers : headers()
44+
});
45+
}
46+
3547
// USER API
3648
// =======
3749

@@ -78,7 +90,7 @@
7890
// -------
7991

8092
this.getBlob = function(sha, cb) {
81-
_request("GET", repoPath + "/git/blobs/" + sha, null, function(err, res) {
93+
_raw_request("GET", repoPath + "/git/blobs/" + sha, null, function(err, res) {
8294
cb(err, res);
8395
});
8496
};
@@ -199,19 +211,7 @@
199211
that.getSha(branch, path, function(err, sha) {
200212
if (!sha) return cb("not found", null);
201213

202-
that.getBlob(sha, function(err, blob) {
203-
function decode(blob) {
204-
if (blob.content) {
205-
var data = blob.encoding == 'base64' ?
206-
atob(blob.content.replace(/\s/g, '')) :
207-
blob.content;
208-
return data;
209-
} else {
210-
return "";
211-
}
212-
}
213-
cb(null, decode(blob));
214-
});
214+
that.getBlob(sha, cb);
215215
});
216216
};
217217

0 commit comments

Comments
 (0)