fixing small issues

This commit is contained in:
Abhinav Adduri 2017-07-10 12:45:20 -07:00
parent c4b7a2bd97
commit 6aa79472bf
6 changed files with 10 additions and 14 deletions

View File

@ -4,7 +4,6 @@ const { hexToArray } = require('./utils');
class FileReceiver extends EventEmitter { class FileReceiver extends EventEmitter {
constructor() { constructor() {
super(); super();
this.salt = hexToArray(location.pathname.slice(10, -1));
} }
download() { download() {
@ -37,7 +36,7 @@ class FileReceiver extends EventEmitter {
data: this.result, data: this.result,
aad: meta.aad, aad: meta.aad,
filename: meta.filename, filename: meta.filename,
iv: meta.iv iv: meta.id
}); });
}; };

View File

@ -72,8 +72,7 @@ class FileSender extends EventEmitter {
}, },
secretKey, secretKey,
file.plaintext file.plaintext
) ),
.catch(err => console.log('Error with encrypting.')),
window.crypto.subtle.exportKey('jwk', secretKey), window.crypto.subtle.exportKey('jwk', secretKey),
new Promise((resolve, reject) => { resolve(file.hash) }) new Promise((resolve, reject) => { resolve(file.hash) })
]); ]);
@ -114,7 +113,7 @@ class FileSender extends EventEmitter {
'X-File-Metadata', 'X-File-Metadata',
JSON.stringify({ JSON.stringify({
aad: arrayToHex(hash), aad: arrayToHex(hash),
iv: fileId, id: fileId,
filename: file.name filename: file.name
}) })
); );

View File

@ -147,7 +147,7 @@ app.post('/upload', (req, res, next) => {
req.busboy.on('file', (fieldname, file, filename) => { req.busboy.on('file', (fieldname, file, filename) => {
log.info('Uploading:', newId); log.info('Uploading:', newId);
storage.set(meta.iv, newId, file, filename, meta).then(() => { storage.set(newId, file, filename, meta).then(() => {
const protocol = conf.env === 'production' ? 'https' : req.protocol; const protocol = conf.env === 'production' ? 'https' : req.protocol;
const url = `${protocol}://${req.get('host')}/download/${newId}/`; const url = `${protocol}://${req.get('host')}/download/${newId}/`;
res.json({ res.json({

View File

@ -115,14 +115,13 @@ function localGet(id) {
return fs.createReadStream(path.join(__dirname, '../static', id)); return fs.createReadStream(path.join(__dirname, '../static', id));
} }
function localSet(id, newId, file, filename, meta) { function localSet(newId, file, filename, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const fstream = fs.createWriteStream(path.join(__dirname, '../static', newId)); const fstream = fs.createWriteStream(path.join(__dirname, '../static', newId));
file.pipe(fstream); file.pipe(fstream);
fstream.on('close', () => { fstream.on('close', () => {
meta.id = id;
redis_client.hmset(newId, meta); redis_client.hmset(newId, meta);
redis_client.expire(id, 86400000); redis_client.expire(newId, 86400000);
log.info('localSet:', 'Upload Finished of ' + newId); log.info('localSet:', 'Upload Finished of ' + newId);
resolve(meta.delete); resolve(meta.delete);
}); });
@ -192,7 +191,7 @@ function awsGet(id) {
} }
} }
function awsSet(id, newId, file, filename, meta) { function awsSet(newId, file, filename, meta) {
const params = { const params = {
Bucket: conf.s3_bucket, Bucket: conf.s3_bucket,
Key: newId, Key: newId,
@ -205,10 +204,9 @@ function awsSet(id, newId, file, filename, meta) {
log.info('awsUploadError:', err.stack); // an error occurred log.info('awsUploadError:', err.stack); // an error occurred
reject(); reject();
} else { } else {
meta.id = id;
redis_client.hmset(newId, meta); redis_client.hmset(newId, meta);
redis_client.expire(id, 86400000); redis_client.expire(newId, 86400000);
log.info('awsUploadFinish', 'Upload Finished of ' + filename); log.info('awsUploadFinish', 'Upload Finished of ' + filename);
resolve(meta.delete); resolve(meta.delete);
} }

View File

@ -112,7 +112,7 @@ describe('Testing Set using aws', function() {
sinon.stub(crypto, 'randomBytes').returns(buf); sinon.stub(crypto, 'randomBytes').returns(buf);
s3Stub.upload.callsArgWith(1, null, {}); s3Stub.upload.callsArgWith(1, null, {});
return storage return storage
.set('123', '123', {}, 'Filename.moz', {}) .set('123', {}, 'Filename.moz', {})
.then(() => { .then(() => {
assert(expire.calledOnce); assert(expire.calledOnce);
assert(expire.calledWith('123', 86400000)); assert(expire.calledWith('123', 86400000));

View File

@ -122,7 +122,7 @@ describe('Testing Set to local filesystem', function() {
fsStub.createWriteStream.returns({ on: stub }); fsStub.createWriteStream.returns({ on: stub });
return storage return storage
.set('test', 'test', { pipe: sinon.stub() }, 'Filename.moz', {}) .set('test', { pipe: sinon.stub() }, 'Filename.moz', {})
.then(() => { .then(() => {
assert(1); assert(1);
}) })