24
1
Fork 0

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 conf = convict({
bitly_key: {
format: String,
default: 'localhost',
env: 'P2P_BITLY_KEY'
},
s3_bucket: {
format: String,
default: 'localhost',
@ -47,5 +42,4 @@ module.exports = props;
module.exports.notLocalHost =
props.env === 'production' &&
props.s3_bucket !== 'localhost' &&
props.bitly_key !== 'localhost';
props.s3_bucket !== 'localhost';

View File

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

View File

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