port fix for #1005 to vnext
This commit is contained in:
parent
4ef303a2c9
commit
b6517c5442
@ -318,8 +318,8 @@ function download(id, keychain, onprogress, canceller) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
xhr.addEventListener('progress', function(event) {
|
xhr.addEventListener('progress', function(event) {
|
||||||
if (event.lengthComputable && event.target.status === 200) {
|
if (event.target.status === 200) {
|
||||||
onprogress([event.loaded, event.total]);
|
onprogress(event.loaded);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const auth = await keychain.authHeader();
|
const auth = await keychain.authHeader();
|
||||||
@ -327,7 +327,7 @@ function download(id, keychain, onprogress, canceller) {
|
|||||||
xhr.setRequestHeader('Authorization', auth);
|
xhr.setRequestHeader('Authorization', auth);
|
||||||
xhr.responseType = 'blob';
|
xhr.responseType = 'blob';
|
||||||
xhr.send();
|
xhr.send();
|
||||||
onprogress([0, 1]);
|
onprogress(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ export default class FileReceiver extends Nanobus {
|
|||||||
this.fileInfo.name = meta.name;
|
this.fileInfo.name = meta.name;
|
||||||
this.fileInfo.type = meta.type;
|
this.fileInfo.type = meta.type;
|
||||||
this.fileInfo.iv = meta.iv;
|
this.fileInfo.iv = meta.iv;
|
||||||
this.fileInfo.size = meta.size;
|
this.fileInfo.size = +meta.size;
|
||||||
this.fileInfo.manifest = meta.manifest;
|
this.fileInfo.manifest = meta.manifest;
|
||||||
this.state = 'ready';
|
this.state = 'ready';
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ export default class FileReceiver extends Nanobus {
|
|||||||
this.fileInfo.id,
|
this.fileInfo.id,
|
||||||
this.keychain,
|
this.keychain,
|
||||||
p => {
|
p => {
|
||||||
this.progress = p;
|
this.progress = [p, this.fileInfo.size];
|
||||||
this.emit('progress');
|
this.emit('progress');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -113,7 +113,7 @@ export default class FileReceiver extends Nanobus {
|
|||||||
|
|
||||||
async downloadStream(noSave = false) {
|
async downloadStream(noSave = false) {
|
||||||
const onprogress = p => {
|
const onprogress = p => {
|
||||||
this.progress = p;
|
this.progress = [p, this.fileInfo.size];
|
||||||
this.emit('progress');
|
this.emit('progress');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ export default class FileReceiver extends Nanobus {
|
|||||||
};
|
};
|
||||||
await this.sendMessageToSw(info);
|
await this.sendMessageToSw(info);
|
||||||
|
|
||||||
onprogress([0, this.fileInfo.size]);
|
onprogress(0);
|
||||||
|
|
||||||
if (noSave) {
|
if (noSave) {
|
||||||
const res = await fetch(`/api/download/${this.fileInfo.id}`);
|
const res = await fetch(`/api/download/${this.fileInfo.id}`);
|
||||||
@ -166,7 +166,7 @@ export default class FileReceiver extends Nanobus {
|
|||||||
id: this.fileInfo.id
|
id: this.fileInfo.id
|
||||||
});
|
});
|
||||||
prog = msg.progress;
|
prog = msg.progress;
|
||||||
onprogress([prog, this.fileInfo.size]);
|
onprogress(prog);
|
||||||
await delay(1000);
|
await delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,14 +6,6 @@ module.exports = async function(req, res) {
|
|||||||
const id = req.params.id;
|
const id = req.params.id;
|
||||||
try {
|
try {
|
||||||
const meta = req.meta;
|
const meta = req.meta;
|
||||||
const contentLength = await storage.length(id);
|
|
||||||
res.writeHead(200, {
|
|
||||||
'Content-Disposition': 'attachment',
|
|
||||||
'Content-Type': 'application/octet-stream',
|
|
||||||
'Content-Length': contentLength,
|
|
||||||
'WWW-Authenticate': `send-v1 ${req.nonce}`
|
|
||||||
});
|
|
||||||
|
|
||||||
const fileStream = await storage.get(id);
|
const fileStream = await storage.get(id);
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
@ -22,7 +14,7 @@ module.exports = async function(req, res) {
|
|||||||
fileStream.destroy();
|
fileStream.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
fileStream.on('end', async () => {
|
fileStream.pipe(res).on('finish', async () => {
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -39,8 +31,6 @@ module.exports = async function(req, res) {
|
|||||||
log.info('StorageError:', id);
|
log.info('StorageError:', id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fileStream.pipe(res);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.sendStatus(404);
|
res.sendStatus(404);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class GCSStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getStream(id) {
|
getStream(id) {
|
||||||
return this.bucket.file(id).createReadStream();
|
return this.bucket.file(id).createReadStream({ validation: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
set(id, file) {
|
set(id, file) {
|
||||||
|
Loading…
Reference in New Issue
Block a user