mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Fix file transfer error handling.
This commit is contained in:
parent
8aaa6d1466
commit
f66cabd6f4
1 changed files with 12 additions and 3 deletions
|
@ -2369,6 +2369,11 @@ TransferredFile.get = function(up, userid, fileid) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TransferredFile.prototype.close = function() {
|
TransferredFile.prototype.close = function() {
|
||||||
|
if(this.dc) {
|
||||||
|
this.dc.onclose = null;
|
||||||
|
this.dc.onerror = null;
|
||||||
|
this.dc.onmessage = null;
|
||||||
|
}
|
||||||
if(this.pc)
|
if(this.pc)
|
||||||
this.pc.close();
|
this.pc.close();
|
||||||
this.dc = null;
|
this.dc = null;
|
||||||
|
@ -2488,6 +2493,8 @@ function setFileStatus(f, status, delyes, delno) {
|
||||||
* @param {any} message
|
* @param {any} message
|
||||||
*/
|
*/
|
||||||
function failFile(f, message) {
|
function failFile(f, message) {
|
||||||
|
if(!f.dc)
|
||||||
|
return;
|
||||||
console.error('File transfer failed:', message);
|
console.error('File transfer failed:', message);
|
||||||
setFileStatus(f, message ? `Failed: ${message}` : 'Failed.');
|
setFileStatus(f, message ? `Failed: ${message}` : 'Failed.');
|
||||||
f.close();
|
f.close();
|
||||||
|
@ -2689,12 +2696,14 @@ async function sendFileData(f) {
|
||||||
async function write(a) {
|
async function write(a) {
|
||||||
while(f.dc.bufferedAmount > f.dc.bufferedAmountLowThreshold) {
|
while(f.dc.bufferedAmount > f.dc.bufferedAmountLowThreshold) {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
if(f.dc == null) {
|
if(!f.dc) {
|
||||||
reject(new Error('File is closed.'));
|
reject(new Error('File is closed.'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
f.dc.onbufferedamountlow = function(e) {
|
f.dc.onbufferedamountlow = function(e) {
|
||||||
if(f.dc == null) {
|
if(!f.dc) {
|
||||||
reject(new Error('File is closed.'));
|
reject(new Error('File is closed.'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
f.dc.onbufferedamountlow = null;
|
f.dc.onbufferedamountlow = null;
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -2805,7 +2814,7 @@ async function doneReceiveFileData(f) {
|
||||||
* @param {TransferredFile} f
|
* @param {TransferredFile} f
|
||||||
*/
|
*/
|
||||||
function closeReceiveFileData(f) {
|
function closeReceiveFileData(f) {
|
||||||
if(f.datalen != f.size) {
|
if(f.datalen !== f.size) {
|
||||||
setFileStatus(f, 'Failed.', true, true)
|
setFileStatus(f, 'Failed.', true, true)
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue