core-3nweb-client-lib 0.49.1 → 0.49.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,8 +39,7 @@ class WIP {
|
|
|
39
39
|
this.packer = undefined;
|
|
40
40
|
this.currentObjIndInMeta = 0;
|
|
41
41
|
this.currentObj = undefined;
|
|
42
|
-
this.doStateRecording =
|
|
43
|
-
(this.msg.progress.msgSize > MSG_SIZE_FOR_STATE_RECORDING);
|
|
42
|
+
this.doStateRecording = (this.msg.progress.msgSize > MSG_SIZE_FOR_STATE_RECORDING);
|
|
44
43
|
Object.seal(this);
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
@@ -65,8 +64,7 @@ class WIP {
|
|
|
65
64
|
const wip = new WIP(msg, state, cryptor);
|
|
66
65
|
wip.packer = await msg.msgPacker(state.pack);
|
|
67
66
|
if (state.bytesUploaded > 0) {
|
|
68
|
-
msg.progress.recipients[state.recipient].bytesSent =
|
|
69
|
-
state.bytesUploaded;
|
|
67
|
+
msg.progress.recipients[state.recipient].bytesSent = state.bytesUploaded;
|
|
70
68
|
}
|
|
71
69
|
return wip;
|
|
72
70
|
}
|
|
@@ -82,6 +80,7 @@ class WIP {
|
|
|
82
80
|
* or if this wip is done, undefined is returned.
|
|
83
81
|
*/
|
|
84
82
|
startNext() {
|
|
83
|
+
var _a, _b;
|
|
85
84
|
let proc = this.proc.latestTaskAtThisMoment();
|
|
86
85
|
if (proc) {
|
|
87
86
|
return;
|
|
@@ -103,9 +102,13 @@ class WIP {
|
|
|
103
102
|
proc = this.proc.addStarted(this.sendObjs());
|
|
104
103
|
}
|
|
105
104
|
else if (stage === "cancel") {
|
|
105
|
+
// DEBUG log
|
|
106
|
+
console.log(` canceled sending msgId: ${(_a = this.state.session) === null || _a === void 0 ? void 0 : _a.msgId}`);
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
else if (stage === undefined) {
|
|
110
|
+
// DEBUG log
|
|
111
|
+
console.log(` done sending msgId: ${(_b = this.state.session) === null || _b === void 0 ? void 0 : _b.msgId}`);
|
|
109
112
|
return;
|
|
110
113
|
}
|
|
111
114
|
else {
|
|
@@ -230,8 +233,7 @@ class WIP {
|
|
|
230
233
|
const recInfo = this.msg.progress.recipients[recipient];
|
|
231
234
|
if (complete) {
|
|
232
235
|
if (err) {
|
|
233
|
-
recInfo.err = (err.runtimeException ?
|
|
234
|
-
err : (err.stack ? err.stack : err));
|
|
236
|
+
recInfo.err = (err.runtimeException ? err : (err.stack ? err.stack : err));
|
|
235
237
|
}
|
|
236
238
|
else {
|
|
237
239
|
recInfo.bytesSent = this.msg.progress.msgSize;
|
|
@@ -258,8 +260,9 @@ class WIP {
|
|
|
258
260
|
throw new Error(`Message pack is not set.`);
|
|
259
261
|
}
|
|
260
262
|
this.state.session = await this.sender.sendMetadata(this.state.pack.meta);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
// DEBUG log
|
|
264
|
+
console.log(`\n wip.sendMeta() returned with\n msgId: ${this.state.session.msgId}\n meta.objIds sent to server:`, this.state.pack.meta.objIds);
|
|
265
|
+
this.msg.progress.recipients[this.state.recipient].idOnDelivery = this.state.session.msgId;
|
|
263
266
|
if (this.state.stage !== "cancel") {
|
|
264
267
|
this.state.stage = "5-send-objs";
|
|
265
268
|
}
|
|
@@ -312,6 +315,9 @@ class WIP {
|
|
|
312
315
|
return { objId, upload, src };
|
|
313
316
|
}
|
|
314
317
|
async completeDelivery() {
|
|
318
|
+
var _a;
|
|
319
|
+
// DEBUG log
|
|
320
|
+
console.log(` wip.completeDelivery() msg ${!!((_a = this.state.session) === null || _a === void 0 ? void 0 : _a.msgId)}`);
|
|
315
321
|
await this.sender.completeDelivery();
|
|
316
322
|
this.updateInfo(0, true);
|
|
317
323
|
this.state.stage = undefined;
|
|
@@ -331,12 +337,17 @@ class WIP {
|
|
|
331
337
|
* completes sending, when no more sending is left.
|
|
332
338
|
*/
|
|
333
339
|
async sendObjs() {
|
|
340
|
+
var _a, _b, _c;
|
|
341
|
+
// DEBUG log
|
|
342
|
+
console.log(` wip.sendObjs(), msgId: ${(_a = this.state.session) === null || _a === void 0 ? void 0 : _a.msgId}, p 0, \n !!this.sender is ${!!this.sender}\n this.currentObj is ${(_b = this.currentObj) === null || _b === void 0 ? void 0 : _b.objId}`);
|
|
334
343
|
if (!this.sender) {
|
|
335
344
|
this.sender = await sender_1.MailSender.resume(this.msg.r.makeNet(), this.state.recipient, this.state.session);
|
|
336
345
|
}
|
|
337
346
|
// ensure there is an object to send, or complete delivery
|
|
338
347
|
if (!this.currentObj) {
|
|
339
348
|
this.currentObj = await this.getObjToSend();
|
|
349
|
+
// DEBUG log
|
|
350
|
+
console.log(` ... this.getObjToSend() sets currentObj to be ${(_c = this.currentObj) === null || _c === void 0 ? void 0 : _c.objId}`);
|
|
340
351
|
if (!this.currentObj) {
|
|
341
352
|
return this.completeDelivery();
|
|
342
353
|
}
|
|
@@ -364,6 +375,8 @@ class WIP {
|
|
|
364
375
|
* @param obj is a message object to send
|
|
365
376
|
*/
|
|
366
377
|
async firstObjSendingRequest(obj) {
|
|
378
|
+
// DEBUG log
|
|
379
|
+
console.log(` wip.firstObjSendingRequest() ${obj.objId}`);
|
|
367
380
|
// read from source
|
|
368
381
|
const header = await obj.src.readHeader();
|
|
369
382
|
const { size, isEndless } = await obj.src.segSrc.getSize();
|
|
@@ -395,6 +408,8 @@ class WIP {
|
|
|
395
408
|
obj.upload.header = buffer_utils_1.base64.pack(header);
|
|
396
409
|
}
|
|
397
410
|
this.updateInfo(header.length + segsChunk.length);
|
|
411
|
+
// DEBUG log
|
|
412
|
+
console.log(` ... ${obj.objId} 1st/single obj request send, isObjDone is ${isObjDone}`);
|
|
398
413
|
return isObjDone;
|
|
399
414
|
}
|
|
400
415
|
/**
|
|
@@ -404,12 +419,16 @@ class WIP {
|
|
|
404
419
|
* @param obj is a message object to send
|
|
405
420
|
*/
|
|
406
421
|
async followingObjSendingRequest(obj) {
|
|
422
|
+
// DEBUG log
|
|
423
|
+
console.log(` wip.followingObjSendingRequest() ${obj.objId}`);
|
|
407
424
|
// read from source
|
|
408
425
|
const segsSize = obj.upload.expectedSegsSize;
|
|
409
426
|
const chunk = await obj.src.segSrc.readNext(this.sender.maxChunkSize);
|
|
410
427
|
// return early, when there are no bytes
|
|
411
428
|
if (!chunk) {
|
|
412
429
|
await this.sender.sendObj(obj.objId, EMPTY_BYTE_ARR, undefined, { ofs: obj.upload.segsOffset, last: true });
|
|
430
|
+
// DEBUG log
|
|
431
|
+
console.log(` ... ${obj.objId} 2nd/following obj request has no more chunk to send, and completed sending obj`);
|
|
413
432
|
return true;
|
|
414
433
|
}
|
|
415
434
|
// check for an overrun
|
|
@@ -429,6 +448,8 @@ class WIP {
|
|
|
429
448
|
await this.sender.sendObj(obj.objId, chunk, undefined, opts);
|
|
430
449
|
obj.upload.segsOffset += chunk.length;
|
|
431
450
|
this.updateInfo(chunk.length);
|
|
451
|
+
// DEBUG log
|
|
452
|
+
console.log(` ... ${obj.objId} 2nd/following obj request sent ${chunk.length} bytes, isObjDone is ${isObjDone}`);
|
|
432
453
|
return isObjDone;
|
|
433
454
|
}
|
|
434
455
|
}
|
|
@@ -155,9 +155,9 @@ class MailSender {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
prepareRedirectOrThrowUp(rep) {
|
|
158
|
-
if (("string" !== typeof rep.redirect)
|
|
159
|
-
(rep.redirect.length === 0)
|
|
160
|
-
((new URL(rep.redirect)).protocol !== 'https:')) {
|
|
158
|
+
if (("string" !== typeof rep.redirect)
|
|
159
|
+
|| (rep.redirect.length === 0)
|
|
160
|
+
|| ((new URL(rep.redirect)).protocol !== 'https:')) {
|
|
161
161
|
throw this.badRedirectExc();
|
|
162
162
|
}
|
|
163
163
|
// refuse second redirect
|
|
@@ -413,8 +413,8 @@ class MailSender {
|
|
|
413
413
|
async trySessionRestart() {
|
|
414
414
|
// check and set timestamp for session restarts
|
|
415
415
|
const now = Date.now();
|
|
416
|
-
if ((typeof this.sessionRestartTimeStamp === 'number')
|
|
417
|
-
(now <= (this.sessionRestartTimeStamp + TOO_EARLY_RESTART_PERIOD))) {
|
|
416
|
+
if ((typeof this.sessionRestartTimeStamp === 'number')
|
|
417
|
+
&& (now <= (this.sessionRestartTimeStamp + TOO_EARLY_RESTART_PERIOD))) {
|
|
418
418
|
return false;
|
|
419
419
|
}
|
|
420
420
|
this.sessionRestartTimeStamp = now;
|