Skip to content

Commit da49fff

Browse files
authored
Switch to *request* dep (OpenUserJS#1332)
* Covers redirection automatically * Fix undocumented type of `jpg` for `jpeg` *(my gravatar for example)* * Left a response handler in there because **undoubtedly** there's going to be an issue cropping up with something in that arena * Found an inline dependency to deal with later when more time available... added TODO * `Buffer` method utilized is deprecated for base64 will affect repoManager... more TODO later NOTE: * I'm extremely short on time at the moment so thanks to everyone helping out with issues Post OpenUserJS#1303 and should close OpenUserJS#1331 Auto-merge
1 parent be33f4e commit da49fff

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

controllers/scriptStorage.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ var fs = require('fs');
1313
var util = require('util');
1414
var _ = require('underscore');
1515
var URL = require('url');
16-
var http = require('http');
17-
var https = require('https');
16+
var request = require('request');
1817
var crypto = require('crypto');
1918
var stream = require('stream');
2019
var peg = require('pegjs');
@@ -127,7 +126,7 @@ if (isPro) {
127126
secretAccessKey: 'fakeKey',
128127
httpOptions: {
129128
proxy: DEV_AWS_URL,
130-
agent: require('http').globalAgent
129+
agent: require('http').globalAgent // TODO: Move this up eventually
131130
}
132131
});
133132
}
@@ -1391,6 +1390,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
13911390
var matches = null;
13921391
var data = null;
13931392
var rDataURIbase64 = /^data:image\/.+;base64,(.*)$/;
1393+
var req = null;
1394+
var chunks = null;
13941395

13951396
function acceptedImage(aDimensions) {
13961397
var maxX = 256; //px
@@ -1399,6 +1400,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
13991400
switch (aDimensions.type) {
14001401
case 'gif':
14011402
// fallthrough
1403+
case 'jpg':
1404+
// fallthrough
14021405
case 'jpeg':
14031406
// fallthrough
14041407
case 'png':
@@ -1464,17 +1467,24 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14641467
}), null);
14651468
}
14661469
} else {
1467-
fn = /^http:/.test(icon) ? http : https;
1468-
fn.get(URL.parse(icon), function (aRes) {
1469-
var chunks = [];
1470-
aRes.on('data', function (aChunk) {
1470+
chunks = [];
1471+
req = request.get(icon)
1472+
.on('response', function (aRes) {
1473+
// TODO: Probably going to be something here
1474+
})
1475+
.on('error', function (aErr) {
1476+
aInnerCallback(aErr);
1477+
})
1478+
.on('data', function (aChunk) {
14711479
var buf = null;
1480+
14721481
chunks.push(aChunk);
14731482
buf = Buffer.concat(chunks);
14741483
if (buf.length > 3048) {
1475-
aRes.destroy();
1484+
req.abort();
14761485
}
1477-
}).on('end', function () {
1486+
})
1487+
.on('end', function () {
14781488
buffer = Buffer.concat(chunks);
14791489

14801490
if (buffer.length <= 0) {
@@ -1503,12 +1513,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
15031513
} else {
15041514
aInnerCallback(null);
15051515
}
1506-
}).on('error', function (aErr) { // NOTE: response error trap
1507-
aInnerCallback(aErr);
15081516
});
1509-
}).on('error', function (aErr) { // NOTE: request error trap
1510-
aInnerCallback(aErr);
1511-
});
15121517
}
15131518
} else {
15141519
aInnerCallback(null);

0 commit comments

Comments
 (0)