fixed minor streaming nits
This commit is contained in:
parent
c157e4d31c
commit
a4cf46c0eb
11
app/api.js
11
app/api.js
|
@ -128,7 +128,6 @@ async function upload(
|
|||
streamInfo,
|
||||
metadata,
|
||||
verifierB64,
|
||||
keychain,
|
||||
onprogress,
|
||||
canceller
|
||||
) {
|
||||
|
@ -176,14 +175,7 @@ async function upload(
|
|||
}
|
||||
}
|
||||
|
||||
export function uploadWs(
|
||||
encrypted,
|
||||
info,
|
||||
metadata,
|
||||
verifierB64,
|
||||
keychain,
|
||||
onprogress
|
||||
) {
|
||||
export function uploadWs(encrypted, info, metadata, verifierB64, onprogress) {
|
||||
const canceller = { cancelled: false };
|
||||
|
||||
return {
|
||||
|
@ -195,7 +187,6 @@ export function uploadWs(
|
|||
info,
|
||||
metadata,
|
||||
verifierB64,
|
||||
keychain,
|
||||
onprogress,
|
||||
canceller
|
||||
)
|
||||
|
|
|
@ -53,7 +53,7 @@ export default class FileReceiver extends Nanobus {
|
|||
|
||||
async streamToArrayBuffer(stream, streamSize) {
|
||||
const reader = stream.getReader();
|
||||
const result = new Int8Array(streamSize);
|
||||
const result = new Uint8Array(streamSize);
|
||||
let offset = 0;
|
||||
|
||||
let state = await reader.read();
|
||||
|
|
|
@ -74,7 +74,6 @@ export default class FileSender extends Nanobus {
|
|||
enc.streamInfo,
|
||||
metadata,
|
||||
authKeyB64,
|
||||
this.keychain,
|
||||
p => {
|
||||
this.progress = p;
|
||||
this.emit('progress');
|
||||
|
|
|
@ -16,10 +16,8 @@ module.exports = async function(ws, req) {
|
|||
}
|
||||
});
|
||||
|
||||
let first = true;
|
||||
ws.on('message', async function(message) {
|
||||
ws.once('message', async function(message) {
|
||||
try {
|
||||
if (first) {
|
||||
const newId = crypto.randomBytes(5).toString('hex');
|
||||
const owner = crypto.randomBytes(10).toString('hex');
|
||||
|
||||
|
@ -33,7 +31,7 @@ module.exports = async function(ws, req) {
|
|||
error: 400
|
||||
})
|
||||
);
|
||||
ws.close();
|
||||
return ws.close();
|
||||
}
|
||||
|
||||
const meta = {
|
||||
|
@ -58,9 +56,6 @@ module.exports = async function(ws, req) {
|
|||
authentication: `send-v1 ${meta.nonce}`
|
||||
})
|
||||
);
|
||||
|
||||
first = false;
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('upload', e);
|
||||
ws.send(
|
||||
|
|
|
@ -17,14 +17,7 @@ describe('API', function() {
|
|||
const meta = await keychain.encryptMetadata(metadata);
|
||||
const verifierB64 = await keychain.authKeyB64();
|
||||
const p = function() {};
|
||||
const up = api.uploadWs(
|
||||
enc.stream,
|
||||
enc.streamInfo,
|
||||
meta,
|
||||
verifierB64,
|
||||
keychain,
|
||||
p
|
||||
);
|
||||
const up = api.uploadWs(enc.stream, enc.streamInfo, meta, verifierB64, p);
|
||||
|
||||
const result = await up.result;
|
||||
assert.ok(result.url);
|
||||
|
@ -38,14 +31,7 @@ describe('API', function() {
|
|||
const meta = await keychain.encryptMetadata(metadata);
|
||||
const verifierB64 = await keychain.authKeyB64();
|
||||
const p = function() {};
|
||||
const up = api.uploadWs(
|
||||
enc.stream,
|
||||
enc.streamInfo,
|
||||
meta,
|
||||
verifierB64,
|
||||
keychain,
|
||||
p
|
||||
);
|
||||
const up = api.uploadWs(enc.stream, enc.streamInfo, meta, verifierB64, p);
|
||||
up.cancel();
|
||||
try {
|
||||
await up.result;
|
||||
|
|
Loading…
Reference in New Issue