fixing small issues
This commit is contained in:
parent
c4b7a2bd97
commit
6aa79472bf
|
@ -4,7 +4,6 @@ const { hexToArray } = require('./utils');
|
|||
class FileReceiver extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.salt = hexToArray(location.pathname.slice(10, -1));
|
||||
}
|
||||
|
||||
download() {
|
||||
|
@ -37,7 +36,7 @@ class FileReceiver extends EventEmitter {
|
|||
data: this.result,
|
||||
aad: meta.aad,
|
||||
filename: meta.filename,
|
||||
iv: meta.iv
|
||||
iv: meta.id
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -72,8 +72,7 @@ class FileSender extends EventEmitter {
|
|||
},
|
||||
secretKey,
|
||||
file.plaintext
|
||||
)
|
||||
.catch(err => console.log('Error with encrypting.')),
|
||||
),
|
||||
window.crypto.subtle.exportKey('jwk', secretKey),
|
||||
new Promise((resolve, reject) => { resolve(file.hash) })
|
||||
]);
|
||||
|
@ -114,7 +113,7 @@ class FileSender extends EventEmitter {
|
|||
'X-File-Metadata',
|
||||
JSON.stringify({
|
||||
aad: arrayToHex(hash),
|
||||
iv: fileId,
|
||||
id: fileId,
|
||||
filename: file.name
|
||||
})
|
||||
);
|
||||
|
|
|
@ -147,7 +147,7 @@ app.post('/upload', (req, res, next) => {
|
|||
req.busboy.on('file', (fieldname, file, filename) => {
|
||||
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 url = `${protocol}://${req.get('host')}/download/${newId}/`;
|
||||
res.json({
|
||||
|
|
|
@ -115,14 +115,13 @@ function localGet(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) => {
|
||||
const fstream = fs.createWriteStream(path.join(__dirname, '../static', newId));
|
||||
file.pipe(fstream);
|
||||
fstream.on('close', () => {
|
||||
meta.id = id;
|
||||
redis_client.hmset(newId, meta);
|
||||
redis_client.expire(id, 86400000);
|
||||
redis_client.expire(newId, 86400000);
|
||||
log.info('localSet:', 'Upload Finished of ' + newId);
|
||||
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 = {
|
||||
Bucket: conf.s3_bucket,
|
||||
Key: newId,
|
||||
|
@ -205,10 +204,9 @@ function awsSet(id, newId, file, filename, meta) {
|
|||
log.info('awsUploadError:', err.stack); // an error occurred
|
||||
reject();
|
||||
} else {
|
||||
meta.id = id;
|
||||
redis_client.hmset(newId, meta);
|
||||
|
||||
redis_client.expire(id, 86400000);
|
||||
redis_client.expire(newId, 86400000);
|
||||
log.info('awsUploadFinish', 'Upload Finished of ' + filename);
|
||||
resolve(meta.delete);
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ describe('Testing Set using aws', function() {
|
|||
sinon.stub(crypto, 'randomBytes').returns(buf);
|
||||
s3Stub.upload.callsArgWith(1, null, {});
|
||||
return storage
|
||||
.set('123', '123', {}, 'Filename.moz', {})
|
||||
.set('123', {}, 'Filename.moz', {})
|
||||
.then(() => {
|
||||
assert(expire.calledOnce);
|
||||
assert(expire.calledWith('123', 86400000));
|
||||
|
|
|
@ -122,7 +122,7 @@ describe('Testing Set to local filesystem', function() {
|
|||
fsStub.createWriteStream.returns({ on: stub });
|
||||
|
||||
return storage
|
||||
.set('test', 'test', { pipe: sinon.stub() }, 'Filename.moz', {})
|
||||
.set('test', { pipe: sinon.stub() }, 'Filename.moz', {})
|
||||
.then(() => {
|
||||
assert(1);
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue