Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to *request* dep #1332

Merged
merged 1 commit into from
Feb 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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