Merge branch 'master' into cross-env-dep

This commit is contained in:
Danny Coates 2017-06-22 15:54:11 -07:00 committed by GitHub
commit 5a1602a479
3 changed files with 6 additions and 33 deletions

View file

@ -1,11 +1,6 @@
const convict = require('convict'); const convict = require('convict');
const conf = convict({ const conf = convict({
bitly_key: {
format: String,
default: 'localhost',
env: 'P2P_BITLY_KEY'
},
s3_bucket: { s3_bucket: {
format: String, format: String,
default: 'localhost', default: 'localhost',
@ -47,5 +42,4 @@ module.exports = props;
module.exports.notLocalHost = module.exports.notLocalHost =
props.env === 'production' && props.env === 'production' &&
props.s3_bucket !== 'localhost' && props.s3_bucket !== 'localhost';
props.bitly_key !== 'localhost';

View file

@ -4,7 +4,6 @@ const s3 = new AWS.S3();
const conf = require('./config.js'); const conf = require('./config.js');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const fetch = require('node-fetch');
const crypto = require('crypto'); const crypto = require('crypto');
const notLocalHost = conf.notLocalHost; const notLocalHost = conf.notLocalHost;
@ -170,29 +169,10 @@ function awsSet(id, file, filename, url) {
redis_client.expire(id, 86400000); redis_client.expire(id, 86400000);
log.info('awsUploadFinish', 'Upload Finished of ' + filename); log.info('awsUploadFinish', 'Upload Finished of ' + filename);
if (conf.bitly_key) { resolve({
fetch( uuid: uuid,
'https://api-ssl.bitly.com/v3/shorten?access_token=' + url: url
conf.bitly_key + });
'&longUrl=' +
encodeURIComponent(url) +
'&format=txt'
)
.then(res => {
return res.text();
})
.then(body => {
resolve({
uuid: uuid,
url: body
});
});
} else {
resolve({
uuid: uuid,
url: url
});
}
} }
}); });
}); });

View file

@ -107,8 +107,7 @@ describe('Testing Set using aws', function() {
crypto.randomBytes.restore(); crypto.randomBytes.restore();
}); });
it('Should pass when the file is successfully uploaded and no bitly key', function() { it('Should pass when the file is successfully uploaded', function() {
conf.bitly_key = null;
const buf = Buffer.alloc(10); const buf = Buffer.alloc(10);
sinon.stub(crypto, 'randomBytes').returns(buf); sinon.stub(crypto, 'randomBytes').returns(buf);
s3Stub.upload.callsArgWith(1, null, {}); s3Stub.upload.callsArgWith(1, null, {});