Implemented multi-file upload/download

This commit is contained in:
Danny Coates 2018-07-25 22:26:11 -07:00
parent b2aed06328
commit 7bf104960e
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
18 changed files with 475 additions and 183 deletions

View file

@ -4,6 +4,7 @@ import OwnedFile from './ownedFile';
import Keychain from './keychain';
import { arrayToB64, bytes } from './utils';
import { uploadWs } from './api';
import { encryptedSize } from './ece';
export default class FileSender extends Nanobus {
constructor(file) {
@ -64,21 +65,15 @@ export default class FileSender extends Nanobus {
}
this.msg = 'encryptingFile';
this.emit('encrypting');
const enc = await this.keychain.encryptStream(this.file);
const totalSize = encryptedSize(this.file.size);
const encStream = await this.keychain.encryptStream(this.file.stream);
const metadata = await this.keychain.encryptMetadata(this.file);
const authKeyB64 = await this.keychain.authKeyB64();
this.uploadRequest = uploadWs(
enc.stream,
enc.streamInfo,
metadata,
authKeyB64,
p => {
this.progress = p;
this.emit('progress');
}
);
this.uploadRequest = uploadWs(encStream, metadata, authKeyB64, p => {
this.progress = [p, totalSize];
this.emit('progress');
});
if (this.cancelled) {
throw new Error(0);