@vitrinka/web 0.8.0 → 0.8.1
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.
- package/CHANGELOG.md +43 -0
- package/README.md +15 -6
- package/build/hud.iife.js +15 -15
- package/build/one.iife.js +1 -1
- package/build/recorder/api.d.ts +5 -3
- package/build/recorder/api.js +5 -3
- package/build/recorder/storage/index.d.ts +1 -1
- package/build/recorder/storage/index.js +3 -2
- package/build/recorder/storage/lock.js +85 -3
- package/build/recorder/version.d.ts +2 -2
- package/build/recorder/version.js +1 -1
- package/build/report/engine.d.ts +8 -0
- package/build/report/engine.js +24 -3
- package/build/report/i18n.d.ts +2 -0
- package/build/report/i18n.js +2 -0
- package/build/report/styles.d.ts +1 -1
- package/build/report/styles.js +9 -3
- package/build/report/widget.d.ts +15 -2
- package/build/report/widget.js +81 -27
- package/build/report/wire.d.ts +40 -1
- package/build/report/wire.js +74 -9
- package/build/report-widget.mjs +18 -12
- package/package.json +1 -1
package/build/report/widget.js
CHANGED
|
@@ -47,10 +47,9 @@ import { listMine, openSession, sessionLive } from './reader';
|
|
|
47
47
|
import { noteSent, readSent } from './sent';
|
|
48
48
|
import { readSize, SIZE_KEY, SIZE_SCALE, SIZES, techDetails, writePref } from './settings';
|
|
49
49
|
import { REPORT_CSS } from './styles';
|
|
50
|
-
import { ReportJob } from './wire';
|
|
50
|
+
import { EMPTY_CAPTURE, prepareCapture, ReportJob } from './wire';
|
|
51
51
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
52
52
|
const TITLE_CAP = 100;
|
|
53
|
-
const EMPTY_CAPTURE = { chunks: [], truncated: false, console: [], network: [] };
|
|
54
53
|
const TOOLS = ['circle', 'box', 'arrow', 'hide'];
|
|
55
54
|
/** A keyboard mark starts as this, centred; arrows move it 10 px, Shift+arrows resize it. */
|
|
56
55
|
const KB_DRAFT = { w: 160, h: 80 };
|
|
@@ -149,13 +148,26 @@ function setLabel(el, text) {
|
|
|
149
148
|
if (span)
|
|
150
149
|
span.textContent = text;
|
|
151
150
|
}
|
|
152
|
-
/**
|
|
153
|
-
|
|
151
|
+
/**
|
|
152
|
+
* A segmented control's sliding indicator under its picked segment (the marking bar's shapes, the settings' sizes);
|
|
153
|
+
* unmeasurable while hidden. It slides only from one pick to the next: its first placement, and `land` (its bar just
|
|
154
|
+
* appeared), put it in place on the frame it shows — slid there, it would grow from width 0 at the control's edge
|
|
155
|
+
* (or from where a hidden bar last left it), with the picked segment bare until it arrived.
|
|
156
|
+
*/
|
|
157
|
+
function placeIndicator(seg, ind, btn, land = false) {
|
|
154
158
|
if (!btn || !btn.offsetWidth)
|
|
155
159
|
return;
|
|
160
|
+
const jump = land || !seg.classList.contains('measured');
|
|
161
|
+
if (jump)
|
|
162
|
+
ind.style.transition = 'none';
|
|
156
163
|
ind.style.width = `${btn.offsetWidth}px`;
|
|
157
164
|
ind.style.transform = `translateX(${btn.offsetLeft}px)`;
|
|
158
165
|
seg.classList.add('measured');
|
|
166
|
+
if (!jump)
|
|
167
|
+
return;
|
|
168
|
+
// The read commits the placement as the style the slide starts from, so restoring the slide animates nothing.
|
|
169
|
+
void ind.offsetWidth;
|
|
170
|
+
ind.style.removeProperty('transition');
|
|
159
171
|
}
|
|
160
172
|
/** A text field has the focus — its own editing keys (⌘Z included) are its. */
|
|
161
173
|
function typing() {
|
|
@@ -187,6 +199,9 @@ function buildDom(mount) {
|
|
|
187
199
|
const mReports = menuItem(ICON.list);
|
|
188
200
|
const mRecents = menuItem(ICON.clock);
|
|
189
201
|
const mRecord = menuItem(ICON.rec);
|
|
202
|
+
// Why Record waits, a second line under its label: its description, so aria-hidden keeps it out of the name.
|
|
203
|
+
const mRecordWhy = h('small', { class: 'pop-why', id: 'vr-record-why', 'aria-hidden': 'true' });
|
|
204
|
+
mRecord.append(mRecordWhy);
|
|
190
205
|
const mSettings = menuItem(ICON.gear);
|
|
191
206
|
const mOpen = h('a', { class: 'pop-item', role: 'menuitem', target: '_blank', rel: 'noopener noreferrer' }, icon(ICON.ext), h('span'));
|
|
192
207
|
const morePop = h('div', { class: 'pop more', role: 'menu' }, mReports, mRecents, mRecord, mSettings, mOpen);
|
|
@@ -313,7 +328,7 @@ function buildDom(mount) {
|
|
|
313
328
|
return {
|
|
314
329
|
root, fab, fabLabel, fabKbd, card, head, title, whoBtn, whoAv, whoName, more, closeBtn, body, foot,
|
|
315
330
|
accountPop, accName, accMail, accVia, accLinked, accUnlink, accLink, accPortal,
|
|
316
|
-
morePop, mReports, mRecents, mRecord, mSettings, mOpen,
|
|
331
|
+
morePop, mReports, mRecents, mRecord, mRecordWhy, mSettings, mOpen,
|
|
317
332
|
reports, repBack, repStatus, repRows, repLocal, repPortal, recents, recBack, recStatus, recRows,
|
|
318
333
|
linking, linkBack, linkLabel, linkCode, linkOpen, linkOpenText, linkQr, linkHint, linkWait, linkRetry,
|
|
319
334
|
describe, kinds, kindsLabel, kindButtons, prompt, desc, lines, linesEmpty, attached, attachedText, disclose, discloseText, included,
|
|
@@ -626,9 +641,9 @@ export class ReportWidget {
|
|
|
626
641
|
this.size = z;
|
|
627
642
|
writePref(SIZE_KEY, z);
|
|
628
643
|
this.paint();
|
|
629
|
-
// A parked card is placed by its painted size: re-place it at the new one.
|
|
644
|
+
// A parked card is placed by its painted size: re-place it at the new one, in its corner at once.
|
|
630
645
|
if (this.parked)
|
|
631
|
-
this.placeCard();
|
|
646
|
+
this.placeCard(true);
|
|
632
647
|
});
|
|
633
648
|
}
|
|
634
649
|
on(e.techBtn, 'click', () => {
|
|
@@ -660,7 +675,12 @@ export class ReportWidget {
|
|
|
660
675
|
});
|
|
661
676
|
on(e.mReports, 'click', fromMenu(() => void this.openReports()));
|
|
662
677
|
on(e.mRecents, 'click', fromMenu(() => this.show('recents')));
|
|
663
|
-
|
|
678
|
+
const switchFace = fromMenu(() => this.recordSwitch?.());
|
|
679
|
+
// A waiting Record stays focusable so it can say why (paintAccount), so its press must do nothing: the menu stays open.
|
|
680
|
+
on(e.mRecord, 'click', () => {
|
|
681
|
+
if (!this.recordWaits())
|
|
682
|
+
switchFace();
|
|
683
|
+
});
|
|
664
684
|
on(e.mSettings, 'click', fromMenu(() => this.show('settings')));
|
|
665
685
|
on(e.mOpen, 'click', fromMenu(() => undefined));
|
|
666
686
|
on(e.accPortal, 'click', fromMenu(() => undefined));
|
|
@@ -804,7 +824,7 @@ export class ReportWidget {
|
|
|
804
824
|
}));
|
|
805
825
|
this.offs.push(listen(window, 'resize', () => {
|
|
806
826
|
if (this.parked)
|
|
807
|
-
this.placeCard();
|
|
827
|
+
this.placeCard(true);
|
|
808
828
|
if (this.marking)
|
|
809
829
|
this.placeSeg();
|
|
810
830
|
}));
|
|
@@ -1241,7 +1261,7 @@ export class ReportWidget {
|
|
|
1241
1261
|
this.renderMarks();
|
|
1242
1262
|
this.paint();
|
|
1243
1263
|
this.placeCard();
|
|
1244
|
-
this.placeSeg();
|
|
1264
|
+
this.placeSeg(true);
|
|
1245
1265
|
const vw = globalThis.innerWidth || 800;
|
|
1246
1266
|
this.placeCoach({ x: vw / 2 - 150, y: BAR_CLEAR + 12 }, false);
|
|
1247
1267
|
this.e.mark.focus();
|
|
@@ -1290,17 +1310,31 @@ export class ReportWidget {
|
|
|
1290
1310
|
const r = this.e.card.getBoundingClientRect();
|
|
1291
1311
|
return { vw, vh, w: r.width || Math.min(CARD.w * k, vw - 32), h: r.height || Math.min(CARD.h * k, vh - insets.top - insets.bottom), ...insets };
|
|
1292
1312
|
}
|
|
1293
|
-
/**
|
|
1294
|
-
|
|
1313
|
+
/**
|
|
1314
|
+
* Parks the card in the corner that covers none of the marks; it glides there (styles: `.card.parked`).
|
|
1315
|
+
* `reanchor`: the corner itself changed (a new size, a resized viewport) — kept in the same corner, the card
|
|
1316
|
+
* lands there on the frame it changes, as an anchored card does; slid there, a parked card (scaled from its
|
|
1317
|
+
* top-left) would first overhang its corner by the size difference, then glide back.
|
|
1318
|
+
*/
|
|
1319
|
+
placeCard(reanchor = false) {
|
|
1295
1320
|
if (!this.parked)
|
|
1296
1321
|
return;
|
|
1297
1322
|
const f = this.frame();
|
|
1323
|
+
const was = this.parked;
|
|
1298
1324
|
this.parked = pickCorner(this.parked, this.markers.map((m) => m.rect), f);
|
|
1299
1325
|
const r = cornerRect(this.parked, f);
|
|
1300
|
-
const
|
|
1301
|
-
this.
|
|
1302
|
-
|
|
1303
|
-
|
|
1326
|
+
const card = this.e.card;
|
|
1327
|
+
const land = reanchor && this.parked === was;
|
|
1328
|
+
if (land)
|
|
1329
|
+
card.style.transition = 'none';
|
|
1330
|
+
card.classList.add('parked');
|
|
1331
|
+
card.style.left = `${r.x}px`;
|
|
1332
|
+
card.style.top = `${r.y}px`;
|
|
1333
|
+
if (!land)
|
|
1334
|
+
return;
|
|
1335
|
+
// The read commits the new place as the style the glide starts from, so restoring the glide moves nothing.
|
|
1336
|
+
void card.offsetWidth;
|
|
1337
|
+
card.style.removeProperty('transition');
|
|
1304
1338
|
}
|
|
1305
1339
|
unpark() {
|
|
1306
1340
|
this.parked = null;
|
|
@@ -1309,9 +1343,9 @@ export class ReportWidget {
|
|
|
1309
1343
|
this.e.card.style.removeProperty('left');
|
|
1310
1344
|
this.e.card.style.removeProperty('top');
|
|
1311
1345
|
}
|
|
1312
|
-
/** The segmented control's indicator under the picked shape. */
|
|
1313
|
-
placeSeg() {
|
|
1314
|
-
placeIndicator(this.e.seg, this.e.segInd, this.e.toolButtons.get(this.tool));
|
|
1346
|
+
/** The segmented control's indicator under the picked shape; `land`: the bar just appeared, so it does not slide. */
|
|
1347
|
+
placeSeg(land = false) {
|
|
1348
|
+
placeIndicator(this.e.seg, this.e.segInd, this.e.toolButtons.get(this.tool), land);
|
|
1315
1349
|
}
|
|
1316
1350
|
onChrome(t) {
|
|
1317
1351
|
return t instanceof Node && (this.e.toolbar.contains(t) || this.e.pins.contains(t));
|
|
@@ -1544,6 +1578,18 @@ export class ReportWidget {
|
|
|
1544
1578
|
words() {
|
|
1545
1579
|
return this.e.desc.value.trim() || (this.markers.find((m) => m.note.trim())?.note.trim() ?? '');
|
|
1546
1580
|
}
|
|
1581
|
+
/**
|
|
1582
|
+
* The card holds something the reporter made and has not sent: words in the
|
|
1583
|
+
* description or a mark's note (a note lives on its mark), a mark, the
|
|
1584
|
+
* picked word for it, a file.
|
|
1585
|
+
*/
|
|
1586
|
+
hasDraft() {
|
|
1587
|
+
return this.e.desc.value.trim() !== '' || this.markers.length > 0 || this.kind !== null || this.files.length > 0;
|
|
1588
|
+
}
|
|
1589
|
+
/** Record unmounts this card for the pill (vt-8020 D8), so it waits while the card holds a draft or a report sending or waiting on Try again — the switch would lose it. */
|
|
1590
|
+
recordWaits() {
|
|
1591
|
+
return this.sending || this.job !== null || this.hasDraft();
|
|
1592
|
+
}
|
|
1547
1593
|
async send() {
|
|
1548
1594
|
const description = this.words();
|
|
1549
1595
|
if (this.sending || !description)
|
|
@@ -1562,12 +1608,9 @@ export class ReportWidget {
|
|
|
1562
1608
|
for (const m of this.markers)
|
|
1563
1609
|
for (const id of this.hideIds.get(m.key) ?? [])
|
|
1564
1610
|
marked.add(id);
|
|
1565
|
-
const
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
return EMPTY_CAPTURE;
|
|
1569
|
-
})
|
|
1570
|
-
: EMPTY_CAPTURE;
|
|
1611
|
+
const engine = this.engine;
|
|
1612
|
+
const frozen = this.frozen ?? { clip: null, stored: Promise.resolve(new Map()) };
|
|
1613
|
+
const capture = engine ? await prepareCapture(() => engine.build(frozen, this.markers, marked)) : EMPTY_CAPTURE;
|
|
1571
1614
|
this.job = new ReportJob(capture, globalThis.location?.host ?? '', { url: this.opts.base, key: this.opts.key }, this.files);
|
|
1572
1615
|
}
|
|
1573
1616
|
this.result = await this.job.run(this.envelope(description, this.job.capture));
|
|
@@ -1670,8 +1713,19 @@ export class ReportWidget {
|
|
|
1670
1713
|
// Recording lives where the pill does: only a linked member gets it, its recents and the way to vitrinka.
|
|
1671
1714
|
e.mRecents.hidden = !this.recordSwitch;
|
|
1672
1715
|
e.mRecord.hidden = !this.recordSwitch;
|
|
1673
|
-
//
|
|
1674
|
-
|
|
1716
|
+
// A waiting Record says why (recordWaits). aria-disabled, never `disabled`: the menu's arrows still reach it,
|
|
1717
|
+
// so a keyboard and screen-reader user hears the reason too; its click is guarded in bind().
|
|
1718
|
+
const waits = this.recordWaits();
|
|
1719
|
+
if (waits)
|
|
1720
|
+
e.mRecord.setAttribute('aria-disabled', 'true');
|
|
1721
|
+
else
|
|
1722
|
+
e.mRecord.removeAttribute('aria-disabled');
|
|
1723
|
+
e.mRecordWhy.hidden = !waits;
|
|
1724
|
+
e.mRecordWhy.textContent = s.recordHasDraft;
|
|
1725
|
+
if (waits)
|
|
1726
|
+
e.mRecord.setAttribute('aria-describedby', e.mRecordWhy.id);
|
|
1727
|
+
else
|
|
1728
|
+
e.mRecord.removeAttribute('aria-describedby');
|
|
1675
1729
|
const open = member ? this.opts.base : portal;
|
|
1676
1730
|
e.mOpen.hidden = !open;
|
|
1677
1731
|
if (open)
|
package/build/report/wire.d.ts
CHANGED
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
* 4xx) is skipped with a warning: the report still files, without it. The
|
|
18
18
|
* reporter's files go before the replay — they are what they chose to send.
|
|
19
19
|
* `reportUrl` is the server's — shown as returned, never composed.
|
|
20
|
+
*
|
|
21
|
+
* EVERY LEG HAS A DEADLINE (`deadline`): a request nothing answers — a server
|
|
22
|
+
* stuck in a handler, a proxy or connection holding it — rejects like a
|
|
23
|
+
* dropped connection, so the card shows Try again instead of "Sending…"
|
|
24
|
+
* forever. An upload's allowance grows with its bytes at a slow uplink's
|
|
25
|
+
* pace, so only a stalled one runs out. A create whose answer was lost after
|
|
26
|
+
* the server stored it is created again by Try again: the same risk a dropped
|
|
27
|
+
* connection already carries.
|
|
20
28
|
*/
|
|
21
29
|
import { type ApiTarget } from '../recorder/api';
|
|
22
30
|
import { type BuiltCapture, type ConsoleEntry, type NetEntry } from './engine';
|
|
@@ -54,11 +62,38 @@ export interface SubmitReply {
|
|
|
54
62
|
status: 'filed' | 'quarantined';
|
|
55
63
|
reportUrl?: string;
|
|
56
64
|
}
|
|
65
|
+
/** How long a leg may go unanswered: `ms` for any leg, plus one ms per `bytesPerMs` bytes an upload carries. */
|
|
66
|
+
export interface LegLimits {
|
|
67
|
+
ms: number;
|
|
68
|
+
bytesPerMs: number;
|
|
69
|
+
}
|
|
70
|
+
/** 30 s for a JSON leg; an upload adds its bytes at 32 KiB/s (≈ 256 kbit/s), so a 10 MiB file gets about six minutes. */
|
|
71
|
+
export declare const LEG_LIMITS: LegLimits;
|
|
72
|
+
/** A leg ran past its deadline: retryable, never a refusal for good. */
|
|
73
|
+
export declare class LegTimeout extends Error {
|
|
74
|
+
constructor(what: string, ms: number);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Run `work` under a deadline: past `ms` its signal aborts (the fetch and its
|
|
78
|
+
* answer's body stop) and the returned promise rejects with LegTimeout —
|
|
79
|
+
* whether or not `work` honours the signal, so nothing waits on it forever.
|
|
80
|
+
*/
|
|
81
|
+
export declare function deadline<T>(what: string, ms: number, work: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
82
|
+
/** What a report carries when its capture could not be prepared. */
|
|
83
|
+
export declare const EMPTY_CAPTURE: BuiltCapture;
|
|
84
|
+
/**
|
|
85
|
+
* The capture a report sends, under its deadline like every leg (reading an
|
|
86
|
+
* earlier load's stored windows can hang): past it, or failed, the report
|
|
87
|
+
* goes without one. A build that finishes later is dropped — it never
|
|
88
|
+
* reaches the job this answer started.
|
|
89
|
+
*/
|
|
90
|
+
export declare function prepareCapture(build: () => Promise<BuiltCapture>, ms?: number): Promise<BuiltCapture>;
|
|
57
91
|
export declare class ReportJob {
|
|
58
92
|
readonly capture: BuiltCapture;
|
|
59
93
|
private readonly tabHost;
|
|
60
94
|
private readonly target;
|
|
61
95
|
readonly files: readonly File[];
|
|
96
|
+
private readonly limits;
|
|
62
97
|
id: string;
|
|
63
98
|
custody: 'direct' | 'quarantined' | '';
|
|
64
99
|
/** The editable fields as the server last received them. */
|
|
@@ -69,7 +104,11 @@ export declare class ReportJob {
|
|
|
69
104
|
/** The files (by index) the server has — landed or refused for good. */
|
|
70
105
|
private readonly filesDone;
|
|
71
106
|
/** `target`: the widget's own base and key — never whatever another widget configured. `files`: the reporter's attachments, fixed for the job. */
|
|
72
|
-
constructor(capture: BuiltCapture, tabHost: string, target: ApiTarget, files?: readonly File[]);
|
|
107
|
+
constructor(capture: BuiltCapture, tabHost: string, target: ApiTarget, files?: readonly File[], limits?: LegLimits);
|
|
108
|
+
/** One JSON call under its leg deadline. */
|
|
109
|
+
private call;
|
|
110
|
+
/** One upload under a deadline that grows with its bytes. */
|
|
111
|
+
private upload;
|
|
73
112
|
/** A file has not landed yet: the attachment leg is what a retry resumes. */
|
|
74
113
|
get filesPending(): boolean;
|
|
75
114
|
/** Run the legs from wherever the last run stopped; rejects with the failing leg's error. */
|
package/build/report/wire.js
CHANGED
|
@@ -17,14 +17,68 @@
|
|
|
17
17
|
* 4xx) is skipped with a warning: the report still files, without it. The
|
|
18
18
|
* reporter's files go before the replay — they are what they chose to send.
|
|
19
19
|
* `reportUrl` is the server's — shown as returned, never composed.
|
|
20
|
+
*
|
|
21
|
+
* EVERY LEG HAS A DEADLINE (`deadline`): a request nothing answers — a server
|
|
22
|
+
* stuck in a handler, a proxy or connection holding it — rejects like a
|
|
23
|
+
* dropped connection, so the card shows Try again instead of "Sending…"
|
|
24
|
+
* forever. An upload's allowance grows with its bytes at a slow uplink's
|
|
25
|
+
* pace, so only a stalled one runs out. A create whose answer was lost after
|
|
26
|
+
* the server stored it is created again by Try again: the same risk a dropped
|
|
27
|
+
* connection already carries.
|
|
20
28
|
*/
|
|
21
29
|
import { api, permanentStatus, uploadTo, VitrinkaApiError } from '../recorder/api';
|
|
22
30
|
import { EVENTS_PER_POST } from './engine';
|
|
31
|
+
/** 30 s for a JSON leg; an upload adds its bytes at 32 KiB/s (≈ 256 kbit/s), so a 10 MiB file gets about six minutes. */
|
|
32
|
+
export const LEG_LIMITS = { ms: 30_000, bytesPerMs: 32 };
|
|
33
|
+
/** A leg ran past its deadline: retryable, never a refusal for good. */
|
|
34
|
+
export class LegTimeout extends Error {
|
|
35
|
+
constructor(what, ms) {
|
|
36
|
+
super(`vitrinka: ${what} got no answer in ${Math.round(ms / 1000)} s — Try again resumes it`);
|
|
37
|
+
this.name = 'LegTimeout';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run `work` under a deadline: past `ms` its signal aborts (the fetch and its
|
|
42
|
+
* answer's body stop) and the returned promise rejects with LegTimeout —
|
|
43
|
+
* whether or not `work` honours the signal, so nothing waits on it forever.
|
|
44
|
+
*/
|
|
45
|
+
export async function deadline(what, ms, work) {
|
|
46
|
+
const ctl = new AbortController();
|
|
47
|
+
let timer;
|
|
48
|
+
const expired = new Promise((_, reject) => {
|
|
49
|
+
timer = setTimeout(() => {
|
|
50
|
+
const e = new LegTimeout(what, ms);
|
|
51
|
+
ctl.abort(e);
|
|
52
|
+
reject(e);
|
|
53
|
+
}, ms);
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
return await Promise.race([work(ctl.signal), expired]);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** What a report carries when its capture could not be prepared. */
|
|
63
|
+
export const EMPTY_CAPTURE = { chunks: [], truncated: false, console: [], network: [] };
|
|
64
|
+
/**
|
|
65
|
+
* The capture a report sends, under its deadline like every leg (reading an
|
|
66
|
+
* earlier load's stored windows can hang): past it, or failed, the report
|
|
67
|
+
* goes without one. A build that finishes later is dropped — it never
|
|
68
|
+
* reaches the job this answer started.
|
|
69
|
+
*/
|
|
70
|
+
export function prepareCapture(build, ms = LEG_LIMITS.ms) {
|
|
71
|
+
return deadline('preparing the capture', ms, build).catch((e) => {
|
|
72
|
+
console.warn('vitrinka: the capture could not be prepared — the report goes without it', e);
|
|
73
|
+
return EMPTY_CAPTURE;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
23
76
|
export class ReportJob {
|
|
24
77
|
capture;
|
|
25
78
|
tabHost;
|
|
26
79
|
target;
|
|
27
80
|
files;
|
|
81
|
+
limits;
|
|
28
82
|
id = '';
|
|
29
83
|
custody = '';
|
|
30
84
|
/** The editable fields as the server last received them. */
|
|
@@ -35,11 +89,23 @@ export class ReportJob {
|
|
|
35
89
|
/** The files (by index) the server has — landed or refused for good. */
|
|
36
90
|
filesDone = new Set();
|
|
37
91
|
/** `target`: the widget's own base and key — never whatever another widget configured. `files`: the reporter's attachments, fixed for the job. */
|
|
38
|
-
constructor(capture, tabHost, target, files = []) {
|
|
92
|
+
constructor(capture, tabHost, target, files = [], limits = LEG_LIMITS) {
|
|
39
93
|
this.capture = capture;
|
|
40
94
|
this.tabHost = tabHost;
|
|
41
95
|
this.target = target;
|
|
42
96
|
this.files = files;
|
|
97
|
+
this.limits = limits;
|
|
98
|
+
}
|
|
99
|
+
/** One JSON call under its leg deadline. */
|
|
100
|
+
call(method, path, body) {
|
|
101
|
+
return deadline(`${method} ${path}`, this.limits.ms, (signal) => api(method, path, body, { target: this.target, signal }));
|
|
102
|
+
}
|
|
103
|
+
/** One upload under a deadline that grows with its bytes. */
|
|
104
|
+
upload(path, contentType, body) {
|
|
105
|
+
// The bytes fetch sends: a JSON chunk's UTF-8, never its UTF-16 length (non-ASCII text runs up to 3× longer).
|
|
106
|
+
const bytes = typeof body === 'string' ? new TextEncoder().encode(body).byteLength : body.size;
|
|
107
|
+
const ms = this.limits.ms + Math.ceil(bytes / this.limits.bytesPerMs);
|
|
108
|
+
return deadline(`POST ${path}`, ms, (signal) => uploadTo(path, contentType, body, this.target, signal));
|
|
43
109
|
}
|
|
44
110
|
/** A file has not landed yet: the attachment leg is what a retry resumes. */
|
|
45
111
|
get filesPending() {
|
|
@@ -47,17 +113,16 @@ export class ReportJob {
|
|
|
47
113
|
}
|
|
48
114
|
/** Run the legs from wherever the last run stopped; rejects with the failing leg's error. */
|
|
49
115
|
async run(env) {
|
|
50
|
-
const to = { target: this.target };
|
|
51
116
|
const edits = { title: env.title, description: env.description, markers: env.markers, notify: env.notify ?? false };
|
|
52
117
|
const editsKey = JSON.stringify(edits);
|
|
53
118
|
if (!this.id) {
|
|
54
|
-
const res = await
|
|
119
|
+
const res = await this.call('POST', '/api/v1/reports', env).catch((e) => {
|
|
55
120
|
// A vitrinka older than the report type refuses the unknown field: the hint is optional, the report is not.
|
|
56
121
|
if (env.type === undefined || !(e instanceof VitrinkaApiError) || e.status !== 400 || !/\btype\b/.test(e.message))
|
|
57
122
|
throw e;
|
|
58
123
|
console.warn('vitrinka: this server takes no report type yet — sending the report without it');
|
|
59
124
|
const { type: _dropped, ...rest } = env;
|
|
60
|
-
return
|
|
125
|
+
return this.call('POST', '/api/v1/reports', rest);
|
|
61
126
|
});
|
|
62
127
|
if (typeof res.id !== 'string' || !res.id)
|
|
63
128
|
throw new Error('vitrinka: the server filed the report without an id');
|
|
@@ -66,7 +131,7 @@ export class ReportJob {
|
|
|
66
131
|
this.sent = editsKey;
|
|
67
132
|
}
|
|
68
133
|
else if (this.sent !== editsKey) {
|
|
69
|
-
await
|
|
134
|
+
await this.call('PATCH', `/api/v1/reports/${encodeURIComponent(this.id)}`, edits);
|
|
70
135
|
this.sent = editsKey;
|
|
71
136
|
}
|
|
72
137
|
await this.sendFiles();
|
|
@@ -81,7 +146,7 @@ export class ReportJob {
|
|
|
81
146
|
this.skipCapture = true;
|
|
82
147
|
}
|
|
83
148
|
}
|
|
84
|
-
const reply = await
|
|
149
|
+
const reply = await this.call('POST', `/api/v1/reports/${encodeURIComponent(this.id)}/submit`, {});
|
|
85
150
|
return {
|
|
86
151
|
status: reply.status === 'filed' ? 'filed' : 'quarantined',
|
|
87
152
|
...(typeof reply.reportUrl === 'string' && reply.reportUrl ? { reportUrl: reply.reportUrl } : {}),
|
|
@@ -93,7 +158,7 @@ export class ReportJob {
|
|
|
93
158
|
if (this.filesDone.has(i))
|
|
94
159
|
continue;
|
|
95
160
|
try {
|
|
96
|
-
await
|
|
161
|
+
await this.upload(`/api/v1/reports/${id}/attachment?name=${encodeURIComponent(f.name)}`, f.type || 'application/octet-stream', f);
|
|
97
162
|
}
|
|
98
163
|
catch (e) {
|
|
99
164
|
if (!(e instanceof VitrinkaApiError) || !permanentStatus(e.status))
|
|
@@ -109,7 +174,7 @@ export class ReportJob {
|
|
|
109
174
|
for (const c of chunks) {
|
|
110
175
|
if (this.blobKeys.has(c.seq))
|
|
111
176
|
continue;
|
|
112
|
-
const up = await
|
|
177
|
+
const up = await this.upload(`/api/v1/reports/${id}/chunk?seq=${c.seq}`, 'application/json', c.body);
|
|
113
178
|
if (!up.blobKey)
|
|
114
179
|
throw new Error(`vitrinka: chunk ${c.seq} came back without a blob key`);
|
|
115
180
|
this.blobKeys.set(c.seq, up.blobKey);
|
|
@@ -124,7 +189,7 @@ export class ReportJob {
|
|
|
124
189
|
}));
|
|
125
190
|
while (this.rowsPosted < rows.length) {
|
|
126
191
|
const batch = rows.slice(this.rowsPosted, this.rowsPosted + EVENTS_PER_POST);
|
|
127
|
-
await
|
|
192
|
+
await this.call('POST', `/api/v1/reports/${id}/events`, { events: batch });
|
|
128
193
|
this.rowsPosted += batch.length;
|
|
129
194
|
}
|
|
130
195
|
}
|