Skip to content

Commit

Permalink
Switch to *request* dep (#1332)
Browse files Browse the repository at this point in the history
* 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 #1303 and should close #1331

Auto-merge
  • Loading branch information
Martii committed Feb 23, 2018
1 parent be33f4e commit da49fff
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ var fs = require('fs');
var util = require('util');
var _ = require('underscore');
var URL = require('url');
var http = require('http');
var https = require('https');
var request = require('request');
var crypto = require('crypto');
var stream = require('stream');
var peg = require('pegjs');
Expand Down Expand Up @@ -127,7 +126,7 @@ if (isPro) {
secretAccessKey: 'fakeKey',
httpOptions: {
proxy: DEV_AWS_URL,
agent: require('http').globalAgent
agent: require('http').globalAgent // TODO: Move this up eventually
}
});
}
Expand Down Expand Up @@ -1391,6 +1390,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
var matches = null;
var data = null;
var rDataURIbase64 = /^data:image\/.+;base64,(.*)$/;
var req = null;
var chunks = null;

function acceptedImage(aDimensions) {
var maxX = 256; //px
Expand All @@ -1399,6 +1400,8 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
switch (aDimensions.type) {
case 'gif':
// fallthrough
case 'jpg':
// fallthrough
case 'jpeg':
// fallthrough
case 'png':
Expand Down Expand Up @@ -1464,17 +1467,24 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
}), null);
}
} else {
fn = /^http:/.test(icon) ? http : https;
fn.get(URL.parse(icon), function (aRes) {
var chunks = [];
aRes.on('data', function (aChunk) {
chunks = [];
req = request.get(icon)
.on('response', function (aRes) {
// TODO: Probably going to be something here
})
.on('error', function (aErr) {
aInnerCallback(aErr);
})
.on('data', function (aChunk) {
var buf = null;

chunks.push(aChunk);
buf = Buffer.concat(chunks);
if (buf.length > 3048) {
aRes.destroy();
req.abort();
}
}).on('end', function () {
})
.on('end', function () {
buffer = Buffer.concat(chunks);

if (buffer.length <= 0) {
Expand Down Expand Up @@ -1503,12 +1513,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
} else {
aInnerCallback(null);
}
}).on('error', function (aErr) { // NOTE: response error trap
aInnerCallback(aErr);
});
}).on('error', function (aErr) { // NOTE: request error trap
aInnerCallback(aErr);
});
}
} else {
aInnerCallback(null);
Expand Down

0 comments on commit da49fff

Please sign in to comment.