format
This commit is contained in:
parent
05fe534e14
commit
67f586b65c
|
@ -1,8 +1,6 @@
|
|||
const EventEmitter = require('events');
|
||||
const { hexToArray } = require('./utils');
|
||||
|
||||
const Raven = window.Raven;
|
||||
|
||||
class FileReceiver extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -34,7 +32,7 @@ class FileReceiver extends EventEmitter {
|
|||
const blob = new Blob([this.response]);
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = function() {
|
||||
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'))
|
||||
const meta = JSON.parse(xhr.getResponseHeader('X-File-Metadata'));
|
||||
resolve({
|
||||
data: this.result,
|
||||
aad: meta.aad,
|
||||
|
|
|
@ -38,14 +38,18 @@ class FileSender extends EventEmitter {
|
|||
|
||||
upload() {
|
||||
return Promise.all([
|
||||
window.crypto.subtle.generateKey(
|
||||
window.crypto.subtle
|
||||
.generateKey(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
length: 128
|
||||
},
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
).catch(err => console.log('There was an error generating a crypto key')),
|
||||
)
|
||||
.catch(err =>
|
||||
console.log('There was an error generating a crypto key')
|
||||
),
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsArrayBuffer(this.file);
|
||||
|
@ -56,7 +60,8 @@ class FileSender extends EventEmitter {
|
|||
])
|
||||
.then(([secretKey, plaintext]) => {
|
||||
return Promise.all([
|
||||
window.crypto.subtle.encrypt(
|
||||
window.crypto.subtle
|
||||
.encrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv: this.iv,
|
||||
|
@ -64,7 +69,8 @@ class FileSender extends EventEmitter {
|
|||
},
|
||||
secretKey,
|
||||
plaintext
|
||||
).catch(err => console.log('Error with encrypting.')),
|
||||
)
|
||||
.catch(err => console.log('Error with encrypting.')),
|
||||
window.crypto.subtle.exportKey('jwk', secretKey)
|
||||
]);
|
||||
})
|
||||
|
@ -100,7 +106,14 @@ class FileSender extends EventEmitter {
|
|||
};
|
||||
|
||||
xhr.open('post', '/upload/' + fileId, true);
|
||||
xhr.setRequestHeader('X-File-Metadata', JSON.stringify({ aad: arrayToHex(this.aad), iv: fileId, filename: file.name }))
|
||||
xhr.setRequestHeader(
|
||||
'X-File-Metadata',
|
||||
JSON.stringify({
|
||||
aad: arrayToHex(this.aad),
|
||||
iv: fileId,
|
||||
filename: file.name
|
||||
})
|
||||
);
|
||||
xhr.send(fd);
|
||||
});
|
||||
})
|
||||
|
|
|
@ -20,7 +20,6 @@ function hexToArray(str) {
|
|||
return iv;
|
||||
}
|
||||
|
||||
|
||||
function notify(str) {
|
||||
if (!('Notification' in window)) {
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const conf = require('./config.js');
|
||||
|
||||
const isProduction = conf.env === 'production'
|
||||
const isProduction = conf.env === 'production';
|
||||
|
||||
const mozlog = require('mozlog')({
|
||||
app: 'FirefoxFileshare',
|
||||
|
|
|
@ -78,10 +78,10 @@ app.get('/assets/download/:id', (req, res) => {
|
|||
return;
|
||||
}
|
||||
|
||||
storage.metadata(id)
|
||||
storage
|
||||
.metadata(id)
|
||||
.then(meta => {
|
||||
storage.length(id).then(contentLength => {
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Disposition': 'attachment; filename=' + meta.filename,
|
||||
'Content-Type': 'application/octet-stream',
|
||||
|
@ -142,7 +142,7 @@ app.post('/upload/:id', (req, res, next) => {
|
|||
return;
|
||||
}
|
||||
const meta = JSON.parse(req.header('X-File-Metadata'));
|
||||
log.info('meta', meta)
|
||||
log.info('meta', meta);
|
||||
req.pipe(req.busboy);
|
||||
|
||||
req.busboy.on('file', (fieldname, file, filename) => {
|
||||
|
@ -157,8 +157,6 @@ app.post('/upload/:id', (req, res, next) => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
app.get('/__lbheartbeat__', (req, res) => {
|
||||
|
|
|
@ -58,8 +58,8 @@ function metadata(id) {
|
|||
} else {
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function filename(id) {
|
||||
|
@ -98,8 +98,8 @@ function aad(id) {
|
|||
} else {
|
||||
reject();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function localLength(id) {
|
||||
|
|
Loading…
Reference in New Issue