diff --git a/app/fileManager.js b/app/fileManager.js index 9be93215..b9161502 100644 --- a/app/fileManager.js +++ b/app/fileManager.js @@ -98,7 +98,7 @@ export default function(state, emitter) { await delay(200); try { metrics.startedUpload({ size, type }); - const ownedFile = await sender.upload(state.storage); + const ownedFile = await sender.upload(); state.storage.totalUploads += 1; metrics.completedUpload(ownedFile); diff --git a/app/fileSender.js b/app/fileSender.js index fd6465c1..5b1f356c 100644 --- a/app/fileSender.js +++ b/app/fileSender.js @@ -49,7 +49,7 @@ export default class FileSender extends Nanobus { }); } - async upload(storage) { + async upload() { const start = Date.now(); const plaintext = await this.readFile(); if (this.cancelled) { @@ -81,23 +81,20 @@ export default class FileSender extends Nanobus { this.uploadRequest = null; this.progress = [1, 1]; const secretKey = arrayToB64(this.keychain.rawSecret); - const ownedFile = new OwnedFile( - { - id: result.id, - url: `${result.url}#${secretKey}`, - name: this.file.name, - size: this.file.size, - type: this.file.type, //TODO 'click' ? - time: time, - speed: this.file.size / (time / 1000), - createdAt: Date.now(), - expiresAt: Date.now() + EXPIRE_SECONDS * 1000, - secretKey: secretKey, - nonce: this.keychain.nonce, - ownerToken: result.ownerToken - }, - storage - ); + const ownedFile = new OwnedFile({ + id: result.id, + url: `${result.url}#${secretKey}`, + name: this.file.name, + size: this.file.size, + type: this.file.type, //TODO 'click' ? + time: time, + speed: this.file.size / (time / 1000), + createdAt: Date.now(), + expiresAt: Date.now() + EXPIRE_SECONDS * 1000, + secretKey: secretKey, + nonce: this.keychain.nonce, + ownerToken: result.ownerToken + }); return ownedFile; } catch (e) { this.msg = 'errorPageHeader'; diff --git a/app/keychain.js b/app/keychain.js index cfd7a331..eacffec3 100644 --- a/app/keychain.js +++ b/app/keychain.js @@ -1,12 +1,10 @@ -import Nanobus from 'nanobus'; import { arrayToB64, b64ToArray } from './utils'; const encoder = new TextEncoder(); const decoder = new TextDecoder(); -export default class Keychain extends Nanobus { +export default class Keychain { constructor(secretKeyB64, nonce, ivB64) { - super('Keychain'); this._nonce = nonce || 'yRCdyQ1EMSA3mo4rqSkuNQ=='; if (ivB64) { this.iv = b64ToArray(ivB64); @@ -85,7 +83,6 @@ export default class Keychain extends Nanobus { set nonce(n) { if (n && n !== this._nonce) { this._nonce = n; - this.emit('nonceChanged'); } } diff --git a/app/ownedFile.js b/app/ownedFile.js index ca41fd0a..307621f1 100644 --- a/app/ownedFile.js +++ b/app/ownedFile.js @@ -3,7 +3,7 @@ import { arrayToB64 } from './utils'; import { del, fileInfo, setParams, setPassword } from './api'; export default class OwnedFile { - constructor(obj, storage) { + constructor(obj) { this.id = obj.id; this.url = obj.url; this.name = obj.name; @@ -16,8 +16,7 @@ export default class OwnedFile { this.ownerToken = obj.ownerToken; this.dlimit = obj.dlimit || 1; this.dtotal = obj.dtotal || 0; - this.keychain = new Keychain(obj.secretKey, obj.nonce); - this.keychain.on('nonceChanged', () => storage.writeFile(this)); + this.keychain = new Keychain(obj.secretKey); this._hasPassword = !!obj.hasPassword; } @@ -69,7 +68,6 @@ export default class OwnedFile { createdAt: this.createdAt, expiresAt: this.expiresAt, secretKey: arrayToB64(this.keychain.rawSecret), - nonce: this.keychain.nonce, ownerToken: this.ownerToken, dlimit: this.dlimit, dtotal: this.dtotal, diff --git a/app/storage.js b/app/storage.js index 64d591fc..e33e449b 100644 --- a/app/storage.js +++ b/app/storage.js @@ -43,7 +43,7 @@ class Storage { const k = this.engine.key(i); if (isFile(k)) { try { - const f = new OwnedFile(JSON.parse(this.engine.getItem(k)), this); + const f = new OwnedFile(JSON.parse(this.engine.getItem(k))); if (!f.id) { f.id = f.fileId; }