phirepass-widgets 0.0.116 → 0.0.118
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/README.md +10 -20
- package/dist/cjs/{index-BCgmMoIq.js → index-C3v5xmUo.js} +3 -75
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/phirepass-rdp.cjs.entry.js +5 -16
- package/dist/cjs/phirepass-sftp-client.cjs.entry.js +1470 -0
- package/dist/cjs/phirepass-terminal.cjs.entry.js +4 -4
- package/dist/cjs/phirepass-widgets.cjs.js +3 -3
- package/dist/cjs/{protocol-BjOgJZ9-.js → protocol-DCBMfc2u.js} +21 -277
- package/dist/collection/collection-manifest.json +1 -3
- package/dist/collection/common/channel.js +1 -21
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +13 -36
- package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.css +0 -122
- package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.js +31 -181
- package/dist/collection/components/phirepass-terminal/phirepass-terminal.js +2 -2
- package/dist/collection/phirepass-channel_bg.wasm +0 -0
- package/dist/components/index.js +1 -1
- package/dist/components/p-CsYQJXY2.js +1 -0
- package/dist/components/phirepass-rdp.js +1 -1
- package/dist/components/phirepass-sftp-client.js +1 -1
- package/dist/components/phirepass-terminal.js +5 -5
- package/dist/esm/{index-Dd9o0CbU.js → index-BVOulYtW.js} +3 -75
- package/dist/esm/loader.js +3 -3
- package/dist/esm/phirepass-rdp.entry.js +5 -16
- package/dist/esm/phirepass-sftp-client.entry.js +1468 -0
- package/dist/esm/phirepass-terminal.entry.js +4 -4
- package/dist/esm/phirepass-widgets.js +4 -4
- package/dist/esm/{protocol-BekUePpu.js → protocol-CsYQJXY2.js} +20 -276
- package/dist/phirepass-widgets/{p-c28a9257.entry.js → p-7ea2fdbc.entry.js} +2 -2
- package/dist/phirepass-widgets/p-BVOulYtW.js +3 -0
- package/dist/phirepass-widgets/p-CsYQJXY2.js +1 -0
- package/dist/phirepass-widgets/p-c1c616ca.entry.js +1 -0
- package/dist/phirepass-widgets/p-f1bc04a8.entry.js +1 -0
- package/dist/phirepass-widgets/phirepass-channel_bg.wasm +0 -0
- package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
- package/dist/types/common/channel.d.ts +0 -30
- package/dist/types/components/phirepass-rdp/phirepass-rdp.d.ts +0 -10
- package/dist/types/components/phirepass-sftp-client/phirepass-sftp-client.d.ts +0 -30
- package/dist/types/components.d.ts +34 -434
- package/package.json +5 -19
- package/dist/cjs/phirepass-downloader_3.cjs.entry.js +0 -3812
- package/dist/collection/common/fetch.js +0 -44
- package/dist/collection/components/phirepass-downloader/form.js +0 -69
- package/dist/collection/components/phirepass-downloader/format.js +0 -105
- package/dist/collection/components/phirepass-downloader/jobs.js +0 -393
- package/dist/collection/components/phirepass-downloader/phirepass-downloader.css +0 -1109
- package/dist/collection/components/phirepass-downloader/phirepass-downloader.js +0 -1455
- package/dist/collection/components/phirepass-downloader/source.js +0 -120
- package/dist/collection/components/phirepass-downloader/views/dialogs.js +0 -34
- package/dist/collection/components/phirepass-downloader/views/fetch-form.js +0 -65
- package/dist/collection/components/phirepass-downloader/views/icons.js +0 -34
- package/dist/collection/components/phirepass-downloader/views/job-row.js +0 -91
- package/dist/collection/components/phirepass-downloader/views/notices.js +0 -15
- package/dist/collection/components/phirepass-downloader/views/states.js +0 -19
- package/dist/collection/components/phirepass-media-player/phirepass-media-player.css +0 -225
- package/dist/collection/components/phirepass-media-player/phirepass-media-player.js +0 -549
- package/dist/collection/components/phirepass-media-player/player.js +0 -118
- package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.fetch.js +0 -35
- package/dist/collection/testing/fixtures.js +0 -219
- package/dist/collection/testing/mock-channel.js +0 -410
- package/dist/components/p-5QoAejYG.js +0 -1
- package/dist/components/p-BekUePpu.js +0 -1
- package/dist/components/p-DIf-Ru26.js +0 -1
- package/dist/components/phirepass-downloader.d.ts +0 -11
- package/dist/components/phirepass-downloader.js +0 -1
- package/dist/components/phirepass-media-player.d.ts +0 -11
- package/dist/components/phirepass-media-player.js +0 -1
- package/dist/esm/phirepass-downloader_3.entry.js +0 -3808
- package/dist/phirepass-widgets/p-70a67e4d.entry.js +0 -1
- package/dist/phirepass-widgets/p-BekUePpu.js +0 -1
- package/dist/phirepass-widgets/p-Dd9o0CbU.js +0 -3
- package/dist/phirepass-widgets/p-ab33f71f.entry.js +0 -1
- package/dist/types/common/fetch.d.ts +0 -167
- package/dist/types/components/phirepass-downloader/form.d.ts +0 -54
- package/dist/types/components/phirepass-downloader/format.d.ts +0 -17
- package/dist/types/components/phirepass-downloader/jobs.d.ts +0 -123
- package/dist/types/components/phirepass-downloader/phirepass-downloader.d.ts +0 -231
- package/dist/types/components/phirepass-downloader/source.d.ts +0 -61
- package/dist/types/components/phirepass-downloader/views/dialogs.d.ts +0 -52
- package/dist/types/components/phirepass-downloader/views/fetch-form.d.ts +0 -31
- package/dist/types/components/phirepass-downloader/views/icons.d.ts +0 -5
- package/dist/types/components/phirepass-downloader/views/job-row.d.ts +0 -21
- package/dist/types/components/phirepass-downloader/views/notices.d.ts +0 -18
- package/dist/types/components/phirepass-downloader/views/states.d.ts +0 -38
- package/dist/types/components/phirepass-media-player/phirepass-media-player.d.ts +0 -82
- package/dist/types/components/phirepass-media-player/player.d.ts +0 -53
- package/dist/types/components/phirepass-sftp-client/phirepass-sftp-client.fetch.d.ts +0 -40
- package/dist/types/testing/fixtures.d.ts +0 -25
- package/dist/types/testing/mock-channel.d.ts +0 -132
|
@@ -1,3812 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-BCgmMoIq.js');
|
|
4
|
-
var protocol = require('./protocol-BjOgJZ9-.js');
|
|
5
|
-
|
|
6
|
-
const DOWNLOAD_METHODS = [
|
|
7
|
-
'send_download_start',
|
|
8
|
-
'send_download_stop',
|
|
9
|
-
'send_download_resume',
|
|
10
|
-
'send_download_set_order',
|
|
11
|
-
'send_download_delete',
|
|
12
|
-
'send_download_subscribe',
|
|
13
|
-
'send_download_where',
|
|
14
|
-
];
|
|
15
|
-
/**
|
|
16
|
-
* Whether this channel can speak Remote Fetch. A channel built from a
|
|
17
|
-
* `phirepass-channel` release older than T1.10 cannot, and the widgets then
|
|
18
|
-
* keep the feature out of sight instead of offering buttons that do nothing.
|
|
19
|
-
* The folder picker's method is optional (phase 4) and checked where used.
|
|
20
|
-
*/
|
|
21
|
-
function supportsDownloads(channel) {
|
|
22
|
-
if (!channel || typeof channel !== 'object') {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return DOWNLOAD_METHODS.every(name => typeof channel[name] === 'function');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Remote Fetch: the browser side of `common/src/protocol/fetch.rs` and the
|
|
30
|
-
* `Download*` web frames (codes 56–68).
|
|
31
|
-
*
|
|
32
|
-
* Shapes follow serde's defaults as the WASM channel hands them to JS: unit
|
|
33
|
-
* enums by name, data-carrying enums externally tagged (`{ Http: { … } }`).
|
|
34
|
-
* Unit enums that may grow end in `Unknown`, as on the Rust side, so a newer
|
|
35
|
-
* server never breaks an older widget.
|
|
36
|
-
*
|
|
37
|
-
* A Rust `None` reaches JS as `undefined` (the field is absent), not `null`,
|
|
38
|
-
* even where a type below says `| null`. Read optional fields with `??` or a
|
|
39
|
-
* truthiness check, never `=== null`. Checked against the real channel build.
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* `msg_id`s `<phirepass-downloader>` mints start here, so a host sharing its
|
|
43
|
-
* channel (the SFTP client) can tell which `Error` frames to hand over
|
|
44
|
-
* without bookkeeping. `msg_id` is a u32 on the wire.
|
|
45
|
-
*/
|
|
46
|
-
const DOWNLOADER_MSG_ID_BASE = 0x4000_0000;
|
|
47
|
-
/** Largest `.torrent` accepted from the browser. Mirrors `FETCH_TORRENT_MAX_BYTES`. */
|
|
48
|
-
const FETCH_TORRENT_MAX_BYTES = 2 * 1024 * 1024;
|
|
49
|
-
const DOWNLOAD_FRAME_TYPES = new Set(['DownloadProgress', 'DownloadAccepted', 'DownloadWhereAnswer', 'DownloadCaps', 'DownloadFoldersAnswer']);
|
|
50
|
-
/** True for the frames a host should hand to `<phirepass-downloader>`. */
|
|
51
|
-
function isDownloadFrame(web) {
|
|
52
|
-
return DOWNLOAD_FRAME_TYPES.has(web.type);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Header names a link login may not set: they belong to the transfer itself or
|
|
56
|
-
* to the connection, and the agent refuses them too.
|
|
57
|
-
*/
|
|
58
|
-
const DENIED_AUTH_HEADERS = new Set([
|
|
59
|
-
'host',
|
|
60
|
-
'content-length',
|
|
61
|
-
'range',
|
|
62
|
-
'if-range',
|
|
63
|
-
'transfer-encoding',
|
|
64
|
-
'connection',
|
|
65
|
-
'keep-alive',
|
|
66
|
-
'proxy-authenticate',
|
|
67
|
-
'proxy-authorization',
|
|
68
|
-
'te',
|
|
69
|
-
'trailer',
|
|
70
|
-
'upgrade',
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
74
|
-
/** `356 MB`, `4.31 GB`, `2 KB`. Decimal units, as the mockups and disk tools use. */
|
|
75
|
-
function formatBytes(bytes) {
|
|
76
|
-
if (bytes === null || bytes === undefined || !Number.isFinite(bytes) || bytes < 0) {
|
|
77
|
-
return '—';
|
|
78
|
-
}
|
|
79
|
-
let value = bytes;
|
|
80
|
-
let unit = 0;
|
|
81
|
-
while (value >= 1000 && unit < UNITS.length - 1) {
|
|
82
|
-
value /= 1000;
|
|
83
|
-
unit++;
|
|
84
|
-
}
|
|
85
|
-
if (unit === 0) {
|
|
86
|
-
return `${Math.round(value)} B`;
|
|
87
|
-
}
|
|
88
|
-
// 812 MB, 11.8 MB, 4.31 GB, 1.2 KB: more digits only where a unit is coarse.
|
|
89
|
-
const digits = value >= 100 ? 0 : value >= 10 ? 1 : unit >= 3 ? 2 : 1;
|
|
90
|
-
const text = value.toFixed(digits);
|
|
91
|
-
// Trim trailing zeros: "2.00 GB" reads as "2 GB".
|
|
92
|
-
return `${digits ? text.replace(/\.?0+$/, '') : text} ${UNITS[unit]}`;
|
|
93
|
-
}
|
|
94
|
-
/** `↓ 11.8 MB/s`. A rate of zero shows nothing worth reading, so it returns ''. */
|
|
95
|
-
function formatRate(bps, arrow = '↓') {
|
|
96
|
-
if (!bps || bps <= 0) {
|
|
97
|
-
return '';
|
|
98
|
-
}
|
|
99
|
-
return `${arrow} ${formatBytes(bps)}/s`;
|
|
100
|
-
}
|
|
101
|
-
/** `48s`, `3m 40s`, `12m`, `2h 5m`. */
|
|
102
|
-
function formatDuration(totalSeconds) {
|
|
103
|
-
const s = Math.max(0, Math.round(totalSeconds));
|
|
104
|
-
if (s < 60) {
|
|
105
|
-
return `${s}s`;
|
|
106
|
-
}
|
|
107
|
-
const m = Math.floor(s / 60);
|
|
108
|
-
if (m < 10) {
|
|
109
|
-
const rest = s % 60;
|
|
110
|
-
return rest ? `${m}m ${rest}s` : `${m}m`;
|
|
111
|
-
}
|
|
112
|
-
if (m < 60) {
|
|
113
|
-
return `${m}m`;
|
|
114
|
-
}
|
|
115
|
-
const h = Math.floor(m / 60);
|
|
116
|
-
const rm = m % 60;
|
|
117
|
-
if (h < 24) {
|
|
118
|
-
return rm ? `${h}h ${rm}m` : `${h}h`;
|
|
119
|
-
}
|
|
120
|
-
const d = Math.floor(h / 24);
|
|
121
|
-
return `${d}d ${h % 24}h`;
|
|
122
|
-
}
|
|
123
|
-
/** Time left at the current rate, or '' when it cannot be told. */
|
|
124
|
-
function formatEta(done, total, bps) {
|
|
125
|
-
if (!total || !bps || bps <= 0 || done >= total) {
|
|
126
|
-
return '';
|
|
127
|
-
}
|
|
128
|
-
return `${formatDuration((total - done) / bps)} left`;
|
|
129
|
-
}
|
|
130
|
-
/** `38.7%`. One decimal under 100, none at 100. */
|
|
131
|
-
function formatPercent(done, total) {
|
|
132
|
-
if (!total || total <= 0) {
|
|
133
|
-
return '';
|
|
134
|
-
}
|
|
135
|
-
const pct = Math.min(100, (done / total) * 100);
|
|
136
|
-
return pct >= 100 ? '100%' : `${pct.toFixed(1)}%`;
|
|
137
|
-
}
|
|
138
|
-
function percent(done, total) {
|
|
139
|
-
if (!total || total <= 0) {
|
|
140
|
-
return 0;
|
|
141
|
-
}
|
|
142
|
-
return Math.max(0, Math.min(100, (done / total) * 100));
|
|
143
|
-
}
|
|
144
|
-
/** Media clock: `2:31`, `1:02:09`. */
|
|
145
|
-
function formatClock(seconds) {
|
|
146
|
-
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
147
|
-
return '0:00';
|
|
148
|
-
}
|
|
149
|
-
const s = Math.floor(seconds);
|
|
150
|
-
const h = Math.floor(s / 3600);
|
|
151
|
-
const m = Math.floor((s % 3600) / 60);
|
|
152
|
-
const sec = String(s % 60).padStart(2, '0');
|
|
153
|
-
return h ? `${h}:${String(m).padStart(2, '0')}:${sec}` : `${m}:${sec}`;
|
|
154
|
-
}
|
|
155
|
-
/** `13 Nov`. */
|
|
156
|
-
function formatDay(ms) {
|
|
157
|
-
const d = new Date(ms);
|
|
158
|
-
return `${d.getDate()} ${d.toLocaleString('en-GB', { month: 'short' })}`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function lastSegment(pathname) {
|
|
162
|
-
const parts = pathname.split('/').filter(Boolean);
|
|
163
|
-
const last = parts[parts.length - 1] ?? '';
|
|
164
|
-
try {
|
|
165
|
-
return decodeURIComponent(last);
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
return last;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Works out what was pasted into the Fetch field, as the person types.
|
|
173
|
-
*
|
|
174
|
-
* Only `http:`, `https:` and `magnet:` are links here; anything else is
|
|
175
|
-
* `invalid` (B4). The name is a guess for the Save as placeholder and the
|
|
176
|
-
* “Saved under another name” notice. The node has the last word.
|
|
177
|
-
*/
|
|
178
|
-
function detectSource(text) {
|
|
179
|
-
const value = text.trim();
|
|
180
|
-
if (!value) {
|
|
181
|
-
return { kind: 'empty' };
|
|
182
|
-
}
|
|
183
|
-
if (/^magnet:\?/i.test(value)) {
|
|
184
|
-
const query = value.slice(value.indexOf('?') + 1);
|
|
185
|
-
const params = new URLSearchParams(query);
|
|
186
|
-
const xt = params.getAll('xt').find(x => /^urn:btih:/i.test(x));
|
|
187
|
-
if (!xt) {
|
|
188
|
-
return { kind: 'invalid' };
|
|
189
|
-
}
|
|
190
|
-
const infoHash = xt.slice('urn:btih:'.length);
|
|
191
|
-
const dn = params.get('dn')?.trim();
|
|
192
|
-
return { kind: 'magnet', uri: value, infoHash, ...(dn ? { name: dn } : {}) };
|
|
193
|
-
}
|
|
194
|
-
let url;
|
|
195
|
-
try {
|
|
196
|
-
url = new URL(value);
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
return { kind: 'invalid' };
|
|
200
|
-
}
|
|
201
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
202
|
-
return { kind: 'invalid' };
|
|
203
|
-
}
|
|
204
|
-
if (!url.hostname) {
|
|
205
|
-
return { kind: 'invalid' };
|
|
206
|
-
}
|
|
207
|
-
// The agent refuses credentials in the URL; say so here instead of after Start.
|
|
208
|
-
if (url.username || url.password) {
|
|
209
|
-
return { kind: 'invalid' };
|
|
210
|
-
}
|
|
211
|
-
const scheme = url.protocol === 'https:' ? 'HTTPS' : 'HTTP';
|
|
212
|
-
const name = lastSegment(url.pathname) || 'download';
|
|
213
|
-
const kind = /\.torrent$/i.test(url.pathname) ? 'torrent-url' : 'http';
|
|
214
|
-
return { kind, url: value, host: url.hostname, name, scheme };
|
|
215
|
-
}
|
|
216
|
-
/** Short form of a magnet for a row title before its metadata arrives: `magnet:?xt=urn:btih:9f2c…a41e`. */
|
|
217
|
-
function shortMagnet(uri) {
|
|
218
|
-
const m = /urn:btih:([a-z0-9]+)/i.exec(uri);
|
|
219
|
-
if (!m) {
|
|
220
|
-
return uri.length > 40 ? `${uri.slice(0, 37)}…` : uri;
|
|
221
|
-
}
|
|
222
|
-
const hash = m[1];
|
|
223
|
-
return `magnet:?xt=urn:btih:${hash.slice(0, 4)}…${hash.slice(-4)}`;
|
|
224
|
-
}
|
|
225
|
-
/** Refuses a `.torrent` in the browser, before anything is sent (B6). */
|
|
226
|
-
function checkTorrentFile(file) {
|
|
227
|
-
if (!/\.torrent$/i.test(file.name)) {
|
|
228
|
-
return { ok: false, reason: 'not-torrent' };
|
|
229
|
-
}
|
|
230
|
-
if (file.size > FETCH_TORRENT_MAX_BYTES) {
|
|
231
|
-
return { ok: false, reason: 'too-large' };
|
|
232
|
-
}
|
|
233
|
-
return { ok: true };
|
|
234
|
-
}
|
|
235
|
-
const EMPTY_AUTH = { mode: 'none', username: '', password: '', token: '', headerName: '', headerValue: '' };
|
|
236
|
-
/**
|
|
237
|
-
* Turns the login fields into the `SourceAuth` the node seals, or explains
|
|
238
|
-
* what is missing. `null` with no error means no login.
|
|
239
|
-
*/
|
|
240
|
-
function buildSourceAuth(form) {
|
|
241
|
-
// The node refuses these too (`SourceAuth::problem`); this answers sooner.
|
|
242
|
-
const breaks = (...values) => values.some(v => /[\r\n\0]/.test(v));
|
|
243
|
-
switch (form.mode) {
|
|
244
|
-
case 'none':
|
|
245
|
-
return { auth: null };
|
|
246
|
-
case 'basic':
|
|
247
|
-
if (!form.username) {
|
|
248
|
-
return { auth: null, error: 'Enter a username.' };
|
|
249
|
-
}
|
|
250
|
-
if (form.username.includes(':')) {
|
|
251
|
-
return { auth: null, error: 'A username cannot contain a colon.' };
|
|
252
|
-
}
|
|
253
|
-
if (breaks(form.username, form.password)) {
|
|
254
|
-
return { auth: null, error: 'A login cannot contain line breaks.' };
|
|
255
|
-
}
|
|
256
|
-
return { auth: { Basic: { username: form.username, password: form.password } } };
|
|
257
|
-
case 'bearer':
|
|
258
|
-
if (!form.token.trim()) {
|
|
259
|
-
return { auth: null, error: 'Enter a token.' };
|
|
260
|
-
}
|
|
261
|
-
if (breaks(form.token)) {
|
|
262
|
-
return { auth: null, error: 'A login cannot contain line breaks.' };
|
|
263
|
-
}
|
|
264
|
-
return { auth: { Bearer: { token: form.token.trim() } } };
|
|
265
|
-
case 'header': {
|
|
266
|
-
const name = form.headerName.trim();
|
|
267
|
-
if (!/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(name)) {
|
|
268
|
-
return { auth: null, error: 'Enter a valid header name.' };
|
|
269
|
-
}
|
|
270
|
-
if (DENIED_AUTH_HEADERS.has(name.toLowerCase())) {
|
|
271
|
-
return { auth: null, error: `${name} cannot be set here.` };
|
|
272
|
-
}
|
|
273
|
-
if (breaks(form.headerValue)) {
|
|
274
|
-
return { auth: null, error: 'A login cannot contain line breaks.' };
|
|
275
|
-
}
|
|
276
|
-
return { auth: { Header: { name, value: form.headerValue } } };
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const EMPTY_FORM = { text: '', saveAs: '', torrent: null, order: null, auth: EMPTY_AUTH, authOpen: false };
|
|
282
|
-
function chooseTorrent(file) {
|
|
283
|
-
const check = checkTorrentFile(file);
|
|
284
|
-
return check.ok ? { name: file.name, size: file.size } : { name: file.name, size: file.size, error: check.reason };
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Everything the Fetch dialog shows that follows from what was typed or
|
|
288
|
-
* chosen: which fields appear, which note (B4–B7), and whether Start works.
|
|
289
|
-
* `ready` is false while the dialog still waits on something outside the form
|
|
290
|
-
* (where the file will land, or the Start already in flight).
|
|
291
|
-
*/
|
|
292
|
-
function formModel(form, caps, ready) {
|
|
293
|
-
const detected = form.torrent ? { kind: 'empty' } : detectSource(form.text);
|
|
294
|
-
const isTorrent = !!form.torrent || detected.kind === 'magnet';
|
|
295
|
-
const torrentsOff = isTorrent && !!caps && !caps.torrents;
|
|
296
|
-
const isHttp = detected.kind === 'http' || detected.kind === 'torrent-url';
|
|
297
|
-
let note = null;
|
|
298
|
-
if (form.torrent?.error === 'too-large') {
|
|
299
|
-
note = { tone: 'err', title: 'Too large', body: 'A .torrent file can be up to 2 MB. Use its magnet link instead.' };
|
|
300
|
-
}
|
|
301
|
-
else if (form.torrent?.error === 'not-torrent') {
|
|
302
|
-
note = { tone: 'err', title: 'Not a .torrent', body: 'Choose a file that ends in .torrent.' };
|
|
303
|
-
}
|
|
304
|
-
else if (detected.kind === 'invalid') {
|
|
305
|
-
note = { tone: 'err', title: 'Not a link', body: 'Use http://, https:// or magnet:' };
|
|
306
|
-
}
|
|
307
|
-
else if (torrentsOff) {
|
|
308
|
-
note = { tone: 'warn', title: 'Torrents are off', body: "This node only allows ordinary links. Its owner can allow torrents in the node's settings." };
|
|
309
|
-
}
|
|
310
|
-
const auth = buildSourceAuth(form.auth);
|
|
311
|
-
const hasSource = isHttp || detected.kind === 'magnet' || (!!form.torrent && !form.torrent.error && !!form.torrent.contents);
|
|
312
|
-
const needsOrder = isTorrent && !torrentsOff;
|
|
313
|
-
const canStart = ready && !!caps && hasSource && !note && (!needsOrder || form.order !== null) && (!isHttp || !form.authOpen || !auth.error);
|
|
314
|
-
let askedName;
|
|
315
|
-
if (isHttp) {
|
|
316
|
-
askedName = form.saveAs.trim() || detected.name;
|
|
317
|
-
}
|
|
318
|
-
else if (detected.kind === 'magnet') {
|
|
319
|
-
askedName = detected.name;
|
|
320
|
-
}
|
|
321
|
-
const typed = form.auth.username || form.auth.token || form.auth.headerName || form.auth.headerValue;
|
|
322
|
-
const authError = isHttp && form.authOpen && typed ? auth.error : undefined;
|
|
323
|
-
return { detected, isTorrent, needsOrder, showSaveAs: detected.kind === 'http', showAuth: isHttp, note, canStart, askedName, authError };
|
|
324
|
-
}
|
|
325
|
-
/** The `FetchSource`, order and options a valid form starts. */
|
|
326
|
-
function buildStart(form) {
|
|
327
|
-
const options = { source_auth: null, ignore_window: false };
|
|
328
|
-
if (form.torrent) {
|
|
329
|
-
if (!form.torrent.contents || form.torrent.error) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
return { source: { TorrentFile: { name: form.torrent.name, contents: form.torrent.contents } }, inOrder: form.order === 'in', options };
|
|
333
|
-
}
|
|
334
|
-
const detected = detectSource(form.text);
|
|
335
|
-
if (detected.kind === 'magnet') {
|
|
336
|
-
return { source: { Magnet: { uri: detected.uri } }, inOrder: form.order === 'in', options };
|
|
337
|
-
}
|
|
338
|
-
if (detected.kind === 'http' || detected.kind === 'torrent-url') {
|
|
339
|
-
const auth = form.authOpen ? buildSourceAuth(form.auth) : { auth: null };
|
|
340
|
-
if ('error' in auth && auth.error) {
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
const saveAs = form.saveAs.trim();
|
|
344
|
-
// A link always downloads front to back.
|
|
345
|
-
return { source: { Http: { url: detected.url, save_as: saveAs || null } }, inOrder: true, options: { ...options, source_auth: auth.auth } };
|
|
346
|
-
}
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/** Ends of a download where it stops moving by itself. */
|
|
351
|
-
const FINISHED = new Set(['Completed', 'Seeding']);
|
|
352
|
-
function isFinished(state) {
|
|
353
|
-
return FINISHED.has(state);
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Folds one `DownloadProgress` into the rows.
|
|
357
|
-
*
|
|
358
|
-
* `completed` is set only the first time a job reaches Completed or Seeding
|
|
359
|
-
* from anything else: a re-sent Completed (after a reconnect, or the snapshot a
|
|
360
|
-
* fresh subscription gets) is not a second completion. A job first seen already
|
|
361
|
-
* finished is not one either. `Deleted` removes the row.
|
|
362
|
-
*/
|
|
363
|
-
function applyProgress(prev, job) {
|
|
364
|
-
const before = prev[job.download_id];
|
|
365
|
-
if (job.state === 'Deleted') {
|
|
366
|
-
if (!before) {
|
|
367
|
-
return { jobs: prev, first: false };
|
|
368
|
-
}
|
|
369
|
-
const { [job.download_id]: _gone, ...rest } = prev;
|
|
370
|
-
return { jobs: rest, first: false };
|
|
371
|
-
}
|
|
372
|
-
// Once deleting, a row stays so until the node says Deleted: its own
|
|
373
|
-
// progress in between does not carry the flag.
|
|
374
|
-
const deleting = job.deleting || before?.deleting || undefined;
|
|
375
|
-
const jobs = { ...prev, [job.download_id]: { ...job, deleting } };
|
|
376
|
-
const completed = before && !isFinished(before.state) && isFinished(job.state) ? job : undefined;
|
|
377
|
-
return { jobs, completed, first: !before };
|
|
378
|
-
}
|
|
379
|
-
const ACTIVE_STATES = new Set(['Queued', 'Scheduled', 'Resolving', 'FetchingMetadata', 'Downloading', 'Verifying', 'Paused', 'Stopped', 'Unknown']);
|
|
380
|
-
/**
|
|
381
|
-
* A finished torrent whose seeding was stopped. Its files are whole and
|
|
382
|
-
* Resume seeds again, so it stays with the finished rows. The agent keeps
|
|
383
|
-
* `seeding_since` through a Stop, which is what tells it apart from a
|
|
384
|
-
* download stopped half-way.
|
|
385
|
-
*/
|
|
386
|
-
function isPausedSeeding(row) {
|
|
387
|
-
return row.state === 'Stopped' && row.kind === 'Torrent' && !!row.seeding_since;
|
|
388
|
-
}
|
|
389
|
-
function tabOf(row) {
|
|
390
|
-
if (row.state === 'Retrying') {
|
|
391
|
-
return 'retrying';
|
|
392
|
-
}
|
|
393
|
-
if (isPausedSeeding(row)) {
|
|
394
|
-
return 'finished';
|
|
395
|
-
}
|
|
396
|
-
if (ACTIVE_STATES.has(row.state)) {
|
|
397
|
-
return 'active';
|
|
398
|
-
}
|
|
399
|
-
return 'finished';
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Jobs working towards their bytes: what the badge and “N active” count.
|
|
403
|
-
* A Retrying job is waiting out its backoff, so it is not counted (mockup A
|
|
404
|
-
* shows 3 active beside a retrying row); it has its own tab instead.
|
|
405
|
-
*/
|
|
406
|
-
function isRunning(row) {
|
|
407
|
-
return ['Queued', 'Scheduled', 'Resolving', 'FetchingMetadata', 'Downloading', 'Verifying', 'Paused'].includes(row.state);
|
|
408
|
-
}
|
|
409
|
-
/** Rows “Clear finished” deletes: Completed and Cancelled, never a seeding torrent. */
|
|
410
|
-
function isClearable(row) {
|
|
411
|
-
return (row.state === 'Completed' || row.state === 'Cancelled') && !row.deleting;
|
|
412
|
-
}
|
|
413
|
-
const ORDER = {
|
|
414
|
-
Downloading: 0,
|
|
415
|
-
Verifying: 1,
|
|
416
|
-
FetchingMetadata: 2,
|
|
417
|
-
Resolving: 3,
|
|
418
|
-
Paused: 4,
|
|
419
|
-
Queued: 5,
|
|
420
|
-
Scheduled: 6,
|
|
421
|
-
Retrying: 7,
|
|
422
|
-
Stopped: 8,
|
|
423
|
-
Seeding: 9,
|
|
424
|
-
Completed: 10,
|
|
425
|
-
Cancelled: 11,
|
|
426
|
-
Deleted: 12,
|
|
427
|
-
Unknown: 13,
|
|
428
|
-
};
|
|
429
|
-
/** Active work first, newest first within a state; finished rows by when they finished. */
|
|
430
|
-
function sortRows(rows) {
|
|
431
|
-
return [...rows].sort((a, b) => ORDER[a.state] - ORDER[b.state] || (b.finished_at ?? b.started_at) - (a.finished_at ?? a.started_at));
|
|
432
|
-
}
|
|
433
|
-
function summarize(rows) {
|
|
434
|
-
const running = rows.filter(isRunning);
|
|
435
|
-
const downBps = running.reduce((n, r) => n + (r.down_bps || 0), 0);
|
|
436
|
-
const sized = running.filter(r => r.total_bytes);
|
|
437
|
-
const done = sized.reduce((n, r) => n + r.done_bytes, 0);
|
|
438
|
-
const total = sized.reduce((n, r) => n + (r.total_bytes ?? 0), 0);
|
|
439
|
-
return { active: running.length, downBps, done, total, percent: total ? (done / total) * 100 : null };
|
|
440
|
-
}
|
|
441
|
-
// ---- playback ----
|
|
442
|
-
const MEDIA_EXT = /\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;
|
|
443
|
-
function isMediaName(name) {
|
|
444
|
-
return MEDIA_EXT.test(name);
|
|
445
|
-
}
|
|
446
|
-
/** The file a player opens: the largest media file, which is the one the in-order reader follows. */
|
|
447
|
-
function mediaFile(row) {
|
|
448
|
-
const media = row.files.filter(f => f.media || isMediaName(f.name));
|
|
449
|
-
if (media.length) {
|
|
450
|
-
return media.reduce((a, b) => (b.size > a.size ? b : a));
|
|
451
|
-
}
|
|
452
|
-
if (!row.files.length && isMediaName(row.name)) {
|
|
453
|
-
return { index: 0, name: row.name, size: row.total_bytes ?? 0, done_bytes: row.done_bytes, media: true, ready_from_start: row.in_order ? row.done_bytes : 0 };
|
|
454
|
-
}
|
|
455
|
-
return null;
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Play appears only for video or audio whose size is known and whose download
|
|
459
|
-
* is finished or in order. A Fastest torrent offers “Switch to in order to
|
|
460
|
-
* watch” instead; the server refuses its stream anyway (409).
|
|
461
|
-
*/
|
|
462
|
-
function playCheck(row) {
|
|
463
|
-
const file = mediaFile(row);
|
|
464
|
-
if (!file || row.deleting) {
|
|
465
|
-
return { play: false, file: null, switchToInOrder: false };
|
|
466
|
-
}
|
|
467
|
-
if (isFinished(row.state)) {
|
|
468
|
-
return { play: true, file, switchToInOrder: false };
|
|
469
|
-
}
|
|
470
|
-
const moving = ['Downloading', 'Verifying', 'Paused', 'Stopped', 'Retrying'].includes(row.state);
|
|
471
|
-
if (!moving || !file.size) {
|
|
472
|
-
return { play: false, file: null, switchToInOrder: false };
|
|
473
|
-
}
|
|
474
|
-
if (row.in_order) {
|
|
475
|
-
return { play: true, file, switchToInOrder: false };
|
|
476
|
-
}
|
|
477
|
-
// Paused seeding has nothing left to download, so switching the order
|
|
478
|
-
// would change nothing.
|
|
479
|
-
return { play: false, file: null, switchToInOrder: row.kind === 'Torrent' && !isPausedSeeding(row) };
|
|
480
|
-
}
|
|
481
|
-
function streamUrl(base, nodeId, downloadId, fileIndex) {
|
|
482
|
-
return `${base.replace(/\/+$/, '')}/api/web/stream/${encodeURIComponent(nodeId)}/${encodeURIComponent(downloadId)}/${fileIndex}`;
|
|
483
|
-
}
|
|
484
|
-
// ---- where a job saves ----
|
|
485
|
-
function joinPath(...parts) {
|
|
486
|
-
const joined = parts
|
|
487
|
-
.filter((p) => !!p)
|
|
488
|
-
.join('/')
|
|
489
|
-
.replace(/\/{2,}/g, '/');
|
|
490
|
-
return joined.length > 1 ? joined.replace(/\/+$/, '') : joined;
|
|
491
|
-
}
|
|
492
|
-
function folderOf(row) {
|
|
493
|
-
return joinPath(row.dest_root, row.sub_dir);
|
|
494
|
-
}
|
|
495
|
-
/** The path of a running link download's part file, as the SFTP listing shows it. */
|
|
496
|
-
function partPath(row) {
|
|
497
|
-
return `${joinPath(folderOf(row), row.name)}.phirepass-part`;
|
|
498
|
-
}
|
|
499
|
-
function statePill(row) {
|
|
500
|
-
if (row.deleting) {
|
|
501
|
-
return { text: 'Deleting…', tone: 'ps' };
|
|
502
|
-
}
|
|
503
|
-
if (row.waitingForNode) {
|
|
504
|
-
return { text: 'Waiting for the node', tone: 'q' };
|
|
505
|
-
}
|
|
506
|
-
switch (row.state) {
|
|
507
|
-
case 'Queued':
|
|
508
|
-
return { text: 'Queued', tone: 'q' };
|
|
509
|
-
case 'Scheduled':
|
|
510
|
-
return { text: 'Scheduled', tone: 'q' };
|
|
511
|
-
case 'Resolving':
|
|
512
|
-
return { text: 'Connecting', tone: 'meta' };
|
|
513
|
-
case 'FetchingMetadata':
|
|
514
|
-
return { text: 'Fetching metadata', tone: 'meta' };
|
|
515
|
-
case 'Downloading':
|
|
516
|
-
return { text: 'Downloading', tone: 'dl' };
|
|
517
|
-
case 'Verifying':
|
|
518
|
-
return { text: 'Checking pieces', tone: 'meta' };
|
|
519
|
-
case 'Paused':
|
|
520
|
-
return { text: row.pause_reason === 'DiskFull' ? 'Paused · disk almost full' : 'Paused', tone: 'mv' };
|
|
521
|
-
case 'Retrying':
|
|
522
|
-
return { text: 'Retrying', tone: 'mv' };
|
|
523
|
-
case 'Seeding':
|
|
524
|
-
return { text: 'Seeding', tone: 'sd' };
|
|
525
|
-
case 'Completed':
|
|
526
|
-
return { text: 'Completed', tone: 'ok' };
|
|
527
|
-
case 'Stopped':
|
|
528
|
-
return { text: isPausedSeeding(row) ? 'Seeding paused' : 'Stopped', tone: 'ps' };
|
|
529
|
-
case 'Cancelled':
|
|
530
|
-
return { text: 'Cancelled', tone: 'err' };
|
|
531
|
-
default:
|
|
532
|
-
return { text: row.state, tone: 'ps' };
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
/** The second pill on a torrent row: which order it downloads in. */
|
|
536
|
-
function orderPill(row) {
|
|
537
|
-
if (row.kind !== 'Torrent' || !['Downloading', 'Verifying', 'Paused'].includes(row.state)) {
|
|
538
|
-
return null;
|
|
539
|
-
}
|
|
540
|
-
return row.in_order ? 'In order' : 'Fastest';
|
|
541
|
-
}
|
|
542
|
-
/** The stats line under a row's bar, state by state, as mockups R and R2 draw it. */
|
|
543
|
-
function statsLine(row, ctx = {}) {
|
|
544
|
-
const now = ctx.now ?? Date.now();
|
|
545
|
-
const pct = formatPercent(row.done_bytes, row.total_bytes);
|
|
546
|
-
const sizes = row.total_bytes ? `${formatBytes(row.done_bytes)} of ${formatBytes(row.total_bytes)}` : row.done_bytes ? formatBytes(row.done_bytes) : '';
|
|
547
|
-
const out = [];
|
|
548
|
-
const push = (text, extra = {}) => text && out.push({ text, ...extra });
|
|
549
|
-
if (row.deleting) {
|
|
550
|
-
push('Waiting for the node to confirm');
|
|
551
|
-
return out;
|
|
552
|
-
}
|
|
553
|
-
if (row.waitingForNode) {
|
|
554
|
-
push('Starts when the node reports in');
|
|
555
|
-
push('It keeps going after you close this tab');
|
|
556
|
-
return out;
|
|
557
|
-
}
|
|
558
|
-
switch (row.state) {
|
|
559
|
-
case 'Queued':
|
|
560
|
-
push('Waiting for a free slot');
|
|
561
|
-
if (ctx.running) {
|
|
562
|
-
push(`${ctx.running} ${ctx.running === 1 ? 'is' : 'are'} running`);
|
|
563
|
-
}
|
|
564
|
-
break;
|
|
565
|
-
case 'Scheduled':
|
|
566
|
-
push('Waits for the download window');
|
|
567
|
-
if (row.next_attempt_at && row.next_attempt_at > now) {
|
|
568
|
-
push(`starts in ${formatDuration((row.next_attempt_at - now) / 1000)}`);
|
|
569
|
-
}
|
|
570
|
-
break;
|
|
571
|
-
case 'Resolving':
|
|
572
|
-
push(ctx.source ? `Contacting ${ctx.source}` : 'Contacting the server');
|
|
573
|
-
break;
|
|
574
|
-
case 'FetchingMetadata':
|
|
575
|
-
push('Asking peers for the torrent info');
|
|
576
|
-
push(`${row.peers} ${row.peers === 1 ? 'peer' : 'peers'}`);
|
|
577
|
-
push(formatClock((now - row.started_at) / 1000));
|
|
578
|
-
break;
|
|
579
|
-
case 'Downloading':
|
|
580
|
-
push(pct, { strong: true });
|
|
581
|
-
push(sizes);
|
|
582
|
-
push(formatRate(row.down_bps));
|
|
583
|
-
if (row.kind === 'Torrent') {
|
|
584
|
-
push(formatRate(row.up_bps, '↑'));
|
|
585
|
-
push(`${row.peers} ${row.peers === 1 ? 'peer' : 'peers'}`);
|
|
586
|
-
}
|
|
587
|
-
push(formatEta(row.done_bytes, row.total_bytes, row.down_bps));
|
|
588
|
-
if (row.restarted_from_zero) {
|
|
589
|
-
push('The file changed on the server, so it started over');
|
|
590
|
-
}
|
|
591
|
-
if (ctx.source) {
|
|
592
|
-
push(ctx.source);
|
|
593
|
-
}
|
|
594
|
-
break;
|
|
595
|
-
case 'Verifying':
|
|
596
|
-
push(pct, { strong: true });
|
|
597
|
-
push('Checking downloaded pieces after a restart');
|
|
598
|
-
push(`${formatBytes(row.done_bytes)} already on disk`);
|
|
599
|
-
break;
|
|
600
|
-
case 'Paused':
|
|
601
|
-
if (row.pause_reason === 'DiskFull') {
|
|
602
|
-
push(row.reason ?? 'Free space is below the floor');
|
|
603
|
-
push('Resumes by itself when there is room');
|
|
604
|
-
}
|
|
605
|
-
else {
|
|
606
|
-
push(pct, { strong: true });
|
|
607
|
-
push('Outside the download window');
|
|
608
|
-
push('Resumes by itself');
|
|
609
|
-
}
|
|
610
|
-
break;
|
|
611
|
-
case 'Retrying':
|
|
612
|
-
push(row.retry_reason ?? row.reason ?? 'Something went wrong', { error: true });
|
|
613
|
-
push(`attempt ${row.attempt}`);
|
|
614
|
-
if (row.next_attempt_at) {
|
|
615
|
-
push(row.next_attempt_at > now ? `Next try in ${formatDuration((row.next_attempt_at - now) / 1000)}` : 'Trying again now');
|
|
616
|
-
}
|
|
617
|
-
if (row.done_bytes) {
|
|
618
|
-
push(`${formatBytes(row.done_bytes)} kept`);
|
|
619
|
-
}
|
|
620
|
-
break;
|
|
621
|
-
case 'Seeding':
|
|
622
|
-
push(formatRate(row.up_bps, '↑'));
|
|
623
|
-
push(`${formatBytes(row.up_total)} uploaded`);
|
|
624
|
-
push(`${row.peers} ${row.peers === 1 ? 'peer' : 'peers'}`);
|
|
625
|
-
if (row.seeding_since) {
|
|
626
|
-
push(`seeding for ${formatDuration((now - row.seeding_since) / 1000).replace(/ \d+[hm]$/, '')}, until you delete it`);
|
|
627
|
-
}
|
|
628
|
-
break;
|
|
629
|
-
case 'Completed': {
|
|
630
|
-
push('100%', { strong: true });
|
|
631
|
-
push(row.files.length > 1 ? `${row.files.length} files · ${formatBytes(row.total_bytes ?? row.done_bytes)}` : formatBytes(row.total_bytes ?? row.done_bytes));
|
|
632
|
-
if (row.finished_at && row.started_at) {
|
|
633
|
-
const secs = (row.finished_at - row.started_at) / 1000;
|
|
634
|
-
push(`took ${formatDuration(secs)}`);
|
|
635
|
-
if (secs > 0 && (row.total_bytes ?? row.done_bytes)) {
|
|
636
|
-
push(`avg ${formatBytes((row.total_bytes ?? row.done_bytes) / secs)}/s`);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
break;
|
|
640
|
-
}
|
|
641
|
-
case 'Stopped':
|
|
642
|
-
if (isPausedSeeding(row)) {
|
|
643
|
-
push(`${formatBytes(row.up_total)} uploaded`);
|
|
644
|
-
push(row.reason ?? 'Seeding paused by you');
|
|
645
|
-
push('Resume shares it again');
|
|
646
|
-
break;
|
|
647
|
-
}
|
|
648
|
-
push(pct, { strong: true });
|
|
649
|
-
push(row.reason ?? 'Stopped by you');
|
|
650
|
-
push('Resume continues from here');
|
|
651
|
-
break;
|
|
652
|
-
case 'Cancelled':
|
|
653
|
-
push(row.reason ?? 'Stopped and its part deleted', { error: !!row.reason });
|
|
654
|
-
push('Resume starts from zero');
|
|
655
|
-
break;
|
|
656
|
-
}
|
|
657
|
-
return out;
|
|
658
|
-
}
|
|
659
|
-
// ---- notices ----
|
|
660
|
-
/** Default longest retry wait (node setting “Longest retry wait”). */
|
|
661
|
-
const RETRY_MAX_SECS = 3600;
|
|
662
|
-
/**
|
|
663
|
-
* How long a job has been retrying, from its attempt count: 10 s doubling,
|
|
664
|
-
* capped at the node's longest wait. It ignores jitter and time spent
|
|
665
|
-
* downloading between attempts, which only makes it later, never earlier.
|
|
666
|
-
*/
|
|
667
|
-
function retryingForSecs(attempt, maxSecs = RETRY_MAX_SECS) {
|
|
668
|
-
let total = 0;
|
|
669
|
-
for (let i = 0; i < attempt; i++) {
|
|
670
|
-
total += Math.min(10 * 2 ** i, maxSecs);
|
|
671
|
-
}
|
|
672
|
-
return total;
|
|
673
|
-
}
|
|
674
|
-
const STUCK_AFTER_SECS = 24 * 3600;
|
|
675
|
-
function isStuck(row, maxSecs = RETRY_MAX_SECS) {
|
|
676
|
-
return row.state === 'Retrying' && retryingForSecs(row.attempt, maxSecs) >= STUCK_AFTER_SECS;
|
|
677
|
-
}
|
|
678
|
-
/** True when the node saved under another name than the one asked for (N4). */
|
|
679
|
-
function renamedByNode(asked, used) {
|
|
680
|
-
return !!asked && asked !== used && / \(\d+\)(\.[^.]*)?$/.test(used);
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Why nothing can be started on this node, if anything stops it (B8, B9, L3).
|
|
684
|
-
* Order matters: an agent too old to download is the first thing to fix, an
|
|
685
|
-
* organisation block outranks the node's own switch.
|
|
686
|
-
*/
|
|
687
|
-
function blockerFor(caps, nodeName, canConfigure) {
|
|
688
|
-
if (!caps.agent_supported) {
|
|
689
|
-
return {
|
|
690
|
-
id: 'too-old',
|
|
691
|
-
title: 'Too old',
|
|
692
|
-
body: `${nodeName} runs an agent that cannot download. Update the agent on that machine, then try again.`,
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
if (caps.lock === 'Organisation') {
|
|
696
|
-
return {
|
|
697
|
-
id: 'blocked',
|
|
698
|
-
title: 'Blocked',
|
|
699
|
-
body: `Your organisation does not allow downloads on ${nodeName}.`,
|
|
700
|
-
secondary: 'An owner or admin of the organisation can change this under Organisation → Downloads.',
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
if (!caps.http) {
|
|
704
|
-
return {
|
|
705
|
-
id: 'off',
|
|
706
|
-
title: 'Downloads are off',
|
|
707
|
-
body: `Downloads are turned off for ${nodeName}.`,
|
|
708
|
-
secondary: canConfigure ? "You can turn them on in the node's settings." : "Ask the node's owner to turn them on.",
|
|
709
|
-
action: canConfigure ? 'Open node settings' : undefined,
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
if (caps.lock === 'NoFolder') {
|
|
713
|
-
return {
|
|
714
|
-
id: 'no-folder',
|
|
715
|
-
title: 'No download folder',
|
|
716
|
-
body: "The download folder on this node is missing or can't be written.",
|
|
717
|
-
secondary: 'Someone who can configure the node can pick another one.',
|
|
718
|
-
action: canConfigure ? 'Open node settings' : undefined,
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
return null;
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Whether a Cancelled reason is the node's free-space check (K5), which gets
|
|
725
|
-
* its own dialog. The node words it as “needs X … has Y free” or “not enough
|
|
726
|
-
* space”; until the protocol carries a code for it, the wording decides.
|
|
727
|
-
*/
|
|
728
|
-
function isNoSpace(reason) {
|
|
729
|
-
return !!reason && /not enough (disk )?space|disk (is )?full|needs [\d.]+ ?[kmgt]?b\b.*\bfree\b/i.test(reason);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
/** Line icons shared by the downloader and the SFTP client's Fetch button. 16px, `currentColor`. */
|
|
733
|
-
// Functions, not arrays: a vnode is bound to the element it rendered, so each
|
|
734
|
-
// icon needs fresh ones.
|
|
735
|
-
const paths = {
|
|
736
|
-
fetch: () => [index.h("path", { d: "M17.5 19a4.5 4.5 0 1 0-1.4-8.8A6 6 0 0 0 4.3 12.7 4 4 0 0 0 6 19.9" }), index.h("path", { d: "M12 12v8" }), index.h("path", { d: "m8.5 16.5 3.5 3.5 3.5-3.5" })],
|
|
737
|
-
magnet: () => [index.h("path", { d: "M6 3v8a6 6 0 0 0 12 0V3" }), index.h("path", { d: "M6 7h4M14 7h4" }), index.h("path", { d: "M10 3v8a2 2 0 0 0 4 0V3" })],
|
|
738
|
-
globe: () => [index.h("circle", { cx: "12", cy: "12", r: "9" }), index.h("path", { d: "M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" })],
|
|
739
|
-
torrent: () => [index.h("path", { d: "M6 3h8l4 4v14H6z" }), index.h("path", { d: "M14 3v4h4" }), index.h("path", { d: "M9.5 11.5 12 14l2.5-2.5M12 14v3" })],
|
|
740
|
-
node: () => [index.h("rect", { x: "3", y: "4", width: "18", height: "7", rx: "1.5" }), index.h("rect", { x: "3", y: "13", width: "18", height: "7", rx: "1.5" }), index.h("path", { d: "M7 7.5h.01M7 16.5h.01" })],
|
|
741
|
-
x: () => [index.h("path", { d: "M6 6l12 12M18 6 6 18" })],
|
|
742
|
-
retry: () => [index.h("path", { d: "M3 12a9 9 0 0 0 15.4 6.4L21 16" }), index.h("path", { d: "M21 21v-5h-5" }), index.h("path", { d: "M21 12A9 9 0 0 0 5.6 5.6L3 8" }), index.h("path", { d: "M3 3v5h5" })],
|
|
743
|
-
check: () => [index.h("circle", { cx: "12", cy: "12", r: "9.5" }), index.h("path", { d: "m8 12.5 2.7 2.7L16.5 9.5" })],
|
|
744
|
-
locate: () => [index.h("path", { d: "M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2 2h8.4A1.5 1.5 0 0 1 21 8.5v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z" }), index.h("path", { d: "m11 13 2 2 3-3" })],
|
|
745
|
-
file: () => [index.h("path", { d: "M6 3h8l4 4v14H6z" }), index.h("path", { d: "M14 3v4h4" })],
|
|
746
|
-
folder: () => [index.h("path", { d: "M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2 2h8.4A1.5 1.5 0 0 1 21 8.5v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 17.5z" })],
|
|
747
|
-
warn: () => [index.h("path", { d: "M12 3 2.5 20h19z" }), index.h("path", { d: "M12 10v4.5" }), index.h("path", { d: "M12 17.5v.01" })],
|
|
748
|
-
trash: () => [index.h("path", { d: "M3 6h18" }), index.h("path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" }), index.h("path", { d: "M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6" })],
|
|
749
|
-
chevron: () => [index.h("path", { d: "m6 9 6 6 6-6" })],
|
|
750
|
-
up: () => [index.h("path", { d: "m6 15 6-6 6 6" })],
|
|
751
|
-
cast: () => [index.h("path", { d: "M3 8V6a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-5" }), index.h("path", { d: "M3 12a8 8 0 0 1 8 8" }), index.h("path", { d: "M3 16a4 4 0 0 1 4 4" }), index.h("path", { d: "M3 20h.01" })],
|
|
752
|
-
lock: () => [index.h("rect", { width: "18", height: "11", x: "3", y: "11", rx: "2" }), index.h("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" })],
|
|
753
|
-
signal: () => [index.h("path", { d: "M2 20h.01M7 20v-4M12 20v-8M17 20V8M22 4v16" })],
|
|
754
|
-
plus: () => [index.h("path", { d: "M12 5v14M5 12h14" })],
|
|
755
|
-
link: () => [index.h("path", { d: "M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7" }), index.h("path", { d: "M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7" })],
|
|
756
|
-
};
|
|
757
|
-
const filled = {
|
|
758
|
-
pause: () => [index.h("rect", { x: "6", y: "5", width: "4", height: "14", rx: "1" }), index.h("rect", { x: "14", y: "5", width: "4", height: "14", rx: "1" })],
|
|
759
|
-
play: () => [index.h("path", { d: "M7 5v14l12-7z" })],
|
|
760
|
-
};
|
|
761
|
-
const Icon = ({ name, size = 16, label }) => {
|
|
762
|
-
const fill = filled[name];
|
|
763
|
-
return (index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: size, height: size, viewBox: "0 0 24 24", fill: fill ? 'currentColor' : 'none', stroke: fill ? 'none' : 'currentColor', "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": label ? undefined : 'true', role: label ? 'img' : undefined, "aria-label": label }, (fill ?? paths[name])?.() ?? null));
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
const Modal = ({ label, onClose, wide }, children) => (index.h("div", { class: "overlay", onClick: e => {
|
|
767
|
-
if (e.target === e.currentTarget) {
|
|
768
|
-
onClose();
|
|
769
|
-
}
|
|
770
|
-
} }, index.h("div", { class: { modal: true, wide: !!wide }, role: "dialog", "aria-modal": "true", "aria-label": label, tabindex: -1, onKeyDown: e => {
|
|
771
|
-
if (e.key === 'Escape') {
|
|
772
|
-
e.stopPropagation();
|
|
773
|
-
onClose();
|
|
774
|
-
}
|
|
775
|
-
} }, children)));
|
|
776
|
-
const Footer = ({ cancel, confirm, danger, onCancel, onConfirm }) => (index.h("div", { class: "dlg-f" }, index.h("button", { type: "button", class: "btn", onClick: onCancel }, cancel), index.h("button", { type: "button", class: { btn: true, pri: !danger, dng: !!danger }, onClick: onConfirm }, confirm)));
|
|
777
|
-
/** K1: ✕ on an unfinished row. Unticked → Stopped (resumable); ticked → Cancelled. */
|
|
778
|
-
const ConfirmStop = ({ row, discard, onDiscard, ...b }) => (index.h(Modal, { label: "Stop this download?", onClose: b.onCancel }, index.h("div", { class: "dlg" }, index.h("h4", null, "Stop this download?"), index.h("div", { class: "filechip" }, index.h(Icon, { name: "file", size: 20 }), index.h("div", null, index.h("b", null, row.name), index.h("span", null, row.total_bytes ? `${formatBytes(row.done_bytes)} of ${formatBytes(row.total_bytes)} downloaded` : `${formatBytes(row.done_bytes)} downloaded`))), index.h("label", { class: "checkline" }, index.h("input", { type: "checkbox", checked: discard, onChange: e => onDiscard(e.target.checked) }), index.h("span", null, "Also delete the part already downloaded", index.h("span", { class: "hint block" }, "Leave this off and Resume continues from here."))), index.h(Footer, { cancel: "Keep downloading", confirm: "Stop download", danger: true, ...b }))));
|
|
779
|
-
/** K8: Delete on a finished, stopped or seeding row. */
|
|
780
|
-
const ConfirmDelete = ({ row, deleteFile, onDeleteFile, nodeName, ...b }) => {
|
|
781
|
-
const finished = isFinished(row.state);
|
|
782
|
-
const size = row.files.length > 1 ? `${row.files.length} files · ${formatBytes(row.total_bytes ?? row.done_bytes)}` : formatBytes(row.total_bytes ?? row.done_bytes);
|
|
783
|
-
return (index.h(Modal, { label: "Delete this download?", onClose: b.onCancel }, index.h("div", { class: "dlg" }, index.h("h4", null, "Delete this download?"), index.h("div", { class: "filechip" }, index.h(Icon, { name: "file", size: 20 }), index.h("div", null, index.h("b", null, row.name), index.h("span", null, row.state === 'Seeding' ? 'Seeding · ' : '', size, " in ", folderOf(row)))), row.state === 'Seeding' && index.h("p", { class: "dtx" }, nodeName, " stops sharing it with peers."), finished ? (index.h("label", { class: "checkline" }, index.h("input", { type: "checkbox", checked: deleteFile, onChange: e => onDeleteFile(e.target.checked) }), index.h("span", null, "Also delete the files", index.h("span", { class: "hint block" }, "Off: the files stay in ", folderOf(row), " and only the download is removed.")))) : (index.h("p", { class: "dtx" }, "The part already downloaded is deleted.")), index.h(Footer, { cancel: "Cancel", confirm: "Delete", danger: true, ...b }))));
|
|
784
|
-
};
|
|
785
|
-
/** K9: switching a torrent that is playing to Fastest stops playback. */
|
|
786
|
-
const ConfirmFastest = ({ row, ...b }) => (index.h(Modal, { label: "Switch to fastest?", onClose: b.onCancel }, index.h("div", { class: "dlg" }, index.h("h4", null, "Switch to fastest?"), index.h("p", { class: "dtx" }, index.h("b", null, row.name), " is playing. Fastest downloads pieces in any order, so playback stops until it finishes or you switch back."), index.h(Footer, { cancel: "Keep in order", confirm: "Switch and stop playback", danger: true, ...b }))));
|
|
787
|
-
/** K2: before the first magnet or .torrent on this browser. */
|
|
788
|
-
const ConfirmTorrent = ({ nodeName, dontAsk, onDontAsk, ...b }) => (index.h(Modal, { label: `Start a torrent on ${nodeName}?`, onClose: b.onCancel }, index.h("div", { class: "dlg" }, index.h("h4", null, "Start a torrent on ", nodeName, "?"), index.h("div", { class: "note warn" }, index.h(Icon, { name: "warn", size: 14 }), index.h("div", null, "The node will connect to public peers. They can see its internet address, and it uploads to them while it downloads.")), index.h("p", { class: "dtx" }, "When it finishes, ", nodeName, " keeps sharing it with other peers until you delete it."), index.h("label", { class: "checkline" }, index.h("input", { type: "checkbox", checked: dontAsk, onChange: e => onDontAsk(e.target.checked) }), index.h("span", null, "Do not ask again on this browser")), index.h(Footer, { cancel: "Cancel", confirm: "Start torrent", ...b }))));
|
|
789
|
-
/** K5: a notice, not a question. The node refused a Start that would not fit. */
|
|
790
|
-
const NoSpace = ({ reason, onClose }) => (index.h(Modal, { label: "Not enough space", onClose: onClose }, index.h("div", { class: "dlg" }, index.h("h4", null, "Not enough space"), index.h("p", { class: "dtx" }, reason), index.h("div", { class: "dlg-f" }, index.h("button", { type: "button", class: "btn pri", onClick: onClose }, "OK")))));
|
|
791
|
-
/** H6: folders inside the node's download folder, listed by the agent. */
|
|
792
|
-
const FolderPicker = (p) => (index.h(Modal, { label: "Save downloads to", onClose: p.onCancel, wide: true }, index.h("div", { class: "dlg" }, index.h("h4", null, "Save downloads to"), index.h("nav", { class: "crumbs", "aria-label": "Folder" }, index.h("button", { type: "button", class: "lnk", onClick: () => p.onUp(0) }, p.root), p.path.map((seg, i) => [
|
|
793
|
-
index.h("span", { class: "sep" }, "/"),
|
|
794
|
-
index.h("button", { type: "button", class: "lnk", onClick: () => p.onUp(i + 1) }, seg),
|
|
795
|
-
])), index.h("div", { class: "folders", role: "list" }, p.folders === null && index.h("div", { class: "muted" }, "Loading\u2026"), p.folders?.length === 0 && index.h("div", { class: "muted" }, "No folders here."), p.folders?.map(name => (index.h("button", { type: "button", class: "folder-row", role: "listitem", onClick: () => p.onOpen(name) }, index.h(Icon, { name: "folder", size: 14 }), index.h("span", null, name))))), p.error && index.h("div", { class: "note err" }, p.error), p.newName !== null && (index.h("input", { class: "inp", type: "text", "aria-label": "New folder name", placeholder: "New folder name", value: p.newName, onInput: e => p.onNewName(e.target.value) })), index.h("p", { class: "hint" }, "Folders only, and only inside the node's download folder. A new folder is created by the node when the first download lands in it."), index.h("div", { class: "dlg-f" }, index.h("button", { type: "button", class: "btn left", onClick: () => p.onNewName(p.newName === null ? '' : null) }, index.h(Icon, { name: "plus", size: 12 }), " New folder"), index.h("button", { type: "button", class: "btn", onClick: p.onCancel }, "Cancel"), index.h("button", { type: "button", class: "btn pri", disabled: p.newName !== null && !/^[^/\\\0]+$/.test(p.newName.trim()), onClick: p.onSave }, "Save here")))));
|
|
796
|
-
|
|
797
|
-
const NoteLine = ({ note }) => (index.h("div", { class: `note ${note.tone}`, role: note.tone === 'err' ? 'alert' : 'status' }, index.h(Icon, { name: "warn", size: 14 }), index.h("div", null, index.h("b", null, note.title), " ", note.body)));
|
|
798
|
-
function Detect({ model }) {
|
|
799
|
-
const d = model.detected;
|
|
800
|
-
if (d.kind === 'http' || d.kind === 'torrent-url') {
|
|
801
|
-
return (index.h("div", { class: "detect", "data-kind": d.kind }, index.h("span", { class: "pill meta" }, d.kind === 'torrent-url' ? '.torrent link' : d.scheme), index.h("span", { class: "host" }, d.host)));
|
|
802
|
-
}
|
|
803
|
-
if (d.kind === 'magnet') {
|
|
804
|
-
return (index.h("div", { class: "detect", "data-kind": "magnet" }, index.h("span", { class: "pill meta" }, "Magnet"), index.h("span", { class: "host" }, d.name ?? 'name arrives with the metadata')));
|
|
805
|
-
}
|
|
806
|
-
return index.h("div", { class: "detect" });
|
|
807
|
-
}
|
|
808
|
-
const AuthFields = ({ auth, onChange }) => {
|
|
809
|
-
const set = onChange;
|
|
810
|
-
const field = (label, key, type = 'text') => (index.h("label", { class: "fld" }, index.h("span", null, label), index.h("input", { class: "inp", type: type, autocomplete: "off", spellcheck: false, value: auth[key], onInput: e => set({ [key]: e.target.value }) })));
|
|
811
|
-
return (index.h("div", { class: "auth" }, index.h("div", { class: "seg", role: "radiogroup", "aria-label": "Login for the link" }, [
|
|
812
|
-
['none', 'No login'],
|
|
813
|
-
['basic', 'Username and password'],
|
|
814
|
-
['bearer', 'Bearer token'],
|
|
815
|
-
['header', 'Custom header'],
|
|
816
|
-
].map(([mode, label]) => (index.h("label", { class: { on: auth.mode === mode } }, index.h("input", { type: "radio", name: "auth-mode", checked: auth.mode === mode, onChange: () => set({ mode }) }), label)))), auth.mode === 'basic' && [field('Username', 'username'), field('Password', 'password', 'password')], auth.mode === 'bearer' && field('Token', 'token', 'password'), auth.mode === 'header' && [field('Header name', 'headerName'), field('Value', 'headerValue', 'password')], auth.mode !== 'none' && index.h("p", { class: "hint" }, "Sent only to this link's own site, and dropped if it redirects elsewhere. The node seals it and deletes it when the download finishes.")));
|
|
817
|
-
};
|
|
818
|
-
const OrderChoice = ({ order, onChange }) => (index.h("fieldset", { class: "order" }, index.h("legend", null, "How should it download? (required for torrents)"), index.h("label", { class: { opt: true, on: order === 'in' } }, index.h("input", { type: "radio", name: "order", value: "in", checked: order === 'in', onChange: () => onChange('in') }), index.h("span", null, index.h("b", null, "In order"), " \u00B7 watch while it downloads, a little slower")), index.h("label", { class: { opt: true, on: order === 'fast' } }, index.h("input", { type: "radio", name: "order", value: "fast", checked: order === 'fast', onChange: () => onChange('fast') }), index.h("span", null, index.h("b", null, "Fastest"), " \u00B7 any order; switch to in order later if you want to watch"))));
|
|
819
|
-
/**
|
|
820
|
-
* The add form: mockup B and its states, used as the SFTP browser's Fetch
|
|
821
|
-
* dialog (`dialog`) and as the top of the standalone downloader (`inline`).
|
|
822
|
-
*/
|
|
823
|
-
const FetchForm = (p) => {
|
|
824
|
-
const { form, model, caps } = p;
|
|
825
|
-
let fileInput;
|
|
826
|
-
const torrentsOn = !!caps?.torrents;
|
|
827
|
-
const dialog = p.layout === 'dialog';
|
|
828
|
-
const onDrop = (e) => {
|
|
829
|
-
e.preventDefault();
|
|
830
|
-
const file = e.dataTransfer?.files?.[0];
|
|
831
|
-
if (file) {
|
|
832
|
-
p.onPickTorrent(file);
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
const picker = (index.h("input", { type: "file", accept: ".torrent,application/x-bittorrent", class: "hidden-input", ref: el => (fileInput = el), onChange: e => {
|
|
836
|
-
const input = e.target;
|
|
837
|
-
const file = input.files?.[0];
|
|
838
|
-
if (file) {
|
|
839
|
-
p.onPickTorrent(file);
|
|
840
|
-
}
|
|
841
|
-
input.value = '';
|
|
842
|
-
} }));
|
|
843
|
-
const source = form.torrent ? (index.h("div", { class: { filechip: true, bad: !!form.torrent.error } }, index.h(Icon, { name: "torrent", size: 20 }), index.h("div", null, index.h("b", null, form.torrent.name), index.h("span", null, formatBytes(form.torrent.size), " \u00B7 from this computer")), index.h("button", { type: "button", class: "ib", "aria-label": "Remove the .torrent file", title: "Remove", onClick: () => p.onChange({ torrent: null, order: null }) }, index.h(Icon, { name: "x", size: 14 })))) : (index.h("div", { class: "fld" }, index.h("label", { htmlFor: "fetch-link" }, "Link or magnet"), index.h("div", { class: "inline-row" }, index.h("input", { id: "fetch-link", class: "inp", type: "text", inputMode: "url", autocomplete: "off", autocapitalize: "none", spellcheck: false, placeholder: "https://\u2026 or magnet:?xt=\u2026", value: form.text, disabled: p.starting, onInput: e => p.onChange({ text: e.target.value }), onKeyDown: e => {
|
|
844
|
-
if (e.key === 'Enter' && model.canStart) {
|
|
845
|
-
e.preventDefault();
|
|
846
|
-
p.onStart();
|
|
847
|
-
}
|
|
848
|
-
} }), !dialog && torrentsOn && (index.h("button", { type: "button", class: "btn", onClick: () => fileInput?.click() }, ".torrent\u2026")), !dialog && (index.h("button", { type: "button", class: "btn pri", disabled: !model.canStart || p.starting, onClick: () => p.onStart() }, p.starting ? 'Starting…' : 'Download'))), index.h(Detect, { model: model })));
|
|
849
|
-
return (index.h("form", { class: { 'fetch-form': true, [p.layout]: true }, onSubmit: e => {
|
|
850
|
-
e.preventDefault();
|
|
851
|
-
if (model.canStart) {
|
|
852
|
-
p.onStart();
|
|
853
|
-
}
|
|
854
|
-
}, onDragOver: e => torrentsOn && e.preventDefault(), onDrop: e => torrentsOn && onDrop(e) }, dialog && (index.h("div", { class: "dlg-h" }, index.h(Icon, { name: "fetch" }), index.h("h4", null, p.title))), picker, source, model.note && index.h(NoteLine, { note: model.note }), p.refusal && index.h(NoteLine, { note: p.refusal }), model.showSaveAs && (index.h("div", { class: "fld" }, index.h("label", { htmlFor: "fetch-save-as" }, "Save as"), index.h("input", { id: "fetch-save-as", class: "inp", type: "text", autocomplete: "off", spellcheck: false, placeholder: model.askedName, value: form.saveAs, disabled: p.starting, onInput: e => p.onChange({ saveAs: e.target.value }) }), index.h("span", { class: "hint" }, "Taken from the server's filename when it sends one. An existing file is never overwritten; the new one gets \u201C(1)\u201D added."))), model.showAuth && (index.h("div", { class: "login" }, index.h("button", { type: "button", class: "lnk", "aria-expanded": form.authOpen ? 'true' : 'false', onClick: () => p.onChange({ authOpen: !form.authOpen }) }, index.h(Icon, { name: form.authOpen ? 'up' : 'chevron', size: 12 }), " This link needs a login"), form.authOpen && index.h(AuthFields, { auth: form.auth, onChange: p.onAuth }), model.authError && (index.h("span", { class: "hint err", role: "alert" }, model.authError)))), model.needsOrder && index.h(OrderChoice, { order: form.order, onChange: order => p.onChange({ order }) }), (model.detected.kind === 'http' || model.detected.kind === 'torrent-url') && index.h("p", { class: "hint" }, "A link always downloads in order, so you can watch while it arrives."), dialog && torrentsOn && !form.torrent && [
|
|
855
|
-
index.h("div", { class: "or" }, "or"),
|
|
856
|
-
index.h("button", { type: "button", class: "drop", onClick: () => fileInput?.click() }, index.h(Icon, { name: "torrent", size: 22 }), index.h("span", null, index.h("b", null, "Choose a .torrent file"), " or drop it here", index.h("br", null), index.h("span", { class: "hint" }, "Up to 2 MB, read in the browser and sent to the node"))),
|
|
857
|
-
], p.destination && (index.h("div", { class: "fld" }, dialog && index.h("label", null, "Destination"), index.h("div", { class: "dest-row" }, index.h("div", { class: "dest", title: p.destination.path }, index.h(Icon, { name: "folder", size: 14 }), index.h("span", null, p.destination.path)), p.onChooseFolder && (index.h("button", { type: "button", class: "btn", onClick: () => p.onChooseFolder?.() }, "Choose folder\u2026"))), p.destination.hint && index.h("span", { class: "hint where" }, p.destination.hint))), dialog && (index.h("div", { class: "dlg-f" }, index.h("button", { type: "button", class: "btn", onClick: () => p.onCancel?.() }, "Cancel"), index.h("button", { type: "submit", class: "btn pri", disabled: !model.canStart || p.starting }, p.starting ? 'Starting…' : 'Start download')))));
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
function kindIcon(row) {
|
|
861
|
-
if (row.kind === 'Torrent') {
|
|
862
|
-
return { icon: row.name.startsWith('magnet:') ? 'magnet' : 'torrent', tone: 't' };
|
|
863
|
-
}
|
|
864
|
-
if (row.kind === 'Node') {
|
|
865
|
-
return { icon: 'node', tone: 'n' };
|
|
866
|
-
}
|
|
867
|
-
return { icon: 'globe', tone: 'h' };
|
|
868
|
-
}
|
|
869
|
-
function barClass(row) {
|
|
870
|
-
if (row.state === 'FetchingMetadata' || row.state === 'Resolving') {
|
|
871
|
-
return 'bar indet';
|
|
872
|
-
}
|
|
873
|
-
if (row.state === 'Retrying' || row.state === 'Paused') {
|
|
874
|
-
return 'bar moving';
|
|
875
|
-
}
|
|
876
|
-
if (row.state === 'Stopped' || row.state === 'Queued' || row.state === 'Scheduled' || row.deleting) {
|
|
877
|
-
return 'bar paused';
|
|
878
|
-
}
|
|
879
|
-
if (row.state === 'Cancelled') {
|
|
880
|
-
return 'bar fail';
|
|
881
|
-
}
|
|
882
|
-
if (row.state === 'Seeding') {
|
|
883
|
-
return 'bar seed';
|
|
884
|
-
}
|
|
885
|
-
return 'bar';
|
|
886
|
-
}
|
|
887
|
-
const Btn = ({ icon, label, onClick, primary }) => (index.h("button", { type: "button", class: { ib: true, new: !!primary }, title: label, "aria-label": label, onClick: onClick }, index.h(Icon, { name: icon, size: 14 })));
|
|
888
|
-
/**
|
|
889
|
-
* One download, in any state (mockups R and R2). Which buttons show is decided
|
|
890
|
-
* by the state alone; what a button sends is the host's business.
|
|
891
|
-
*/
|
|
892
|
-
const JobRow = ({ row, actions, running, source, compact }) => {
|
|
893
|
-
const { icon, tone } = kindIcon(row);
|
|
894
|
-
const pill = statePill(row);
|
|
895
|
-
const order = orderPill(row);
|
|
896
|
-
const play = playCheck(row);
|
|
897
|
-
const stats = statsLine(row, { running, source });
|
|
898
|
-
const value = row.state === 'Completed' || row.state === 'Seeding' ? 100 : percent(row.done_bytes, row.total_bytes);
|
|
899
|
-
const buttons = [];
|
|
900
|
-
if (!row.deleting) {
|
|
901
|
-
if (play.play) {
|
|
902
|
-
buttons.push(index.h(Btn, { icon: "play", label: isFinished(row.state) ? 'Play' : 'Play while downloading', primary: true, onClick: () => actions.play(row) }));
|
|
903
|
-
}
|
|
904
|
-
switch (row.state) {
|
|
905
|
-
case 'Downloading':
|
|
906
|
-
case 'Verifying':
|
|
907
|
-
case 'Resolving':
|
|
908
|
-
case 'FetchingMetadata':
|
|
909
|
-
case 'Queued':
|
|
910
|
-
if (row.state === 'Downloading' || row.state === 'Verifying') {
|
|
911
|
-
buttons.push(index.h(Btn, { icon: "pause", label: "Pause", onClick: () => actions.pause(row) }));
|
|
912
|
-
}
|
|
913
|
-
buttons.push(index.h(Btn, { icon: "x", label: "Stop", onClick: () => actions.stop(row) }));
|
|
914
|
-
break;
|
|
915
|
-
case 'Scheduled':
|
|
916
|
-
case 'Paused':
|
|
917
|
-
if (row.state === 'Scheduled' || row.pause_reason === 'Window') {
|
|
918
|
-
buttons.push(index.h(Btn, { icon: "play", label: "Start now", onClick: () => actions.resume(row, true) }));
|
|
919
|
-
}
|
|
920
|
-
buttons.push(index.h(Btn, { icon: "x", label: "Stop", onClick: () => actions.stop(row) }));
|
|
921
|
-
break;
|
|
922
|
-
case 'Retrying':
|
|
923
|
-
buttons.push(index.h(Btn, { icon: "retry", label: "Try now", onClick: () => actions.resume(row) }));
|
|
924
|
-
buttons.push(index.h(Btn, { icon: "x", label: "Stop", onClick: () => actions.stop(row) }));
|
|
925
|
-
break;
|
|
926
|
-
case 'Stopped':
|
|
927
|
-
buttons.push(index.h(Btn, { icon: "play", label: "Resume", onClick: () => actions.resume(row) }));
|
|
928
|
-
buttons.push(index.h(Btn, { icon: "trash", label: "Delete", onClick: () => actions.remove(row) }));
|
|
929
|
-
break;
|
|
930
|
-
case 'Seeding':
|
|
931
|
-
buttons.push(index.h(Btn, { icon: "pause", label: "Pause seeding", onClick: () => actions.pause(row) }));
|
|
932
|
-
buttons.push(index.h(Btn, { icon: "locate", label: "Show in folder", onClick: () => actions.showInFolder(row) }));
|
|
933
|
-
buttons.push(index.h(Btn, { icon: "trash", label: "Delete", onClick: () => actions.remove(row) }));
|
|
934
|
-
break;
|
|
935
|
-
case 'Completed':
|
|
936
|
-
buttons.push(index.h(Btn, { icon: "locate", label: "Show in folder", onClick: () => actions.showInFolder(row) }));
|
|
937
|
-
buttons.push(index.h(Btn, { icon: "x", label: "Remove from list", onClick: () => actions.remove(row) }));
|
|
938
|
-
break;
|
|
939
|
-
case 'Cancelled':
|
|
940
|
-
buttons.push(index.h(Btn, { icon: "retry", label: "Start again", onClick: () => actions.resume(row) }));
|
|
941
|
-
buttons.push(index.h(Btn, { icon: "x", label: "Remove from list", onClick: () => actions.remove(row) }));
|
|
942
|
-
break;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
return (index.h("div", { key: row.download_id, class: { job: true, compact: !!compact }, "data-state": row.deleting ? 'Deleting' : row.state, "data-id": row.download_id, role: "listitem", "aria-label": `${row.name}, ${pill.text}` }, index.h("span", { class: `kind ${tone}` }, index.h(Icon, { name: icon, size: 15 })), index.h("div", { class: "title" }, index.h("span", { class: "nm", title: row.name }, row.name), index.h("span", { class: `pill ${pill.tone}` }, pill.text), order && index.h("span", { class: "pill meta" }, order)), index.h("div", { class: "acts" }, buttons), index.h("div", { class: barClass(row), role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round(value), "aria-label": `${row.name} progress` }, index.h("i", { style: { width: `${value}%` } })), index.h("div", { class: "stats" }, stats.map(s => (s.strong ? index.h("b", null, s.text) : index.h("span", { class: { err: !!s.error } }, s.text))), !play.play && play.switchToInOrder && (index.h("button", { type: "button", class: "lnk inline", onClick: () => actions.setOrder(row, true) }, "Switch to in order to watch")), play.play && row.kind === 'Torrent' && row.in_order && !isFinished(row.state) && (index.h("button", { type: "button", class: "lnk inline", onClick: () => actions.setOrder(row, false) }, "Switch to fastest")))));
|
|
946
|
-
};
|
|
947
|
-
|
|
948
|
-
const ICON = {
|
|
949
|
-
started: 'fetch',
|
|
950
|
-
queued: 'fetch',
|
|
951
|
-
stuck: 'warn',
|
|
952
|
-
renamed: 'file',
|
|
953
|
-
completed: 'check',
|
|
954
|
-
error: 'warn',
|
|
955
|
-
};
|
|
956
|
-
/** Small, self-dismissing notices at the bottom of the widget (N1–N4, D). */
|
|
957
|
-
const Notices = ({ notices, onDismiss }) => notices.length ? (index.h("div", { class: "toasts", "aria-live": "polite" }, notices.map(n => (index.h("div", { class: { toast: true, bad: n.kind === 'stuck' || n.kind === 'error' }, "data-notice": n.kind, key: n.id }, index.h(Icon, { name: ICON[n.kind], size: 18 }), index.h("div", { class: "t" }, index.h("b", null, n.title), index.h("span", { title: n.detail }, n.detail)), n.action && (index.h("button", { type: "button", class: "btn", onClick: () => {
|
|
958
|
-
n.action.run();
|
|
959
|
-
onDismiss(n.id);
|
|
960
|
-
} }, n.action.label)), index.h("button", { type: "button", class: "ib", "aria-label": "Dismiss", onClick: () => onDismiss(n.id) }, index.h(Icon, { name: "x", size: 12 }))))))) : null;
|
|
961
|
-
|
|
962
|
-
const Empty = ({ icon, title, body, action }) => (index.h("div", { class: "empty", role: "status" }, index.h(Icon, { name: icon, size: 28 }), index.h("b", null, title), index.h("span", null, body), action && (index.h("button", { type: "button", class: "btn pri", onClick: action.onClick }, action.label))));
|
|
963
|
-
/** X1: embedded drawer with nothing in it. */
|
|
964
|
-
const DrawerEmpty = () => (index.h(Empty, { icon: "fetch", title: "No downloads yet", body: "Press Fetch and paste a link. Downloads keep running after you close this tab, and they show here when you come back." }));
|
|
965
|
-
/** X2: standalone, first open. */
|
|
966
|
-
const StandaloneEmpty = ({ nodeName, folder }) => (index.h(Empty, { icon: "fetch", title: "Nothing downloading", body: `Paste a link above. It downloads onto ${nodeName}${folder ? `, into ${folder}` : ''}.` }));
|
|
967
|
-
/** X3: no valid session. */
|
|
968
|
-
const SignedOut = ({ onSignIn }) => (index.h(Empty, { icon: "lock", title: "Sign in to PhirePass", body: "Your downloads are tied to your account and the nodes you can reach.", action: { label: 'Sign in', onClick: onSignIn } }));
|
|
969
|
-
/** X4: the node (or the server) cannot be reached. */
|
|
970
|
-
const Unreachable = ({ nodeName, onRetry }) => (index.h(Empty, { icon: "signal", title: `Can't reach ${nodeName}`, body: "If the machine is still running, its downloads carry on. They will show here when it reconnects.", action: onRetry ? { label: 'Try again', onClick: onRetry } : undefined }));
|
|
971
|
-
/** The channel this page loaded predates Remote Fetch. */
|
|
972
|
-
const Unsupported = () => (index.h(Empty, { icon: "warn", title: "Downloads are not available here", body: "This page's connection library is too old to start downloads. Reload after the site updates." }));
|
|
973
|
-
const Loading = () => (index.h("div", { class: "empty", role: "status" }, index.h("span", { class: "spin", "aria-hidden": "true" }), index.h("span", null, "Loading downloads\u2026")));
|
|
974
|
-
/**
|
|
975
|
-
* Why nothing can be added on this node (B8, B9, L3). Shown in place of the
|
|
976
|
-
* form, in the dialog and in the standalone header alike.
|
|
977
|
-
*/
|
|
978
|
-
const BlockerView = ({ blocker, onAction, onClose }) => (index.h("div", { class: "blocker", "data-blocker": blocker.id }, index.h("div", { class: `note ${blocker.id === 'off' ? 'info' : 'warn'}`, role: "status" }, index.h(Icon, { name: blocker.id === 'off' ? 'fetch' : 'warn', size: 14 }), index.h("div", null, index.h("b", null, blocker.title), " ", blocker.body)), blocker.secondary && index.h("p", { class: "hint" }, blocker.secondary), (onClose || (blocker.action && onAction)) && (index.h("div", { class: "dlg-f" }, onClose && (index.h("button", { type: "button", class: "btn", onClick: onClose }, "Close")), blocker.action && onAction && (index.h("button", { type: "button", class: "btn pri", onClick: onAction }, blocker.action))))));
|
|
979
|
-
|
|
980
|
-
const phirepassDownloaderCss = () => `:host{--card:220 18% 10%;--bg:216 18% 7%;--border:220 15% 18%;--primary:160 60% 45%;--primary-foreground:220 20% 7%;--destructive:0 70% 50%;--muted:220 15% 13%;--muted-foreground:215 10% 52%;--foreground:210 20% 90%;--amber:38 75% 55%;--blue:206 72% 63%;--radius:0.375rem;display:block;color:hsl(var(--foreground));font-family:ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;font-size:13px;line-height:1.45;container-type:inline-size}:host(.standalone){position:relative;height:100%;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:var(--radius);overflow:auto}:host(.compact){flex:none}*{box-sizing:border-box}button{font:inherit;color:inherit;cursor:pointer}button:disabled{cursor:not-allowed}:focus-visible{outline:2px solid hsl(var(--primary));outline-offset:2px}.hidden-input{display:none}.mono,code,.stats,.sum,.inp,.dest,.detect .host{font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace}code{font-size:12px}.muted{color:hsl(var(--muted-foreground))}.pad{padding:18px 14px}.ib{width:28px;height:28px;display:inline-grid;place-items:center;border-radius:4px;border:1px solid transparent;background:transparent;color:hsl(var(--muted-foreground));flex:none;padding:0}.ib:hover:not(:disabled){background:hsl(var(--muted));color:hsl(var(--foreground))}.ib:disabled{opacity:0.4}.ib.new{color:hsl(var(--primary));border-color:hsl(var(--primary) / 0.55);background:hsl(var(--primary) / 0.12)}.btn{border-radius:4px;padding:7px 14px;font-size:12px;font-weight:600;border:1px solid hsl(var(--border));background:hsl(var(--muted));white-space:nowrap;display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:hsl(var(--foreground))}.btn:hover:not(:disabled){border-color:hsl(var(--muted-foreground))}.btn.pri{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground))}.btn.dng{background:hsl(var(--destructive));border-color:hsl(var(--destructive));color:#fff}.btn:disabled{opacity:0.45}.lnk{background:none;border:0;color:hsl(var(--muted-foreground));font-size:11px;padding:2px 4px;display:inline-flex;align-items:center;gap:4px}.lnk:hover{color:hsl(var(--foreground))}.lnk.inline{color:hsl(var(--primary));padding:0}.pill{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:2px 7px;border-radius:3px;white-space:nowrap;flex:none}.pill.dl{background:hsl(var(--primary) / 0.18);color:hsl(var(--primary))}.pill.meta,.pill.sd{background:hsl(var(--blue) / 0.18);color:hsl(var(--blue))}.pill.mv{background:hsl(var(--amber) / 0.18);color:hsl(var(--amber))}.pill.ok{background:hsl(var(--primary));color:hsl(var(--primary-foreground))}.pill.err{background:hsl(var(--destructive) / 0.2);color:hsl(var(--destructive))}.pill.ps,.pill.q{background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.bar{display:block;height:5px;border-radius:3px;background:hsl(var(--muted));overflow:hidden;position:relative}.bar i{display:block;height:100%;background:hsl(var(--primary));border-radius:3px;transition:width 0.6s linear}.bar.indet i{width:30% !important;animation:slide 1.3s ease-in-out infinite;background:hsl(var(--blue))}.bar.paused i{background:hsl(var(--muted-foreground))}.bar.fail i{background:hsl(var(--destructive))}.bar.moving i{background:hsl(var(--amber))}.bar.seed i{background:hsl(var(--blue))}@keyframes slide{0%{transform:translateX(-100%)}100%{transform:translateX(340%)}}.jobs{display:flex;flex-direction:column}.job{display:grid;grid-template-columns:28px minmax(0, 1fr) auto;gap:4px 10px;padding:10px 12px;border-bottom:1px solid hsl(var(--border) / 0.6);align-items:center}.job:last-child{border-bottom:0}.job .kind{grid-row:span 3;align-self:start;width:28px;height:28px;border-radius:6px;display:grid;place-items:center;background:hsl(var(--muted));color:hsl(var(--muted-foreground))}.job .kind.t{color:hsl(var(--blue))}.job .kind.h{color:hsl(var(--primary))}.job .kind.n{color:hsl(var(--amber))}.job .title{display:flex;gap:8px;align-items:center;min-width:0}.job .title .nm{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.job .acts{display:flex;gap:2px;grid-row:1;grid-column:3}.job .bar,.job .stats{grid-column:2 / 4}.stats{display:flex;flex-wrap:wrap;gap:4px 14px;font-size:11px;color:hsl(var(--muted-foreground));font-variant-numeric:tabular-nums}.stats b{color:hsl(var(--foreground));font-weight:500}.stats .err{color:hsl(var(--destructive))}.job[data-state='Deleting']{opacity:0.6}.drawer{border-top:1px solid hsl(var(--border));background:hsl(var(--bg));display:flex;flex-direction:column;max-height:min(46vh, 380px)}.drawer-h{display:flex;align-items:center;gap:10px;padding:6px 12px;border-bottom:1px solid hsl(var(--border));flex:none}.drawer-h h4,.strip h4{margin:0;font-size:12px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase}.sum{color:hsl(var(--muted-foreground));font-size:11px;font-variant-numeric:tabular-nums}.sp{flex:1}.drawer-b{overflow:auto;min-height:0}.strip{display:flex;align-items:center;gap:10px;padding:7px 12px;border:0;border-top:1px solid hsl(var(--border));background:hsl(var(--bg));width:100%;text-align:left}.strip .bar{flex:1 1 120px}.overlay{position:absolute;inset:0;background:rgba(5, 7, 9, 0.6);display:grid;place-items:center;padding:14px;z-index:20}:host(.standalone) .overlay{position:fixed}.modal{width:min(100%, 420px);max-height:100%;overflow:auto;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:8px;box-shadow:0 20px 50px -10px rgba(0, 0, 0, 0.7)}.modal.wide{width:min(100%, 480px)}.dlg,.fetch-form.dialog{padding:16px;display:flex;flex-direction:column;gap:14px}.dlg h4,.dlg-h h4{margin:0;font-size:14px;font-weight:600}.dlg-h{display:flex;align-items:center;gap:10px;color:hsl(var(--primary))}.dlg-h h4{color:hsl(var(--foreground))}.dlg-f{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}.dlg-f .left{margin-right:auto}.dtx{margin:0;font-size:13px}.hint{font-size:11px;color:hsl(var(--muted-foreground));margin:0}.hint.block{display:block;margin-top:2px}.hint.err{color:hsl(var(--destructive))}.hint.where{color:hsl(var(--amber))}.fld{display:flex;flex-direction:column;gap:6px;min-width:0}.fld>label,.fld>span:first-child,legend{font-size:11px;text-transform:uppercase;letter-spacing:0.05em;color:hsl(var(--muted-foreground))}.inp{width:100%;min-width:0;background:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:4px;color:hsl(var(--foreground));padding:8px 10px;font-size:12px}.inp:focus{outline:none;border-color:hsl(var(--primary))}.inline-row{display:flex;gap:8px;align-items:stretch}.detect{display:flex;align-items:center;gap:8px;font-size:12px;color:hsl(var(--muted-foreground));min-height:20px;min-width:0}.detect .host{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.note{display:flex;gap:8px;align-items:flex-start;font-size:12px;line-height:1.45;padding:8px 10px;border-radius:4px;border:1px solid hsl(var(--border));background:hsl(var(--muted))}.note svg{flex:none;margin-top:2px}.note.err{border-color:hsl(var(--destructive) / 0.5)}.note.err svg{color:hsl(var(--destructive))}.note.warn{border-color:hsl(var(--amber) / 0.5)}.note.warn svg{color:hsl(var(--amber))}.note.info svg{color:hsl(var(--primary))}.or{display:flex;align-items:center;gap:10px;color:hsl(var(--muted-foreground));font-size:11px;text-transform:uppercase;letter-spacing:0.06em}.or::before,.or::after{content:'';flex:1;height:1px;background:hsl(var(--border))}.drop{border:1px dashed hsl(var(--border));border-radius:6px;padding:14px;display:flex;align-items:center;gap:12px;color:hsl(var(--muted-foreground));font-size:12px;background:transparent;text-align:left}.drop svg{color:hsl(var(--blue));flex:none}.drop b{color:hsl(var(--foreground));font-weight:500}.filechip{display:flex;gap:10px;align-items:center;padding:10px;border:1px solid hsl(var(--border));border-radius:4px;background:hsl(var(--muted))}.filechip>svg{color:hsl(var(--blue));flex:none}.filechip>div{flex:1;min-width:0}.filechip b{display:block;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.filechip span{color:hsl(var(--muted-foreground));font-size:11px}.filechip.bad{border-color:hsl(var(--destructive) / 0.55)}.filechip.bad>svg{color:hsl(var(--destructive))}.dest-row,.sa-dest{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.dest{display:flex;align-items:center;gap:8px;background:hsl(var(--bg));border:1px solid hsl(var(--border));border-radius:4px;padding:7px 10px;font-size:12px;min-width:0;flex:1 1 200px}.dest span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dest svg{color:hsl(var(--primary));flex:none}fieldset.order{border:0;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}fieldset.order legend{margin-bottom:6px}.opt{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border:1px solid hsl(var(--border));border-radius:4px;font-size:12px;cursor:pointer}.opt.on{border-color:hsl(var(--primary));background:hsl(var(--primary) / 0.08)}.opt input,.checkline input,.seg input{accent-color:hsl(var(--primary));margin:2px 0 0}.checkline{display:flex;gap:8px;align-items:flex-start;font-size:12px;cursor:pointer}.login{display:flex;flex-direction:column;gap:8px}.login>.lnk{align-self:flex-start;padding-left:0}.auth{display:flex;flex-direction:column;gap:10px;padding:10px;border:1px solid hsl(var(--border));border-radius:4px}.seg{display:flex;flex-wrap:wrap;gap:6px}.seg label{display:flex;gap:6px;align-items:center;font-size:11px;padding:4px 8px;border:1px solid hsl(var(--border));border-radius:999px;cursor:pointer}.seg label.on{border-color:hsl(var(--primary));color:hsl(var(--primary))}.seg input{margin:0}.crumbs{display:flex;flex-wrap:wrap;align-items:center;gap:2px;font-family:ui-monospace, SFMono-Regular, Menlo, monospace}.crumbs .lnk{font-size:12px}.crumbs .sep{color:hsl(var(--muted-foreground))}.folders{display:flex;flex-direction:column;border:1px solid hsl(var(--border));border-radius:4px;max-height:220px;overflow:auto}.folders .muted{padding:10px}.folder-row{display:flex;align-items:center;gap:8px;padding:7px 10px;border:0;border-bottom:1px solid hsl(var(--border) / 0.6);background:transparent;text-align:left;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:12px}.folder-row:hover{background:hsl(var(--muted))}.folder-row svg{color:hsl(var(--primary))}.blocker{display:flex;flex-direction:column;gap:10px}.empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px;padding:30px 20px}.empty>svg{color:hsl(var(--muted-foreground))}.empty b{font-size:14px;font-weight:600}.empty span{color:hsl(var(--muted-foreground));font-size:12px;max-width:44ch}.spin{width:22px;height:22px;border-radius:50%;border:3px solid hsl(var(--border));border-top-color:hsl(var(--primary));animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}.standalone{display:flex;flex-direction:column;min-height:100%}.sa-head{padding:14px 16px 10px;display:flex;flex-direction:column;gap:4px}.sa-title{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}.sa-title h3{margin:0;font-size:16px;font-weight:600}.sa-title .node{color:hsl(var(--muted-foreground))}.saving{font-size:12px;color:hsl(var(--muted-foreground))}.sa-add{padding:0 16px 14px;display:flex;flex-direction:column;gap:10px;border-bottom:1px solid hsl(var(--border))}.fetch-form.inline{display:flex;flex-direction:column;gap:10px}.tabs{display:flex;gap:4px;padding:0 10px;border-bottom:1px solid hsl(var(--border));overflow-x:auto}.tabs button{padding:9px 10px;font-size:12px;color:hsl(var(--muted-foreground));border:0;border-bottom:2px solid transparent;background:none;white-space:nowrap}.tabs button.on{color:hsl(var(--foreground));border-bottom-color:hsl(var(--primary))}.tabs b{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-weight:500;color:hsl(var(--muted-foreground));margin-left:6px}.tab-h{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;font-size:12px;color:hsl(var(--muted-foreground));border-bottom:1px solid hsl(var(--border) / 0.6)}.toasts{position:absolute;left:12px;right:12px;bottom:12px;display:flex;flex-direction:column;gap:8px;z-index:30;pointer-events:none;align-items:flex-end}:host(.standalone) .toasts{position:sticky;margin:12px}.toast{pointer-events:auto;display:flex;gap:10px;align-items:center;padding:10px 12px;background:hsl(var(--bg));border:1px solid hsl(var(--primary) / 0.5);border-radius:6px;width:min(100%, 420px);box-shadow:0 12px 30px -12px rgba(0, 0, 0, 0.7)}.toast>svg{color:hsl(var(--primary));flex:none}.toast.bad{border-color:hsl(var(--destructive) / 0.55)}.toast.bad>svg{color:hsl(var(--destructive))}.toast .t{flex:1;min-width:0}.toast .t b{display:block;font-weight:600}.toast .t span{color:hsl(var(--muted-foreground));font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block}.overlay.player{padding:10px}.overlay.player phirepass-media-player{width:min(100%, 880px)}@container (max-width: 480px){.job{padding:9px 10px}.job .title .pill.meta{display:none}.inline-row{flex-wrap:wrap}.inline-row .inp{flex-basis:100%}.inline-row .btn.pri{flex:1;justify-content:center}.stats{gap:2px 10px}}@media (prefers-reduced-motion: reduce){.bar i{transition:none}.bar.indet i{animation:none;width:100% !important;opacity:0.5}.spin{animation:none}}`;
|
|
981
|
-
|
|
982
|
-
/** After `DownloadAccepted`, how long the dialog waits for the node's first word before it closes anyway. */
|
|
983
|
-
const NODE_SILENCE_MS = 8_000;
|
|
984
|
-
const NOTICE_MS = 6_000;
|
|
985
|
-
const TORRENT_ACK_KEY = 'phirepass.downloader.torrent-ack';
|
|
986
|
-
function readTorrentAck() {
|
|
987
|
-
try {
|
|
988
|
-
return window.localStorage.getItem(TORRENT_ACK_KEY) === '1';
|
|
989
|
-
}
|
|
990
|
-
catch {
|
|
991
|
-
return false;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
function writeTorrentAck() {
|
|
995
|
-
try {
|
|
996
|
-
window.localStorage.setItem(TORRENT_ACK_KEY, '1');
|
|
997
|
-
}
|
|
998
|
-
catch {
|
|
999
|
-
// A private window keeps no storage: the question simply comes back next time.
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
const PhirepassDownloader = class {
|
|
1003
|
-
constructor(hostRef) {
|
|
1004
|
-
if (new.target === PhirepassDownloader)
|
|
1005
|
-
index.registerInstance(this, hostRef);
|
|
1006
|
-
this.fetchCompleted = index.createEvent(this, "phirepassFetchCompleted");
|
|
1007
|
-
this.play = index.createEvent(this, "phirepassPlay");
|
|
1008
|
-
this.activeCount = index.createEvent(this, "phirepassActiveCount");
|
|
1009
|
-
this.showInFolder = index.createEvent(this, "phirepassShowInFolder");
|
|
1010
|
-
this.openNodeSettings = index.createEvent(this, "phirepassOpenNodeSettings");
|
|
1011
|
-
this.signIn = index.createEvent(this, "phirepassSignIn");
|
|
1012
|
-
}
|
|
1013
|
-
get el() { return index.getElement(this); }
|
|
1014
|
-
ownChannel = false;
|
|
1015
|
-
msgId = DOWNLOADER_MSG_ID_BASE;
|
|
1016
|
-
noticeId = 1;
|
|
1017
|
-
seenNotices = new Set();
|
|
1018
|
-
torrentAcked = readTorrentAck();
|
|
1019
|
-
noticeTimers = new Map();
|
|
1020
|
-
whereMsgId;
|
|
1021
|
-
nodeId;
|
|
1022
|
-
/** What to call the node in sentences; the id is a uuid nobody reads. */
|
|
1023
|
-
nodeLabel;
|
|
1024
|
-
/** Session token, for the standalone form. Not needed when `channel` is given. */
|
|
1025
|
-
token;
|
|
1026
|
-
/**
|
|
1027
|
-
* A channel to share instead of opening one: the SFTP client passes its
|
|
1028
|
-
* own. The host must forward `Download*` frames (and `Error`s whose
|
|
1029
|
-
* `msg_id` is at or above `DOWNLOADER_MSG_ID_BASE`) to `receive()`, and set
|
|
1030
|
-
* `connected` once the channel is authenticated.
|
|
1031
|
-
*/
|
|
1032
|
-
channel;
|
|
1033
|
-
/** With an injected `channel`: whether it is authenticated and usable. */
|
|
1034
|
-
connected = false;
|
|
1035
|
-
/** Builds the channel in place of a WebSocket, for demos and tests (see `ChannelFactory`). */
|
|
1036
|
-
channelFactory;
|
|
1037
|
-
/** The SFTP/SSH service the host is browsing, so the node can map `browsingPath`. */
|
|
1038
|
-
browsingService;
|
|
1039
|
-
/** The folder on screen in the host. Downloads land here when it lies inside the download folder. */
|
|
1040
|
-
browsingPath;
|
|
1041
|
-
/** The drawer layout used inside the SFTP browser. */
|
|
1042
|
-
compact = false;
|
|
1043
|
-
/** Base URL for `/api/web/stream/…`. Defaults to the server the channel talks to. */
|
|
1044
|
-
streamBase;
|
|
1045
|
-
/** Whether the viewer may configure this node, which only changes advice text (B9). */
|
|
1046
|
-
canConfigure = false;
|
|
1047
|
-
/** Open the built-in player on Play, unless a `phirepassPlay` listener calls `preventDefault()`. */
|
|
1048
|
-
inlinePlayer = true;
|
|
1049
|
-
serverHost = 'phirepass.com';
|
|
1050
|
-
serverPort = 443;
|
|
1051
|
-
serverId;
|
|
1052
|
-
allowInsecure = false;
|
|
1053
|
-
heartbeatInterval = 30_000;
|
|
1054
|
-
/** A finished download, once per job. The SFTP client refreshes when it lands in the open folder. */
|
|
1055
|
-
fetchCompleted;
|
|
1056
|
-
/** Play was pressed. Cancelable: prevent it to open your own player instead. */
|
|
1057
|
-
play;
|
|
1058
|
-
/** How many downloads are running, for a badge. */
|
|
1059
|
-
activeCount;
|
|
1060
|
-
/** “Show in folder” on a finished row. */
|
|
1061
|
-
showInFolder;
|
|
1062
|
-
/** “Open node settings” (B9, no folder). */
|
|
1063
|
-
openNodeSettings;
|
|
1064
|
-
/** “Sign in” (X3). */
|
|
1065
|
-
signIn;
|
|
1066
|
-
connection = 'connecting';
|
|
1067
|
-
caps = null;
|
|
1068
|
-
jobs = {};
|
|
1069
|
-
tab = 'active';
|
|
1070
|
-
drawerOpen = false;
|
|
1071
|
-
dialogOpen = false;
|
|
1072
|
-
unread = 0;
|
|
1073
|
-
form = EMPTY_FORM;
|
|
1074
|
-
where = null;
|
|
1075
|
-
starting = null;
|
|
1076
|
-
refusal = null;
|
|
1077
|
-
confirm = null;
|
|
1078
|
-
notices = [];
|
|
1079
|
-
subDir = null;
|
|
1080
|
-
picker = null;
|
|
1081
|
-
player = null;
|
|
1082
|
-
get name() {
|
|
1083
|
-
return this.nodeLabel || this.nodeId;
|
|
1084
|
-
}
|
|
1085
|
-
get ch() {
|
|
1086
|
-
return this.channel ?? this.ownedChannel;
|
|
1087
|
-
}
|
|
1088
|
-
ownedChannel;
|
|
1089
|
-
// ---------------------------------------------------------------- lifecycle
|
|
1090
|
-
async componentWillLoad() {
|
|
1091
|
-
if (this.channel) {
|
|
1092
|
-
this.adoptChannel();
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
await this.openOwnChannel();
|
|
1096
|
-
}
|
|
1097
|
-
disconnectedCallback() {
|
|
1098
|
-
this.noticeTimers.forEach(t => window.clearTimeout(t));
|
|
1099
|
-
this.noticeTimers.clear();
|
|
1100
|
-
if (this.starting?.silence) {
|
|
1101
|
-
window.clearTimeout(this.starting.silence);
|
|
1102
|
-
}
|
|
1103
|
-
if (this.ownChannel && this.ownedChannel) {
|
|
1104
|
-
this.ownedChannel.stop_heartbeat();
|
|
1105
|
-
this.ownedChannel.disconnect();
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
onChannel() {
|
|
1109
|
-
if (this.channel) {
|
|
1110
|
-
this.adoptChannel();
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
onConnected(now, before) {
|
|
1114
|
-
if (!this.channel) {
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
if (now && !before) {
|
|
1118
|
-
this.subscribe();
|
|
1119
|
-
}
|
|
1120
|
-
else if (!now && before) {
|
|
1121
|
-
this.connection = 'unreachable';
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
onBrowsing() {
|
|
1125
|
-
this.where = null;
|
|
1126
|
-
if (this.dialogOpen) {
|
|
1127
|
-
this.askWhere();
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
onNode(now, before) {
|
|
1131
|
-
if (now === before) {
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
this.jobs = {};
|
|
1135
|
-
this.caps = null;
|
|
1136
|
-
this.where = null;
|
|
1137
|
-
if (this.channel) {
|
|
1138
|
-
if (this.connected) {
|
|
1139
|
-
this.subscribe();
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
else if (this.ownedChannel) {
|
|
1143
|
-
this.ownedChannel.disconnect();
|
|
1144
|
-
void this.openOwnChannel();
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
adoptChannel() {
|
|
1148
|
-
this.ownChannel = false;
|
|
1149
|
-
if (!supportsDownloads(this.channel)) {
|
|
1150
|
-
this.connection = 'unsupported';
|
|
1151
|
-
return;
|
|
1152
|
-
}
|
|
1153
|
-
this.connection = 'connecting';
|
|
1154
|
-
if (this.connected) {
|
|
1155
|
-
this.subscribe();
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
endpoint() {
|
|
1159
|
-
const protocol = this.allowInsecure ? 'ws' : 'wss';
|
|
1160
|
-
const defaultPort = (!this.allowInsecure && this.serverPort === 443) || (this.allowInsecure && this.serverPort === 80);
|
|
1161
|
-
return `${protocol}://${this.serverHost}${defaultPort ? '' : `:${this.serverPort}`}/api/web/ws`;
|
|
1162
|
-
}
|
|
1163
|
-
defaultStreamBase() {
|
|
1164
|
-
const protocol = this.allowInsecure ? 'http' : 'https';
|
|
1165
|
-
const defaultPort = (!this.allowInsecure && this.serverPort === 443) || (this.allowInsecure && this.serverPort === 80);
|
|
1166
|
-
return `${protocol}://${this.serverHost}${defaultPort ? '' : `:${this.serverPort}`}`;
|
|
1167
|
-
}
|
|
1168
|
-
async openOwnChannel() {
|
|
1169
|
-
this.ownChannel = true;
|
|
1170
|
-
if (!this.token) {
|
|
1171
|
-
this.connection = 'signed-out';
|
|
1172
|
-
return;
|
|
1173
|
-
}
|
|
1174
|
-
if (!this.nodeId) {
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
if (!this.channelFactory) {
|
|
1178
|
-
await protocol.__wbg_init();
|
|
1179
|
-
}
|
|
1180
|
-
const channel = this.channelFactory
|
|
1181
|
-
? this.channelFactory(this.endpoint(), this.nodeId, this.serverId)
|
|
1182
|
-
: this.serverId
|
|
1183
|
-
? new protocol.Channel(this.endpoint(), this.nodeId, this.serverId)
|
|
1184
|
-
: new protocol.Channel(this.endpoint(), this.nodeId);
|
|
1185
|
-
this.ownedChannel = channel;
|
|
1186
|
-
if (!supportsDownloads(channel)) {
|
|
1187
|
-
this.connection = 'unsupported';
|
|
1188
|
-
return;
|
|
1189
|
-
}
|
|
1190
|
-
channel.on_connection_open(() => channel.authenticate(this.token, this.nodeId));
|
|
1191
|
-
channel.on_connection_close(() => {
|
|
1192
|
-
if (this.connection !== 'signed-out') {
|
|
1193
|
-
this.connection = 'unreachable';
|
|
1194
|
-
}
|
|
1195
|
-
});
|
|
1196
|
-
channel.on_connection_error(() => {
|
|
1197
|
-
if (this.connection !== 'signed-out') {
|
|
1198
|
-
this.connection = 'unreachable';
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
channel.on_connection_message(() => undefined);
|
|
1202
|
-
channel.on_protocol_message((msg) => this.dispatch(msg.data.web));
|
|
1203
|
-
this.connection = 'connecting';
|
|
1204
|
-
channel.connect();
|
|
1205
|
-
}
|
|
1206
|
-
reconnect() {
|
|
1207
|
-
if (this.ownChannel) {
|
|
1208
|
-
this.ownedChannel?.disconnect();
|
|
1209
|
-
void this.openOwnChannel();
|
|
1210
|
-
}
|
|
1211
|
-
else if (this.connected) {
|
|
1212
|
-
this.subscribe();
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
// ---------------------------------------------------------------- inbound
|
|
1216
|
-
/**
|
|
1217
|
-
* Hands this widget a frame from a shared channel: `Download*` frames, and
|
|
1218
|
-
* `Error`s answering one of its `msg_id`s. Anything else is ignored.
|
|
1219
|
-
*/
|
|
1220
|
-
async receive(msg) {
|
|
1221
|
-
this.dispatch(msg.data.web);
|
|
1222
|
-
}
|
|
1223
|
-
dispatch(web) {
|
|
1224
|
-
if (web.type === protocol.ProtocolMessageType.AuthSuccess) {
|
|
1225
|
-
this.ownedChannel?.start_heartbeat(Math.max(30_000, this.heartbeatInterval));
|
|
1226
|
-
this.subscribe();
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
if (web.type === protocol.ProtocolMessageType.Error) {
|
|
1230
|
-
this.handleError(web);
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
if (!isDownloadFrame(web)) {
|
|
1234
|
-
return;
|
|
1235
|
-
}
|
|
1236
|
-
switch (web.type) {
|
|
1237
|
-
case 'DownloadCaps':
|
|
1238
|
-
if (web.node_id === this.nodeId) {
|
|
1239
|
-
this.caps = web.caps;
|
|
1240
|
-
this.connection = 'ready';
|
|
1241
|
-
}
|
|
1242
|
-
break;
|
|
1243
|
-
case 'DownloadProgress':
|
|
1244
|
-
if (web.node_id === this.nodeId) {
|
|
1245
|
-
this.onProgress(web.job);
|
|
1246
|
-
}
|
|
1247
|
-
break;
|
|
1248
|
-
case 'DownloadAccepted':
|
|
1249
|
-
this.onAccepted(web.msg_id, web.download_id);
|
|
1250
|
-
break;
|
|
1251
|
-
case 'DownloadWhereAnswer':
|
|
1252
|
-
if (web.msg_id === this.whereMsgId) {
|
|
1253
|
-
this.where = { saves_to: web.saves_to, mapped: web.mapped };
|
|
1254
|
-
}
|
|
1255
|
-
break;
|
|
1256
|
-
case 'DownloadFoldersAnswer':
|
|
1257
|
-
if (this.picker && web.msg_id === this.picker.msgId) {
|
|
1258
|
-
this.picker = { ...this.picker, folders: [...web.folders].sort((a, b) => a.localeCompare(b)) };
|
|
1259
|
-
}
|
|
1260
|
-
break;
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
handleError(error) {
|
|
1264
|
-
if (error.msg_id !== undefined && error.msg_id === this.starting?.msgId) {
|
|
1265
|
-
this.clearStarting();
|
|
1266
|
-
this.refusal = { tone: 'err', title: 'Refused', body: error.message || 'The server refused this download.' };
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
if (this.picker && error.msg_id === this.picker.msgId) {
|
|
1270
|
-
this.picker = { ...this.picker, folders: [], error: error.message };
|
|
1271
|
-
return;
|
|
1272
|
-
}
|
|
1273
|
-
if (error.msg_id !== undefined && error.msg_id >= DOWNLOADER_MSG_ID_BASE) {
|
|
1274
|
-
this.notify('error', 'That did not work', error.message || 'The server refused it.');
|
|
1275
|
-
return;
|
|
1276
|
-
}
|
|
1277
|
-
if (this.ownChannel && error.kind === protocol.ErrorType.Authentication) {
|
|
1278
|
-
this.connection = 'signed-out';
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
subscribe() {
|
|
1282
|
-
const ch = this.ch;
|
|
1283
|
-
if (!supportsDownloads(ch)) {
|
|
1284
|
-
this.connection = 'unsupported';
|
|
1285
|
-
return;
|
|
1286
|
-
}
|
|
1287
|
-
// A fresh subscription answers with caps and every current row.
|
|
1288
|
-
this.jobs = {};
|
|
1289
|
-
ch.send_download_subscribe({ Node: this.nodeId });
|
|
1290
|
-
if (this.dialogOpen) {
|
|
1291
|
-
this.askWhere();
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
onProgress(job) {
|
|
1295
|
-
const before = this.jobs[job.download_id];
|
|
1296
|
-
const { jobs, completed } = applyProgress(this.jobs, job);
|
|
1297
|
-
this.jobs = jobs;
|
|
1298
|
-
this.emitCount();
|
|
1299
|
-
if (this.starting?.downloadId === job.download_id && !before) {
|
|
1300
|
-
this.onFirstProgress(job);
|
|
1301
|
-
}
|
|
1302
|
-
if (completed) {
|
|
1303
|
-
this.fetchCompleted.emit({ download_id: job.download_id, dest_root: job.dest_root, sub_dir: job.sub_dir, name: job.name });
|
|
1304
|
-
if (!this.drawerOpen && this.compact) {
|
|
1305
|
-
this.unread++;
|
|
1306
|
-
}
|
|
1307
|
-
this.notify('completed', 'Download complete', `${job.name} → ${folderOf(job)}`, {
|
|
1308
|
-
label: 'Show',
|
|
1309
|
-
run: () => this.showInFolder.emit({ path: folderOf(job), name: job.name }),
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
const row = this.jobs[job.download_id];
|
|
1313
|
-
if (row && isStuck(row) && !this.seenNotices.has(`stuck:${job.download_id}`)) {
|
|
1314
|
-
this.seenNotices.add(`stuck:${job.download_id}`);
|
|
1315
|
-
this.notify('stuck', 'Still retrying after a day', `${job.name} · ${job.retry_reason ?? 'no answer'}`, { label: 'Show', run: () => this.showRetrying() }, true);
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
onAccepted(msgId, downloadId) {
|
|
1319
|
-
if (!this.starting || this.starting.msgId !== msgId) {
|
|
1320
|
-
return;
|
|
1321
|
-
}
|
|
1322
|
-
if (this.jobs[downloadId]) {
|
|
1323
|
-
// The node already answered: progress beat the acceptance here.
|
|
1324
|
-
this.onFirstProgress(this.jobs[downloadId]);
|
|
1325
|
-
return;
|
|
1326
|
-
}
|
|
1327
|
-
const silence = window.setTimeout(() => this.nodeSilent(downloadId), NODE_SILENCE_MS);
|
|
1328
|
-
this.starting = { ...this.starting, downloadId, silence };
|
|
1329
|
-
}
|
|
1330
|
-
/** The server took it but the node has not spoken: it is offline, and the row says it waits. */
|
|
1331
|
-
nodeSilent(downloadId) {
|
|
1332
|
-
if (this.starting?.downloadId !== downloadId || this.jobs[downloadId]) {
|
|
1333
|
-
return;
|
|
1334
|
-
}
|
|
1335
|
-
const name = this.starting.askedName ?? 'Download';
|
|
1336
|
-
const now = Date.now();
|
|
1337
|
-
const placeholder = {
|
|
1338
|
-
download_id: downloadId,
|
|
1339
|
-
kind: 'Unknown',
|
|
1340
|
-
name,
|
|
1341
|
-
dest_root: this.where?.saves_to ?? this.caps?.folder ?? '',
|
|
1342
|
-
sub_dir: null,
|
|
1343
|
-
state: 'Queued',
|
|
1344
|
-
done_bytes: 0,
|
|
1345
|
-
total_bytes: null,
|
|
1346
|
-
down_bps: 0,
|
|
1347
|
-
up_bps: 0,
|
|
1348
|
-
peers: 0,
|
|
1349
|
-
in_order: true,
|
|
1350
|
-
started_at: now,
|
|
1351
|
-
finished_at: null,
|
|
1352
|
-
reason: null,
|
|
1353
|
-
requested_by: null,
|
|
1354
|
-
files: [],
|
|
1355
|
-
up_total: 0,
|
|
1356
|
-
pause_reason: null,
|
|
1357
|
-
seeding_since: null,
|
|
1358
|
-
info_hash: null,
|
|
1359
|
-
retry_reason: null,
|
|
1360
|
-
attempt: 0,
|
|
1361
|
-
next_attempt_at: null,
|
|
1362
|
-
restarted_from_zero: false,
|
|
1363
|
-
waitingForNode: true,
|
|
1364
|
-
};
|
|
1365
|
-
this.jobs = { ...this.jobs, [downloadId]: placeholder };
|
|
1366
|
-
this.clearStarting();
|
|
1367
|
-
this.closeDialog(true);
|
|
1368
|
-
this.notify('queued', `Waiting for ${this.name}`, `${name} starts when the node reports in.`);
|
|
1369
|
-
}
|
|
1370
|
-
onFirstProgress(job) {
|
|
1371
|
-
const asked = this.starting?.askedName;
|
|
1372
|
-
this.clearStarting();
|
|
1373
|
-
if (job.state === 'Cancelled') {
|
|
1374
|
-
const reason = job.reason ?? 'The node refused this download.';
|
|
1375
|
-
if (isNoSpace(reason)) {
|
|
1376
|
-
this.confirm = { kind: 'space', reason };
|
|
1377
|
-
}
|
|
1378
|
-
else if (this.dialogOpen || !this.compact) {
|
|
1379
|
-
this.refusal = { tone: 'err', title: 'Refused', body: reason };
|
|
1380
|
-
}
|
|
1381
|
-
return;
|
|
1382
|
-
}
|
|
1383
|
-
this.closeDialog(true);
|
|
1384
|
-
if (job.state === 'Queued') {
|
|
1385
|
-
const running = Object.values(this.jobs).filter(r => r.state === 'Downloading').length;
|
|
1386
|
-
this.notify('queued', 'Added to the queue', `${running} ${running === 1 ? 'download is' : 'downloads are'} already running on this node`);
|
|
1387
|
-
}
|
|
1388
|
-
else {
|
|
1389
|
-
this.notify('started', 'Download started', `${job.name} → ${folderOf(job)}`);
|
|
1390
|
-
}
|
|
1391
|
-
if (renamedByNode(asked, job.name)) {
|
|
1392
|
-
this.notify('renamed', `Saved as ${job.name}`, `A file named ${asked} was already in ${folderOf(job)}`);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
clearStarting() {
|
|
1396
|
-
if (this.starting?.silence) {
|
|
1397
|
-
window.clearTimeout(this.starting.silence);
|
|
1398
|
-
}
|
|
1399
|
-
this.starting = null;
|
|
1400
|
-
}
|
|
1401
|
-
emitCount() {
|
|
1402
|
-
this.activeCount.emit({ n: Object.values(this.jobs).filter(isRunning).length });
|
|
1403
|
-
}
|
|
1404
|
-
notify(kind, title, detail, action, sticky = false) {
|
|
1405
|
-
const id = this.noticeId++;
|
|
1406
|
-
this.notices = [...this.notices.slice(-2), { id, kind, title, detail, action, sticky }];
|
|
1407
|
-
if (!sticky) {
|
|
1408
|
-
this.noticeTimers.set(id, window.setTimeout(() => this.dismiss(id), NOTICE_MS));
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
dismiss(id) {
|
|
1412
|
-
const t = this.noticeTimers.get(id);
|
|
1413
|
-
if (t) {
|
|
1414
|
-
window.clearTimeout(t);
|
|
1415
|
-
this.noticeTimers.delete(id);
|
|
1416
|
-
}
|
|
1417
|
-
this.notices = this.notices.filter(n => n.id !== id);
|
|
1418
|
-
}
|
|
1419
|
-
showRetrying() {
|
|
1420
|
-
this.tab = 'retrying';
|
|
1421
|
-
this.drawerOpen = true;
|
|
1422
|
-
}
|
|
1423
|
-
// ---------------------------------------------------------------- public methods
|
|
1424
|
-
/** Opens the Fetch dialog (and the drawer behind it). `path` updates the folder on screen. */
|
|
1425
|
-
async openFetch(path) {
|
|
1426
|
-
if (path !== undefined && path !== this.browsingPath) {
|
|
1427
|
-
this.browsingPath = path;
|
|
1428
|
-
}
|
|
1429
|
-
this.drawerOpen = true;
|
|
1430
|
-
this.unread = 0;
|
|
1431
|
-
this.dialogOpen = true;
|
|
1432
|
-
this.refusal = null;
|
|
1433
|
-
this.askWhere();
|
|
1434
|
-
}
|
|
1435
|
-
/** Opens or closes the drawer (embedded). */
|
|
1436
|
-
async toggleDrawer(open) {
|
|
1437
|
-
this.drawerOpen = open ?? !this.drawerOpen;
|
|
1438
|
-
if (this.drawerOpen) {
|
|
1439
|
-
this.unread = 0;
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
/** The running download whose part file this is, so the SFTP client can offer K3 instead of a plain delete. */
|
|
1443
|
-
async jobForPath(path) {
|
|
1444
|
-
const row = Object.values(this.jobs).find(r => !isFinished(r.state) && r.state !== 'Cancelled' && partPath(r) === path);
|
|
1445
|
-
return row ? { download_id: row.download_id, name: row.name } : null;
|
|
1446
|
-
}
|
|
1447
|
-
/** Deletes a download (an unfinished one always loses its part file). */
|
|
1448
|
-
async deleteDownload(downloadId, deleteFile = false) {
|
|
1449
|
-
const row = this.jobs[downloadId];
|
|
1450
|
-
if (row) {
|
|
1451
|
-
this.sendDelete(row, deleteFile);
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
/**
|
|
1455
|
-
* The path of a `.torrent` on the node relative to the download folder, or
|
|
1456
|
-
* null when it lies outside it (then C's menu item is not offered).
|
|
1457
|
-
*/
|
|
1458
|
-
async torrentPathFor(path) {
|
|
1459
|
-
const root = this.caps?.folder;
|
|
1460
|
-
if (!root || !this.caps?.torrents || !/\.torrent$/i.test(path) || blockerFor(this.caps, this.name, this.canConfigure)) {
|
|
1461
|
-
return null;
|
|
1462
|
-
}
|
|
1463
|
-
const prefix = root.endsWith('/') ? root : `${root}/`;
|
|
1464
|
-
return path.startsWith(prefix) ? path.slice(prefix.length) : null;
|
|
1465
|
-
}
|
|
1466
|
-
/** C: download the contents of a `.torrent` already on the node, into the folder it sits in. */
|
|
1467
|
-
async startTorrentPath(path, inOrder = false) {
|
|
1468
|
-
const rel = await this.torrentPathFor(path);
|
|
1469
|
-
const ch = this.ch;
|
|
1470
|
-
if (rel === null || !supportsDownloads(ch)) {
|
|
1471
|
-
return false;
|
|
1472
|
-
}
|
|
1473
|
-
const msgId = this.nextMsgId();
|
|
1474
|
-
this.starting = { msgId, askedName: rel.split('/').pop()?.replace(/\.torrent$/i, '') };
|
|
1475
|
-
const dir = rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : null;
|
|
1476
|
-
ch.send_download_start(this.nodeId, { TorrentPath: { path: rel } }, dir, null, inOrder, { source_auth: null, ignore_window: false }, msgId);
|
|
1477
|
-
this.drawerOpen = true;
|
|
1478
|
-
return true;
|
|
1479
|
-
}
|
|
1480
|
-
// ---------------------------------------------------------------- outbound
|
|
1481
|
-
nextMsgId() {
|
|
1482
|
-
this.msgId = this.msgId >= 0xffff_fff0 ? DOWNLOADER_MSG_ID_BASE : this.msgId + 1;
|
|
1483
|
-
return this.msgId;
|
|
1484
|
-
}
|
|
1485
|
-
browsing() {
|
|
1486
|
-
return this.compact && this.browsingService && this.browsingPath ? { service_id: this.browsingService, path: this.browsingPath } : null;
|
|
1487
|
-
}
|
|
1488
|
-
askWhere() {
|
|
1489
|
-
const browsing = this.browsing();
|
|
1490
|
-
const ch = this.ch;
|
|
1491
|
-
if (!browsing || !supportsDownloads(ch) || this.connection !== 'ready') {
|
|
1492
|
-
return;
|
|
1493
|
-
}
|
|
1494
|
-
this.whereMsgId = this.nextMsgId();
|
|
1495
|
-
ch.send_download_where(this.nodeId, browsing, this.whereMsgId);
|
|
1496
|
-
}
|
|
1497
|
-
destination() {
|
|
1498
|
-
if (this.browsing()) {
|
|
1499
|
-
if (!this.where) {
|
|
1500
|
-
return { path: this.browsingPath, hint: 'Asking the node where this lands…' };
|
|
1501
|
-
}
|
|
1502
|
-
return this.where.mapped
|
|
1503
|
-
? { path: this.where.saves_to }
|
|
1504
|
-
: { path: this.where.saves_to, hint: `This folder is outside ${this.name}'s download folder. The file will be saved to ${this.where.saves_to}.` };
|
|
1505
|
-
}
|
|
1506
|
-
const root = this.caps?.folder;
|
|
1507
|
-
return root ? { path: joinPath(root, this.subDir) } : null;
|
|
1508
|
-
}
|
|
1509
|
-
formReady() {
|
|
1510
|
-
if (this.starting || this.connection !== 'ready') {
|
|
1511
|
-
return false;
|
|
1512
|
-
}
|
|
1513
|
-
return this.browsing() ? !!this.where : true;
|
|
1514
|
-
}
|
|
1515
|
-
async pickTorrent(file) {
|
|
1516
|
-
const chosen = chooseTorrent(file);
|
|
1517
|
-
if (!chosen.error) {
|
|
1518
|
-
chosen.contents = new Uint8Array(await file.arrayBuffer());
|
|
1519
|
-
}
|
|
1520
|
-
this.form = { ...this.form, torrent: chosen, text: '', order: null };
|
|
1521
|
-
this.refusal = null;
|
|
1522
|
-
}
|
|
1523
|
-
start(skipTorrentAsk = false) {
|
|
1524
|
-
const model = formModel(this.form, this.caps, this.formReady());
|
|
1525
|
-
const plan = buildStart(this.form);
|
|
1526
|
-
const ch = this.ch;
|
|
1527
|
-
if (!model.canStart || !plan || !supportsDownloads(ch)) {
|
|
1528
|
-
return;
|
|
1529
|
-
}
|
|
1530
|
-
if (model.isTorrent && !this.torrentAcked && !skipTorrentAsk) {
|
|
1531
|
-
this.confirm = { kind: 'torrent', dontAsk: false };
|
|
1532
|
-
return;
|
|
1533
|
-
}
|
|
1534
|
-
const msgId = this.nextMsgId();
|
|
1535
|
-
const askedName = model.askedName ?? (this.form.torrent ? this.form.torrent.name.replace(/\.torrent$/i, '') : model.detected.kind === 'magnet' ? shortMagnet(model.detected.uri) : undefined);
|
|
1536
|
-
this.starting = { msgId, askedName };
|
|
1537
|
-
this.refusal = null;
|
|
1538
|
-
const browsing = this.browsing();
|
|
1539
|
-
ch.send_download_start(this.nodeId, plan.source, browsing ? null : this.subDir, browsing, plan.inOrder, plan.options, msgId);
|
|
1540
|
-
}
|
|
1541
|
-
closeDialog(started = false) {
|
|
1542
|
-
this.dialogOpen = false;
|
|
1543
|
-
this.refusal = null;
|
|
1544
|
-
if (started) {
|
|
1545
|
-
this.form = EMPTY_FORM;
|
|
1546
|
-
this.drawerOpen = true;
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
sendStop(row, discard) {
|
|
1550
|
-
const ch = this.ch;
|
|
1551
|
-
if (supportsDownloads(ch)) {
|
|
1552
|
-
ch.send_download_stop(row.download_id, discard, this.nextMsgId());
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
sendDelete(row, deleteFile) {
|
|
1556
|
-
const ch = this.ch;
|
|
1557
|
-
if (!supportsDownloads(ch)) {
|
|
1558
|
-
return;
|
|
1559
|
-
}
|
|
1560
|
-
ch.send_download_delete(row.download_id, deleteFile, this.nextMsgId());
|
|
1561
|
-
this.jobs = { ...this.jobs, [row.download_id]: { ...row, deleting: true } };
|
|
1562
|
-
}
|
|
1563
|
-
actions = {
|
|
1564
|
-
play: row => this.playRow(row),
|
|
1565
|
-
pause: row => this.sendStop(row, false),
|
|
1566
|
-
resume: (row, ignoreWindow = false) => {
|
|
1567
|
-
const ch = this.ch;
|
|
1568
|
-
if (supportsDownloads(ch)) {
|
|
1569
|
-
ch.send_download_resume(row.download_id, ignoreWindow, this.nextMsgId());
|
|
1570
|
-
}
|
|
1571
|
-
},
|
|
1572
|
-
stop: row => (this.confirm = { kind: 'stop', row, discard: false }),
|
|
1573
|
-
remove: row => {
|
|
1574
|
-
if (row.state === 'Completed' || row.state === 'Seeding' || row.state === 'Stopped') {
|
|
1575
|
-
this.confirm = { kind: 'delete', row, deleteFile: false };
|
|
1576
|
-
}
|
|
1577
|
-
else {
|
|
1578
|
-
// Cancelled: its part is already gone, so there is nothing to lose.
|
|
1579
|
-
this.sendDelete(row, false);
|
|
1580
|
-
}
|
|
1581
|
-
},
|
|
1582
|
-
setOrder: (row, inOrder) => {
|
|
1583
|
-
if (!inOrder && this.player?.downloadId === row.download_id) {
|
|
1584
|
-
this.confirm = { kind: 'fastest', row };
|
|
1585
|
-
return;
|
|
1586
|
-
}
|
|
1587
|
-
this.sendOrder(row, inOrder);
|
|
1588
|
-
},
|
|
1589
|
-
showInFolder: row => this.showInFolder.emit({ path: folderOf(row), name: row.name }),
|
|
1590
|
-
};
|
|
1591
|
-
sendOrder(row, inOrder) {
|
|
1592
|
-
const ch = this.ch;
|
|
1593
|
-
if (supportsDownloads(ch)) {
|
|
1594
|
-
ch.send_download_set_order(row.download_id, inOrder, this.nextMsgId());
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
playRow(row) {
|
|
1598
|
-
const check = playCheck(row);
|
|
1599
|
-
if (!check.play || !check.file) {
|
|
1600
|
-
return;
|
|
1601
|
-
}
|
|
1602
|
-
const src = streamUrl(this.streamBase || this.defaultStreamBase(), this.nodeId, row.download_id, check.file.index);
|
|
1603
|
-
const event = this.play.emit({ src, name: check.file.name, downloadId: row.download_id });
|
|
1604
|
-
if (!event.defaultPrevented && this.inlinePlayer) {
|
|
1605
|
-
this.player = { src, name: check.file.name, downloadId: row.download_id };
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
clearFinished() {
|
|
1609
|
-
Object.values(this.jobs)
|
|
1610
|
-
.filter(isClearable)
|
|
1611
|
-
.forEach(row => this.sendDelete(row, false));
|
|
1612
|
-
}
|
|
1613
|
-
// ---------------------------------------------------------------- folder picker (H6)
|
|
1614
|
-
canPickFolder() {
|
|
1615
|
-
return !!this.caps?.folder && typeof this.ch?.send_download_folders === 'function';
|
|
1616
|
-
}
|
|
1617
|
-
listFolders(path) {
|
|
1618
|
-
const msgId = this.nextMsgId();
|
|
1619
|
-
this.picker = { path, folders: null, msgId, newName: null };
|
|
1620
|
-
this.ch?.send_download_folders?.(this.nodeId, path.length ? path.join('/') : null, msgId);
|
|
1621
|
-
}
|
|
1622
|
-
savePicker() {
|
|
1623
|
-
if (!this.picker) {
|
|
1624
|
-
return;
|
|
1625
|
-
}
|
|
1626
|
-
const segs = [...this.picker.path];
|
|
1627
|
-
const fresh = this.picker.newName?.trim();
|
|
1628
|
-
if (fresh) {
|
|
1629
|
-
segs.push(fresh);
|
|
1630
|
-
}
|
|
1631
|
-
this.subDir = segs.length ? segs.join('/') : null;
|
|
1632
|
-
this.picker = null;
|
|
1633
|
-
}
|
|
1634
|
-
// ---------------------------------------------------------------- render
|
|
1635
|
-
renderConfirm() {
|
|
1636
|
-
const c = this.confirm;
|
|
1637
|
-
if (!c) {
|
|
1638
|
-
return null;
|
|
1639
|
-
}
|
|
1640
|
-
const cancel = () => (this.confirm = null);
|
|
1641
|
-
switch (c.kind) {
|
|
1642
|
-
case 'stop':
|
|
1643
|
-
return (index.h(ConfirmStop, { row: c.row, discard: c.discard, onDiscard: discard => (this.confirm = { ...c, discard }), onCancel: cancel, onConfirm: () => {
|
|
1644
|
-
this.sendStop(c.row, c.discard);
|
|
1645
|
-
this.confirm = null;
|
|
1646
|
-
} }));
|
|
1647
|
-
case 'delete':
|
|
1648
|
-
return (index.h(ConfirmDelete, { row: c.row, nodeName: this.name, deleteFile: c.deleteFile, onDeleteFile: deleteFile => (this.confirm = { ...c, deleteFile }), onCancel: cancel, onConfirm: () => {
|
|
1649
|
-
this.sendDelete(c.row, c.deleteFile);
|
|
1650
|
-
this.confirm = null;
|
|
1651
|
-
} }));
|
|
1652
|
-
case 'fastest':
|
|
1653
|
-
return (index.h(ConfirmFastest, { row: c.row, onCancel: cancel, onConfirm: () => {
|
|
1654
|
-
this.player = null;
|
|
1655
|
-
this.sendOrder(c.row, false);
|
|
1656
|
-
this.confirm = null;
|
|
1657
|
-
} }));
|
|
1658
|
-
case 'torrent':
|
|
1659
|
-
return (index.h(ConfirmTorrent, { nodeName: this.name, dontAsk: c.dontAsk, onDontAsk: dontAsk => (this.confirm = { ...c, dontAsk }), onCancel: cancel, onConfirm: () => {
|
|
1660
|
-
if (c.dontAsk) {
|
|
1661
|
-
writeTorrentAck();
|
|
1662
|
-
this.torrentAcked = true;
|
|
1663
|
-
}
|
|
1664
|
-
this.confirm = null;
|
|
1665
|
-
this.start(true);
|
|
1666
|
-
} }));
|
|
1667
|
-
case 'space':
|
|
1668
|
-
return index.h(NoSpace, { reason: c.reason, onClose: cancel });
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
renderForm(layout) {
|
|
1672
|
-
const blocker = this.caps ? blockerFor(this.caps, this.name, this.canConfigure) : null;
|
|
1673
|
-
const onAction = () => this.openNodeSettings.emit({ nodeId: this.nodeId });
|
|
1674
|
-
if (blocker) {
|
|
1675
|
-
return layout === 'dialog' ? (index.h("div", { class: "dlg" }, index.h("div", { class: "dlg-h" }, index.h(Icon, { name: "fetch" }), index.h("h4", null, "Fetch into this folder")), index.h(BlockerView, { blocker: blocker, onAction: onAction, onClose: () => this.closeDialog() }))) : (index.h(BlockerView, { blocker: blocker, onAction: onAction }));
|
|
1676
|
-
}
|
|
1677
|
-
const model = formModel(this.form, this.caps, this.formReady());
|
|
1678
|
-
return (index.h(FetchForm, { form: this.form, model: model, caps: this.caps, layout: layout, title: this.browsing() ? 'Fetch into this folder' : 'Add download', destination: layout === 'dialog' || this.browsing() ? this.destination() : null, starting: !!this.starting, refusal: this.refusal, onChange: patch => {
|
|
1679
|
-
this.form = { ...this.form, ...patch };
|
|
1680
|
-
if ('text' in patch || 'torrent' in patch) {
|
|
1681
|
-
this.refusal = null;
|
|
1682
|
-
}
|
|
1683
|
-
}, onAuth: patch => (this.form = { ...this.form, auth: { ...this.form.auth, ...patch } }), onPickTorrent: file => void this.pickTorrent(file), onStart: () => this.start(), onCancel: () => this.closeDialog() }));
|
|
1684
|
-
}
|
|
1685
|
-
renderRows(rows) {
|
|
1686
|
-
const running = rows.filter(r => r.state === 'Downloading').length;
|
|
1687
|
-
return (index.h("div", { class: "jobs", role: "list" }, sortRows(rows).map(row => (index.h(JobRow, { row: row, actions: this.actions, running: running, compact: this.compact })))));
|
|
1688
|
-
}
|
|
1689
|
-
renderStatus() {
|
|
1690
|
-
switch (this.connection) {
|
|
1691
|
-
case 'unsupported':
|
|
1692
|
-
return index.h(Unsupported, null);
|
|
1693
|
-
case 'signed-out':
|
|
1694
|
-
return index.h(SignedOut, { onSignIn: () => this.signIn.emit() });
|
|
1695
|
-
case 'unreachable':
|
|
1696
|
-
return index.h(Unreachable, { nodeName: this.name, onRetry: () => this.reconnect() });
|
|
1697
|
-
case 'connecting':
|
|
1698
|
-
return index.h(Loading, null);
|
|
1699
|
-
default:
|
|
1700
|
-
return null;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
renderCompact() {
|
|
1704
|
-
const rows = Object.values(this.jobs);
|
|
1705
|
-
const sum = summarize(rows);
|
|
1706
|
-
const status = this.renderStatus();
|
|
1707
|
-
if (this.connection === 'unsupported') {
|
|
1708
|
-
return null;
|
|
1709
|
-
}
|
|
1710
|
-
const finished = rows.some(isClearable);
|
|
1711
|
-
const showStrip = !this.drawerOpen && (sum.active > 0 || this.unread > 0);
|
|
1712
|
-
const summary = [`${sum.active} active`, sum.percent !== null && !this.drawerOpen ? `${Math.round(sum.percent)}%` : '', formatRate(sum.downBps)].filter(Boolean).join(' · ');
|
|
1713
|
-
return [
|
|
1714
|
-
this.drawerOpen && (index.h("section", { class: "drawer", "aria-label": "Transfers" }, index.h("div", { class: "drawer-h" }, index.h("h4", null, "Transfers"), index.h("span", { class: "sum" }, summary), index.h("span", { class: "sp" }), finished && (index.h("button", { type: "button", class: "lnk", onClick: () => this.clearFinished() }, "Clear finished")), index.h("button", { type: "button", class: "ib", "aria-label": "Collapse transfers", title: "Collapse", onClick: () => (this.drawerOpen = false) }, index.h(Icon, { name: "chevron", size: 12 }))), index.h("div", { class: "drawer-b" }, status ?? (rows.length ? this.renderRows(rows) : index.h(DrawerEmpty, null))))),
|
|
1715
|
-
showStrip && (index.h("button", { type: "button", class: "strip", "aria-label": "Show transfers", onClick: () => this.toggleDrawer(true) }, index.h("h4", null, "Transfers"), index.h("span", { class: "bar" }, index.h("i", { style: { width: `${sum.percent ?? 0}%` } })), index.h("span", { class: "sum" }, this.unread && !sum.active ? `${this.unread} finished` : summary), index.h(Icon, { name: "up", size: 12 }))),
|
|
1716
|
-
this.dialogOpen && (index.h(Modal, { label: "Fetch into this folder", onClose: () => this.closeDialog() }, status && this.connection !== 'ready' ? (index.h("div", { class: "dlg" }, status, index.h("div", { class: "dlg-f" }, index.h("button", { type: "button", class: "btn", onClick: () => this.closeDialog() }, "Close")))) : (this.renderForm('dialog')))),
|
|
1717
|
-
];
|
|
1718
|
-
}
|
|
1719
|
-
renderStandalone() {
|
|
1720
|
-
const status = this.renderStatus();
|
|
1721
|
-
const rows = Object.values(this.jobs);
|
|
1722
|
-
const byTab = { active: [], finished: [], retrying: [] };
|
|
1723
|
-
rows.forEach(r => byTab[tabOf(r)].push(r));
|
|
1724
|
-
const sum = summarize(rows);
|
|
1725
|
-
const shown = byTab[this.tab];
|
|
1726
|
-
const folder = this.caps?.folder ? joinPath(this.caps.folder, this.subDir) : null;
|
|
1727
|
-
return (index.h("section", { class: "standalone" }, index.h("header", { class: "sa-head" }, index.h("div", { class: "sa-title" }, index.h("h3", null, "Downloads"), index.h("span", { class: "node" }, this.name), sum.downBps > 0 && index.h("span", { class: "sum" }, formatRate(sum.downBps))), folder && (index.h("span", { class: "saving" }, "saving to ", index.h("code", null, folder), this.caps && this.caps.folder_free_bytes > 0 && index.h("span", { class: "free" }, " \u00B7 ", formatBytes(this.caps.folder_free_bytes), " free")))), status ?? [
|
|
1728
|
-
index.h("div", { class: "sa-add" }, this.renderForm('inline'), folder && !blockerFor(this.caps, this.name, this.canConfigure) && (index.h("div", { class: "sa-dest" }, index.h("span", { class: "dest" }, index.h(Icon, { name: "folder", size: 14 }), index.h("span", null, folder)), this.canPickFolder() && (index.h("button", { type: "button", class: "btn", onClick: () => this.listFolders(this.subDir ? this.subDir.split('/') : []) }, "Choose folder\u2026"))))),
|
|
1729
|
-
index.h("div", { class: "tabs", role: "tablist", "aria-label": "Downloads" }, [
|
|
1730
|
-
['active', 'Active'],
|
|
1731
|
-
['finished', 'Finished'],
|
|
1732
|
-
['retrying', 'Retrying'],
|
|
1733
|
-
].map(([id, label]) => (index.h("button", { type: "button", role: "tab", "aria-selected": this.tab === id ? 'true' : 'false', class: { on: this.tab === id }, onClick: () => (this.tab = id) }, label, index.h("b", null, byTab[id].length))))),
|
|
1734
|
-
this.tab === 'finished' && byTab.finished.length > 0 && (index.h("div", { class: "tab-h" }, index.h("span", null, byTab.finished.length, " finished"), byTab.finished.some(isClearable) && (index.h("button", { type: "button", class: "lnk", onClick: () => this.clearFinished() }, "Clear finished")))),
|
|
1735
|
-
shown.length ? (this.renderRows(shown)) : rows.length === 0 ? (index.h(StandaloneEmpty, { nodeName: this.name, folder: folder })) : (index.h("div", { class: "muted pad" }, this.tab === 'retrying' ? 'Nothing is retrying.' : this.tab === 'finished' ? 'Nothing has finished yet.' : 'Nothing is running.')),
|
|
1736
|
-
]));
|
|
1737
|
-
}
|
|
1738
|
-
render() {
|
|
1739
|
-
return (index.h(index.Host, { key: '6a7316df730c5bc4bc588f7d05e19033d98a9d0a', class: { compact: this.compact, standalone: !this.compact } }, this.compact ? this.renderCompact() : this.renderStandalone(), this.renderConfirm(), this.picker && (index.h(FolderPicker, { key: '412dc8107ea30420f022a49f188ea020eabd46f5', root: this.caps?.folder ?? '', path: this.picker.path, folders: this.picker.folders, error: this.picker.error, newName: this.picker.newName, onOpen: name => this.listFolders([...this.picker.path, name]), onUp: depth => this.listFolders(this.picker.path.slice(0, depth)), onNewName: newName => (this.picker = { ...this.picker, newName }), onCancel: () => (this.picker = null), onSave: () => this.savePicker() })), this.player && (index.h("div", { key: '61bc6c3ab32346d87c0ed02280182fdae234eb71', class: "overlay player" }, index.h("phirepass-media-player", { key: '59d99ac6289a146ba106e9cb8682d5f7b4383e26', src: this.player.src, name: this.player.name, status: this.playerStatus(), ready: this.playerReady(), positionKey: `dl:${this.player.downloadId}`, onPhirepassPlayerClose: () => (this.player = null) }))), index.h(Notices, { key: 'fa27f16c8f72435939e51b48d92b6f10b0535d80', notices: this.notices, onDismiss: id => this.dismiss(id) })));
|
|
1740
|
-
}
|
|
1741
|
-
playerRow() {
|
|
1742
|
-
return this.player ? this.jobs[this.player.downloadId] : undefined;
|
|
1743
|
-
}
|
|
1744
|
-
playerStatus() {
|
|
1745
|
-
const row = this.playerRow();
|
|
1746
|
-
if (!row) {
|
|
1747
|
-
return this.player ? 'On the node' : undefined;
|
|
1748
|
-
}
|
|
1749
|
-
if (isFinished(row.state)) {
|
|
1750
|
-
return 'On the node';
|
|
1751
|
-
}
|
|
1752
|
-
const pct = row.total_bytes ? ` · ${((row.done_bytes / row.total_bytes) * 100).toFixed(1)}%` : '';
|
|
1753
|
-
return `${row.state === 'Downloading' ? 'Downloading' : row.state}${pct}`;
|
|
1754
|
-
}
|
|
1755
|
-
playerReady() {
|
|
1756
|
-
const row = this.playerRow();
|
|
1757
|
-
if (!row || isFinished(row.state)) {
|
|
1758
|
-
return undefined;
|
|
1759
|
-
}
|
|
1760
|
-
const file = playCheck(row);
|
|
1761
|
-
return file.file?.ready_from_start;
|
|
1762
|
-
}
|
|
1763
|
-
static get watchers() { return {
|
|
1764
|
-
"channel": [{
|
|
1765
|
-
"onChannel": 0
|
|
1766
|
-
}],
|
|
1767
|
-
"connected": [{
|
|
1768
|
-
"onConnected": 0
|
|
1769
|
-
}],
|
|
1770
|
-
"browsingPath": [{
|
|
1771
|
-
"onBrowsing": 0
|
|
1772
|
-
}],
|
|
1773
|
-
"browsingService": [{
|
|
1774
|
-
"onBrowsing": 0
|
|
1775
|
-
}],
|
|
1776
|
-
"nodeId": [{
|
|
1777
|
-
"onNode": 0
|
|
1778
|
-
}]
|
|
1779
|
-
}; }
|
|
1780
|
-
};
|
|
1781
|
-
PhirepassDownloader.style = phirepassDownloaderCss();
|
|
1782
|
-
|
|
1783
|
-
const MIME = {
|
|
1784
|
-
mp4: 'video/mp4',
|
|
1785
|
-
m4v: 'video/mp4',
|
|
1786
|
-
webm: 'video/webm',
|
|
1787
|
-
mkv: 'video/x-matroska',
|
|
1788
|
-
mov: 'video/quicktime',
|
|
1789
|
-
mp3: 'audio/mpeg',
|
|
1790
|
-
m4a: 'audio/mp4',
|
|
1791
|
-
flac: 'audio/flac',
|
|
1792
|
-
ogg: 'audio/ogg',
|
|
1793
|
-
oga: 'audio/ogg',
|
|
1794
|
-
opus: 'audio/ogg',
|
|
1795
|
-
wav: 'audio/wav',
|
|
1796
|
-
};
|
|
1797
|
-
function extOf(name) {
|
|
1798
|
-
const m = /\.([a-z0-9]+)$/i.exec(name);
|
|
1799
|
-
return m ? m[1].toLowerCase() : '';
|
|
1800
|
-
}
|
|
1801
|
-
/** Mime from the extension, as the agent's stream server decides it. */
|
|
1802
|
-
function mimeFor(name) {
|
|
1803
|
-
return MIME[extOf(name)] ?? 'application/octet-stream';
|
|
1804
|
-
}
|
|
1805
|
-
function isAudio(name, mime) {
|
|
1806
|
-
return (mime ?? mimeFor(name)).startsWith('audio/');
|
|
1807
|
-
}
|
|
1808
|
-
/**
|
|
1809
|
-
* Whether a Cast receiver can play this. The Default Media Receiver plays MP4
|
|
1810
|
-
* (H.264/AAC), WebM and common audio, mostly not MKV or MOV.
|
|
1811
|
-
*/
|
|
1812
|
-
function castBlocker(name, mime) {
|
|
1813
|
-
const m = mime ?? mimeFor(name);
|
|
1814
|
-
if (m === 'video/x-matroska') {
|
|
1815
|
-
return 'TVs cannot play MKV files. Download it and play it with VLC.';
|
|
1816
|
-
}
|
|
1817
|
-
if (m === 'video/quicktime') {
|
|
1818
|
-
return 'TVs cannot play MOV files.';
|
|
1819
|
-
}
|
|
1820
|
-
return null;
|
|
1821
|
-
}
|
|
1822
|
-
/** `src` with its ticket, absolute, since it leaves this page. */
|
|
1823
|
-
function ticketUrl(src, ticket, base = globalThis.location?.href) {
|
|
1824
|
-
// An invalid base throws even for an absolute src, so it is used only
|
|
1825
|
-
// when src needs one.
|
|
1826
|
-
const url = /^[a-z][a-z0-9+.-]*:/i.test(src) ? new URL(src) : new URL(src, base);
|
|
1827
|
-
url.searchParams.set('ticket', ticket);
|
|
1828
|
-
return url.href;
|
|
1829
|
-
}
|
|
1830
|
-
/** POSTs the stream URL with the session cookie; the server answers `{ ticket }`. */
|
|
1831
|
-
function fetchLinkMinter(fetcher = (input, init) => fetch(input, init)) {
|
|
1832
|
-
return async (src) => {
|
|
1833
|
-
try {
|
|
1834
|
-
const res = await fetcher(src, { method: 'POST', credentials: 'include' });
|
|
1835
|
-
if (!res.ok) {
|
|
1836
|
-
return null;
|
|
1837
|
-
}
|
|
1838
|
-
const body = (await res.json());
|
|
1839
|
-
return typeof body.ticket === 'string' && body.ticket ? ticketUrl(src, body.ticket) : null;
|
|
1840
|
-
}
|
|
1841
|
-
catch {
|
|
1842
|
-
return null;
|
|
1843
|
-
}
|
|
1844
|
-
};
|
|
1845
|
-
}
|
|
1846
|
-
/** Nothing is saved in the first 30 seconds. */
|
|
1847
|
-
const SAVE_AFTER_SECS = 30;
|
|
1848
|
-
const SAVE_EVERY_MS = 10_000;
|
|
1849
|
-
/** Past 95%, or within the last two minutes, the file counts as watched and the position is cleared. */
|
|
1850
|
-
function isWatched(secs, duration) {
|
|
1851
|
-
if (!Number.isFinite(duration) || duration <= 0) {
|
|
1852
|
-
return false;
|
|
1853
|
-
}
|
|
1854
|
-
return secs >= duration * 0.95 || duration - secs <= 120;
|
|
1855
|
-
}
|
|
1856
|
-
function positionAction(secs, duration) {
|
|
1857
|
-
if (isWatched(secs, duration)) {
|
|
1858
|
-
return 'clear';
|
|
1859
|
-
}
|
|
1860
|
-
if (secs < SAVE_AFTER_SECS) {
|
|
1861
|
-
return 'skip';
|
|
1862
|
-
}
|
|
1863
|
-
return 'save';
|
|
1864
|
-
}
|
|
1865
|
-
const LS_PREFIX = 'phirepass.player.position.';
|
|
1866
|
-
/** The fallback store, per browser. Every access is guarded: storage can be missing or refuse. */
|
|
1867
|
-
const localPositionStore = {
|
|
1868
|
-
async get(key) {
|
|
1869
|
-
try {
|
|
1870
|
-
const raw = window.localStorage.getItem(LS_PREFIX + key);
|
|
1871
|
-
if (!raw) {
|
|
1872
|
-
return null;
|
|
1873
|
-
}
|
|
1874
|
-
const value = JSON.parse(raw);
|
|
1875
|
-
return typeof value?.secs === 'number' ? value : null;
|
|
1876
|
-
}
|
|
1877
|
-
catch {
|
|
1878
|
-
return null;
|
|
1879
|
-
}
|
|
1880
|
-
},
|
|
1881
|
-
async set(key, secs, duration) {
|
|
1882
|
-
try {
|
|
1883
|
-
window.localStorage.setItem(LS_PREFIX + key, JSON.stringify({ secs, duration, at: Date.now() }));
|
|
1884
|
-
}
|
|
1885
|
-
catch {
|
|
1886
|
-
// Nothing to do: the next visit starts from the beginning.
|
|
1887
|
-
}
|
|
1888
|
-
},
|
|
1889
|
-
async clear(key) {
|
|
1890
|
-
try {
|
|
1891
|
-
window.localStorage.removeItem(LS_PREFIX + key);
|
|
1892
|
-
}
|
|
1893
|
-
catch {
|
|
1894
|
-
// ignore
|
|
1895
|
-
}
|
|
1896
|
-
},
|
|
1897
|
-
};
|
|
1898
|
-
|
|
1899
|
-
const phirepassMediaPlayerCss = () => `:host{--card:220 18% 10%;--bg:216 18% 7%;--border:220 15% 18%;--primary:160 60% 45%;--primary-foreground:220 20% 7%;--muted:220 15% 13%;--muted-foreground:215 10% 52%;--foreground:210 20% 90%;--amber:38 75% 55%;display:flex;flex-direction:column;background:hsl(var(--card));color:hsl(var(--foreground));border:1px solid hsl(var(--border));border-radius:8px;overflow:hidden;font-family:ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;font-size:13px;line-height:1.45;box-shadow:0 20px 50px -10px rgba(0, 0, 0, 0.7)}*{box-sizing:border-box}button,a.btn{font:inherit;color:inherit;cursor:pointer}:focus-visible{outline:2px solid hsl(var(--primary));outline-offset:2px}.bar{display:flex;align-items:center;gap:8px;padding:8px 10px;border-bottom:1px solid hsl(var(--border));min-width:0}.nm{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.pill{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;padding:2px 7px;border-radius:3px;white-space:nowrap;background:hsl(var(--primary) / 0.18);color:hsl(var(--primary));flex:none}.sp{flex:1}.ib{width:28px;height:28px;display:inline-grid;place-items:center;border-radius:4px;border:1px solid transparent;background:transparent;color:hsl(var(--muted-foreground));padding:0;flex:none}.ib:hover:not(:disabled){background:hsl(var(--muted));color:hsl(var(--foreground))}.ib:disabled{opacity:0.4;cursor:not-allowed}.btn{border-radius:4px;padding:7px 14px;font-size:12px;font-weight:600;border:1px solid hsl(var(--border));background:hsl(var(--muted));text-decoration:none;display:inline-flex;align-items:center}.btn.pri{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground))}.stage{position:relative;background:#000;min-height:220px;display:grid}.stage.audio{min-height:0;background:hsl(var(--bg));padding:14px}.stage>video,.stage>audio{grid-area:1 / 1;width:100%;max-height:70vh;display:block}.stage>audio{align-self:center}.stage>.hidden{visibility:hidden}.stage-msg{grid-area:1 / 1;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;gap:8px;padding:22px;z-index:1}.stage.audio .stage-msg{padding:8px}.overlay-msg{background:rgba(0, 0, 0, 0.55);pointer-events:none}.stage-msg>svg{color:hsl(var(--amber))}.stage-msg[data-phase='casting']>svg{color:hsl(var(--primary))}.stage-msg b{font-size:14px;font-weight:600}.stage-msg span{color:hsl(var(--muted-foreground));font-size:12px;max-width:44ch}.stage-msg .clock{font-family:ui-monospace, SFMono-Regular, Menlo, monospace;font-variant-numeric:tabular-nums}.stage-msg .row{display:flex;gap:8px;margin-top:4px}.spin{width:26px;height:26px;border-radius:50%;border:3px solid hsl(var(--border));border-top-color:hsl(var(--primary));animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}@media (prefers-reduced-motion: reduce){.spin{animation:none}}.link-note{margin:0;padding:6px 10px;font-size:12px;color:var(--w-dim, #737f8c);overflow-wrap:anywhere;border-top:1px solid var(--w-border, #262c35)}`;
|
|
1900
|
-
|
|
1901
|
-
const PhirepassMediaPlayer = class {
|
|
1902
|
-
constructor(hostRef) {
|
|
1903
|
-
if (new.target === PhirepassMediaPlayer)
|
|
1904
|
-
index.registerInstance(this, hostRef);
|
|
1905
|
-
this.playerClose = index.createEvent(this, "phirepassPlayerClose");
|
|
1906
|
-
}
|
|
1907
|
-
get el() { return index.getElement(this); }
|
|
1908
|
-
media;
|
|
1909
|
-
lastSave = 0;
|
|
1910
|
-
resumeAt = 0;
|
|
1911
|
-
everPlayed = false;
|
|
1912
|
-
/** A stored position was offered (G6): then `startAt` plays, not `autoplay`. */
|
|
1913
|
-
positionPrompted = false;
|
|
1914
|
-
availabilityId;
|
|
1915
|
-
onRemoteConnect = () => (this.phase = 'casting');
|
|
1916
|
-
onRemoteDisconnect = () => {
|
|
1917
|
-
if (this.phase === 'casting') {
|
|
1918
|
-
this.phase = this.everPlayed ? 'playing' : 'buffering';
|
|
1919
|
-
}
|
|
1920
|
-
};
|
|
1921
|
-
/** The stream URL: `/api/web/stream/{node}/{download}/{file}` or a listing token URL. */
|
|
1922
|
-
src;
|
|
1923
|
-
name;
|
|
1924
|
-
/** Overrides the mime the extension implies. */
|
|
1925
|
-
mime;
|
|
1926
|
-
/** The status line above the picture, from the job: “Downloading · 23.4%”, “On the node”. */
|
|
1927
|
-
status;
|
|
1928
|
-
/** Bytes ready from the start of the file, while it is still downloading. */
|
|
1929
|
-
ready;
|
|
1930
|
-
/** “Continue watching”. Without one, positions stay in this browser. */
|
|
1931
|
-
positionStore;
|
|
1932
|
-
/** Key for the stored position: `dl:<download_id>:<file>` or `node:<node_id>:<path>`. */
|
|
1933
|
-
positionKey;
|
|
1934
|
-
/** Stands in for `video.remote`, for demos and tests (like `channelFactory`). */
|
|
1935
|
-
remotePlayback;
|
|
1936
|
-
/** Makes the link a TV or VLC opens (T2.9). Defaults to POSTing `src`. */
|
|
1937
|
-
linkMinter;
|
|
1938
|
-
/** Shown while casting, when the host knows the device's name. */
|
|
1939
|
-
castDevice;
|
|
1940
|
-
playerClose;
|
|
1941
|
-
phase = 'buffering';
|
|
1942
|
-
stored = null;
|
|
1943
|
-
castAvailable = false;
|
|
1944
|
-
/** The ticket URL the element plays from once casting was asked for. */
|
|
1945
|
-
castSrc = null;
|
|
1946
|
-
linkNote = null;
|
|
1947
|
-
currentTime = 0;
|
|
1948
|
-
duration = 0;
|
|
1949
|
-
get store() {
|
|
1950
|
-
return this.positionStore ?? localPositionStore;
|
|
1951
|
-
}
|
|
1952
|
-
get audio() {
|
|
1953
|
-
return isAudio(this.name, this.mime);
|
|
1954
|
-
}
|
|
1955
|
-
async componentWillLoad() {
|
|
1956
|
-
if (this.positionKey) {
|
|
1957
|
-
const stored = await this.store.get(this.positionKey).catch(() => null);
|
|
1958
|
-
if (stored && positionAction(stored.secs, stored.duration) === 'save') {
|
|
1959
|
-
this.stored = stored;
|
|
1960
|
-
this.positionPrompted = true;
|
|
1961
|
-
this.phase = 'prompt';
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
componentDidLoad() {
|
|
1966
|
-
void this.watchRemote();
|
|
1967
|
-
}
|
|
1968
|
-
disconnectedCallback() {
|
|
1969
|
-
void this.savePosition(true);
|
|
1970
|
-
const remote = this.remote();
|
|
1971
|
-
if (remote) {
|
|
1972
|
-
remote.removeEventListener('connect', this.onRemoteConnect);
|
|
1973
|
-
remote.removeEventListener('disconnect', this.onRemoteDisconnect);
|
|
1974
|
-
if (this.availabilityId !== undefined) {
|
|
1975
|
-
void remote.cancelWatchAvailability(this.availabilityId).catch(() => undefined);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
onSrc() {
|
|
1980
|
-
this.castSrc = null;
|
|
1981
|
-
this.everPlayed = false;
|
|
1982
|
-
this.phase = 'buffering';
|
|
1983
|
-
}
|
|
1984
|
-
/** Closes the player, saving where it stopped. The download is not affected. */
|
|
1985
|
-
async close() {
|
|
1986
|
-
await this.savePosition(true);
|
|
1987
|
-
this.media?.pause?.();
|
|
1988
|
-
this.playerClose.emit();
|
|
1989
|
-
}
|
|
1990
|
-
get minter() {
|
|
1991
|
-
return this.linkMinter ?? fetchLinkMinter();
|
|
1992
|
-
}
|
|
1993
|
-
/**
|
|
1994
|
-
* The TV fetches the file itself and has no cookie, so the element first
|
|
1995
|
-
* moves to a ticket URL (same bytes, same position), then the device picker
|
|
1996
|
-
* opens. A ticket that cannot be had still opens the picker: on a
|
|
1997
|
-
* development stack the plain URL plays.
|
|
1998
|
-
*/
|
|
1999
|
-
async cast() {
|
|
2000
|
-
if (!this.castSrc) {
|
|
2001
|
-
const url = await this.minter(this.src);
|
|
2002
|
-
const media = this.media;
|
|
2003
|
-
if (url && media) {
|
|
2004
|
-
const at = media.currentTime;
|
|
2005
|
-
const playing = !media.paused;
|
|
2006
|
-
this.castSrc = url;
|
|
2007
|
-
media.src = url;
|
|
2008
|
-
this.resumeAt = at;
|
|
2009
|
-
if (at > 0) {
|
|
2010
|
-
media.currentTime = at;
|
|
2011
|
-
}
|
|
2012
|
-
if (playing) {
|
|
2013
|
-
void media.play?.()?.catch?.(() => undefined);
|
|
2014
|
-
}
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
await this.remote()?.prompt().catch(() => undefined);
|
|
2018
|
-
}
|
|
2019
|
-
/** “Copy link for VLC”: the same ticket, on the clipboard. */
|
|
2020
|
-
async copyLink() {
|
|
2021
|
-
const url = this.castSrc ?? (await this.minter(this.src));
|
|
2022
|
-
if (!url) {
|
|
2023
|
-
this.linkNote = 'Could not make a link.';
|
|
2024
|
-
return;
|
|
2025
|
-
}
|
|
2026
|
-
try {
|
|
2027
|
-
await navigator.clipboard.writeText(url);
|
|
2028
|
-
this.linkNote = 'Link copied. It works in VLC until it expires.';
|
|
2029
|
-
}
|
|
2030
|
-
catch {
|
|
2031
|
-
this.linkNote = url;
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
remote() {
|
|
2035
|
-
return this.remotePlayback ?? this.media?.remote;
|
|
2036
|
-
}
|
|
2037
|
-
async watchRemote() {
|
|
2038
|
-
const remote = this.remote();
|
|
2039
|
-
if (!remote || this.audio) {
|
|
2040
|
-
return;
|
|
2041
|
-
}
|
|
2042
|
-
remote.addEventListener('connect', this.onRemoteConnect);
|
|
2043
|
-
remote.addEventListener('disconnect', this.onRemoteDisconnect);
|
|
2044
|
-
if (remote.state === 'connected') {
|
|
2045
|
-
this.phase = 'casting';
|
|
2046
|
-
}
|
|
2047
|
-
try {
|
|
2048
|
-
this.availabilityId = await remote.watchAvailability(available => (this.castAvailable = available));
|
|
2049
|
-
}
|
|
2050
|
-
catch {
|
|
2051
|
-
// Browsers that cannot watch (Safari without a device, or a policy) still allow prompt() on click.
|
|
2052
|
-
this.castAvailable = true;
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
async savePosition(force = false) {
|
|
2056
|
-
const media = this.media;
|
|
2057
|
-
if (!media || !this.positionKey || !this.everPlayed) {
|
|
2058
|
-
return;
|
|
2059
|
-
}
|
|
2060
|
-
const now = Date.now();
|
|
2061
|
-
if (!force && now - this.lastSave < SAVE_EVERY_MS) {
|
|
2062
|
-
return;
|
|
2063
|
-
}
|
|
2064
|
-
this.lastSave = now;
|
|
2065
|
-
const action = positionAction(media.currentTime, media.duration);
|
|
2066
|
-
if (action === 'save') {
|
|
2067
|
-
await this.store.set(this.positionKey, media.currentTime, media.duration).catch(() => undefined);
|
|
2068
|
-
}
|
|
2069
|
-
else if (action === 'clear') {
|
|
2070
|
-
await this.store.clear?.(this.positionKey).catch(() => undefined);
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
startAt(secs) {
|
|
2074
|
-
this.stored = null;
|
|
2075
|
-
this.phase = 'buffering';
|
|
2076
|
-
this.resumeAt = secs;
|
|
2077
|
-
const media = this.media;
|
|
2078
|
-
if (media) {
|
|
2079
|
-
if (secs > 0) {
|
|
2080
|
-
media.currentTime = secs;
|
|
2081
|
-
}
|
|
2082
|
-
void media.play?.()?.catch?.(() => undefined);
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
retry() {
|
|
2086
|
-
const media = this.media;
|
|
2087
|
-
const at = media?.currentTime || this.resumeAt;
|
|
2088
|
-
this.phase = 'buffering';
|
|
2089
|
-
if (media) {
|
|
2090
|
-
media.load?.();
|
|
2091
|
-
this.startAt(at);
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
onError() {
|
|
2095
|
-
const code = this.media?.error?.code;
|
|
2096
|
-
// 2: the network dropped (the node went away or the session ended). 3 and 4: the browser cannot decode it.
|
|
2097
|
-
this.phase = code === 2 ? 'stopped' : 'unsupported';
|
|
2098
|
-
}
|
|
2099
|
-
bindMedia(el) {
|
|
2100
|
-
if (!el || el === this.media) {
|
|
2101
|
-
return;
|
|
2102
|
-
}
|
|
2103
|
-
this.media = el;
|
|
2104
|
-
}
|
|
2105
|
-
renderStage() {
|
|
2106
|
-
switch (this.phase) {
|
|
2107
|
-
case 'prompt':
|
|
2108
|
-
return (index.h("div", { class: "stage-msg", "data-phase": "prompt" }, index.h("b", null, "Resume from ", formatClock(this.stored.secs), "?"), index.h("span", null, "You stopped here on ", formatDay(this.stored.at), ". ", formatClock(this.stored.duration), " in total."), index.h("div", { class: "row" }, index.h("button", { type: "button", class: "btn", onClick: () => this.startAt(0) }, "Start over"), index.h("button", { type: "button", class: "btn pri", onClick: () => this.startAt(this.stored.secs) }, "Resume"))));
|
|
2109
|
-
case 'buffering':
|
|
2110
|
-
return (index.h("div", { class: "stage-msg overlay-msg", "data-phase": "buffering" }, index.h("span", { class: "spin", "aria-hidden": "true" }), index.h("b", null, "Buffering"), this.ready !== undefined && index.h("span", null, formatBytes(this.ready), " ready from the start")));
|
|
2111
|
-
case 'waiting':
|
|
2112
|
-
return (index.h("div", { class: "stage-msg overlay-msg", "data-phase": "waiting" }, index.h("span", { class: "spin", "aria-hidden": "true" }), index.h("b", null, "Waiting for this part to download"), index.h("span", null, "You skipped ahead of what the node has. Playback resumes by itself.")));
|
|
2113
|
-
case 'unsupported':
|
|
2114
|
-
return (index.h("div", { class: "stage-msg", "data-phase": "unsupported" }, index.h(Icon, { name: "warn", size: 28 }), index.h("b", null, "This browser cannot play this format"), index.h("span", null, "The download is not affected. Download the file to play it in another app."), index.h("a", { class: "btn pri", href: this.src, download: this.name }, "Download file")));
|
|
2115
|
-
case 'stopped':
|
|
2116
|
-
return (index.h("div", { class: "stage-msg", "data-phase": "stopped" }, index.h(Icon, { name: "signal", size: 28 }), index.h("b", null, "Playback stopped"), index.h("span", null, "The connection to the node was lost."), index.h("button", { type: "button", class: "btn pri", onClick: () => this.retry() }, "Try again")));
|
|
2117
|
-
case 'casting':
|
|
2118
|
-
return (index.h("div", { class: "stage-msg", "data-phase": "casting" }, index.h(Icon, { name: "cast", size: 28 }), index.h("b", null, "Playing on ", this.castDevice ?? 'your TV'), index.h("span", null, "The TV reads the file from the node. You can close this tab."), index.h("span", { class: "clock" }, formatClock(this.currentTime), " / ", formatClock(this.duration)), index.h("button", { type: "button", class: "btn", onClick: () => void this.remote()?.prompt().catch(() => undefined) }, "Stop casting")));
|
|
2119
|
-
default:
|
|
2120
|
-
return null;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
render() {
|
|
2124
|
-
const audio = this.audio;
|
|
2125
|
-
const blocked = castBlocker(this.name, this.mime);
|
|
2126
|
-
const airplay = typeof this.media?.webkitShowPlaybackTargetPicker === 'function';
|
|
2127
|
-
const hideMedia = this.phase === 'prompt' || this.phase === 'unsupported' || this.phase === 'stopped' || this.phase === 'casting';
|
|
2128
|
-
const common = {
|
|
2129
|
-
ref: (el) => this.bindMedia(el),
|
|
2130
|
-
src: this.castSrc ?? this.src,
|
|
2131
|
-
controls: true,
|
|
2132
|
-
// Play was pressed to get here; a stored position asks first (G6).
|
|
2133
|
-
preload: this.phase === 'prompt' ? 'metadata' : 'auto',
|
|
2134
|
-
autoplay: !this.positionPrompted,
|
|
2135
|
-
playsInline: true,
|
|
2136
|
-
class: { hidden: hideMedia },
|
|
2137
|
-
onCanPlay: () => {
|
|
2138
|
-
if (this.phase === 'buffering' || this.phase === 'waiting') {
|
|
2139
|
-
this.phase = 'playing';
|
|
2140
|
-
}
|
|
2141
|
-
},
|
|
2142
|
-
onPlaying: () => {
|
|
2143
|
-
this.everPlayed = true;
|
|
2144
|
-
if (this.phase !== 'casting') {
|
|
2145
|
-
this.phase = 'playing';
|
|
2146
|
-
}
|
|
2147
|
-
},
|
|
2148
|
-
onWaiting: () => {
|
|
2149
|
-
if (this.phase === 'playing') {
|
|
2150
|
-
this.phase = this.everPlayed ? 'waiting' : 'buffering';
|
|
2151
|
-
}
|
|
2152
|
-
},
|
|
2153
|
-
onTimeUpdate: (e) => {
|
|
2154
|
-
const m = e.target;
|
|
2155
|
-
this.currentTime = m.currentTime;
|
|
2156
|
-
void this.savePosition();
|
|
2157
|
-
},
|
|
2158
|
-
onDurationChange: (e) => (this.duration = e.target.duration || 0),
|
|
2159
|
-
onPause: () => void this.savePosition(true),
|
|
2160
|
-
onError: () => this.onError(),
|
|
2161
|
-
};
|
|
2162
|
-
return (index.h(index.Host, { key: '2a0961d6bb91d0d28c516e42b11c8988a7721c99', class: { audio } }, index.h("header", { key: 'c2339f0ca216eb347a09c9be77df877a54cf8b47', class: "bar" }, index.h("span", { key: 'ae5b874219ff03c803febb079027549ee68751b6', class: "nm", title: this.name }, this.name), this.status && index.h("span", { key: '09ccaae203ecb0c205bd2e4b1ac9fc2f5d9b22a1', class: "pill" }, this.status), index.h("span", { key: '7304adbb0b50a3bcf8c4783f3444029f97e84fa9', class: "sp" }), !audio && (this.castAvailable || blocked) && (index.h("button", { key: '5c2b9d5d36ae0fd723d81da54e8e4acbf79a39d0', type: "button", class: "ib", disabled: !!blocked, title: blocked ?? 'Cast', "aria-label": blocked ? `Cast unavailable: ${blocked}` : 'Cast', onClick: () => void this.cast() }, index.h(Icon, { key: 'f45d71a1a5b1144376b6360812185dcbc7e5e57f', name: "cast", size: 15 }))), index.h("button", { key: '71964d197aee9de089f895fd0c017e1e4e04297a', type: "button", class: "ib", title: "Copy link for VLC", "aria-label": "Copy link for VLC", onClick: () => void this.copyLink() }, index.h(Icon, { key: '643d026d4dd85cad24e1e6b01dcba1bfda956825', name: "link", size: 15 })), !audio && airplay && (index.h("button", { key: 'a42d75246d807366e427b660062b47cc03890fac', type: "button", class: "ib", title: "AirPlay", "aria-label": "AirPlay", onClick: () => this.media.webkitShowPlaybackTargetPicker() }, index.h(Icon, { key: '21c9dc4e3ea560f72d230b017f2f73314ae17ef4', name: "cast", size: 15 }))), index.h("button", { key: 'f1413cec5dceb9f1dfe9b0470d3784ccaf20d08a', type: "button", class: "ib", "aria-label": "Close player", title: "Close", onClick: () => void this.close() }, index.h(Icon, { key: '707e719e7608edbad68185c8071ab90e2da614d4', name: "x", size: 14 }))), index.h("div", { key: '51673733f9cd732cfe5f1b9406ddec3787ba0e6c', class: { stage: true, audio }, "data-phase": this.phase }, audio ? index.h("audio", { ...common }) : index.h("video", { ...common }), this.renderStage()), this.linkNote && (index.h("p", { key: 'bd2db764da4183f67d1589a8be5aa4e8e7df76f3', class: "link-note", role: "status" }, this.linkNote))));
|
|
2163
|
-
}
|
|
2164
|
-
static get watchers() { return {
|
|
2165
|
-
"src": [{
|
|
2166
|
-
"onSrc": 0
|
|
2167
|
-
}]
|
|
2168
|
-
}; }
|
|
2169
|
-
};
|
|
2170
|
-
PhirepassMediaPlayer.style = phirepassMediaPlayerCss();
|
|
2171
|
-
|
|
2172
|
-
/**
|
|
2173
|
-
* The SFTP browser's side of Remote Fetch, kept out of the component so it
|
|
2174
|
-
* stays a host and nothing more: the downloads themselves are the
|
|
2175
|
-
* `<phirepass-downloader>`'s, and nothing here goes over SFTP.
|
|
2176
|
-
*/
|
|
2177
|
-
const PART_SUFFIX = '.phirepass-part';
|
|
2178
|
-
function isPartFile(name) {
|
|
2179
|
-
return name.endsWith(PART_SUFFIX);
|
|
2180
|
-
}
|
|
2181
|
-
const PLAYABLE = /\.(mp4|m4v|webm|mkv|mov|mp3|m4a|flac|ogg|oga|opus|wav)$/i;
|
|
2182
|
-
function isPlayableFile(name) {
|
|
2183
|
-
return PLAYABLE.test(name) && !isPartFile(name);
|
|
2184
|
-
}
|
|
2185
|
-
function normalize(path) {
|
|
2186
|
-
const p = path.replace(/\/{2,}/g, '/');
|
|
2187
|
-
return p.length > 1 ? p.replace(/\/+$/, '') : p;
|
|
2188
|
-
}
|
|
2189
|
-
/** Whether a finished download's folder is the one on screen. */
|
|
2190
|
-
function sameFolder(a, b) {
|
|
2191
|
-
return normalize(a) === normalize(b);
|
|
2192
|
-
}
|
|
2193
|
-
function folderOfCompleted(detail) {
|
|
2194
|
-
return normalize(detail.sub_dir ? `${detail.dest_root}/${detail.sub_dir}` : detail.dest_root);
|
|
2195
|
-
}
|
|
2196
|
-
const FetchButton = ({ count, onClick }) => (index.h("button", { type: "button", class: "action fetch", onClick: onClick, title: "Fetch from a link, magnet or torrent", "aria-label": "Fetch from a link, magnet or torrent" }, index.h(Icon, { name: "fetch", size: 14 }), count > 0 && (index.h("span", { class: "badge", "aria-label": `${count} active` }, count))));
|
|
2197
|
-
/** K3: replaces the plain delete prompt for a part file that belongs to a running download. */
|
|
2198
|
-
const PartDeleteDialog = ({ name, busy, onCancel, onConfirm }) => (index.h("section", { class: "delete-modal visible" }, index.h("div", { class: "delete-dialog", role: "dialog", "aria-modal": "true", "aria-label": "This file is still downloading", tabindex: -1, onKeyDown: e => {
|
|
2199
|
-
if (e.key === 'Escape') {
|
|
2200
|
-
onCancel();
|
|
2201
|
-
}
|
|
2202
|
-
} }, index.h("div", { class: "title" }, "This file is still downloading"), index.h("div", { class: "message" }, "Deleting ", index.h("span", { class: "file-name inline" }, name), " deletes its download."), index.h("div", { class: "modal-actions" }, index.h("button", { type: "button", class: "btn secondary", onClick: onCancel, disabled: busy }, "Keep it"), index.h("button", { type: "button", class: "btn destructive", onClick: onConfirm, disabled: busy }, "Delete download")))));
|
|
2203
|
-
/** C: right-click a `.torrent` that lies inside the node's download folder. */
|
|
2204
|
-
const TorrentContextMenu = ({ menu, onFetch, onDownload, onRename, onDelete, onClose, }) => (index.h("div", { class: "context-backdrop", onClick: onClose, onContextMenu: e => (e.preventDefault(), onClose()) }, index.h("div", { class: "context-menu", role: "menu", "aria-label": `Actions for ${menu.name}`, style: { left: `${menu.x}px`, top: `${menu.y}px` }, onClick: e => e.stopPropagation() }, index.h("button", { type: "button", role: "menuitem", class: "primary", onClick: onFetch }, index.h(Icon, { name: "fetch", size: 13 }), " Download torrent contents here"), index.h("hr", null), index.h("button", { type: "button", role: "menuitem", onClick: onDownload }, "Download"), index.h("button", { type: "button", role: "menuitem", onClick: onRename }, "Rename"), index.h("button", { type: "button", role: "menuitem", class: "danger", onClick: onDelete }, "Delete"))));
|
|
2205
|
-
|
|
2206
|
-
const phirepassSftpClientLogoSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoNDYsIDE4NCwgMTM4KSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiCiAgICBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10ZXJtaW5hbCB3LTMuNSBoLTMuNSB0ZXh0LXByaW1hcnkiPgogICAgPHBvbHlsaW5lIHBvaW50cz0iNCAxNyAxMCAxMSA0IDUiPjwvcG9seWxpbmU+CiAgICA8bGluZSB4MT0iMTIiIHgyPSIyMCIgeTE9IjE5IiB5Mj0iMTkiPjwvbGluZT4KPC9zdmc+Cg==';
|
|
2207
|
-
|
|
2208
|
-
const phirepassSftpClientMaxSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTE1LCAxMjMsIDE0MCkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtbWF4aW1pemUyIHctMyBoLTMiPgogICAgPHBvbHlsaW5lIHBvaW50cz0iMTUgMyAyMSAzIDIxIDkiPjwvcG9seWxpbmU+CiAgICA8cG9seWxpbmUgcG9pbnRzPSI5IDIxIDMgMjEgMyAxNSI+PC9wb2x5bGluZT4KICAgIDxsaW5lIHgxPSIyMSIgeDI9IjE0IiB5MT0iMyIgeTI9IjEwIj48L2xpbmU+CiAgICA8bGluZSB4MT0iMyIgeDI9IjEwIiB5MT0iMjEiIHkyPSIxNCI+PC9saW5lPgo8L3N2Zz4K';
|
|
2209
|
-
|
|
2210
|
-
const phirepassSftpClientChevronSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogICAgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIKICAgIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWNoZXZyb24tcmlnaHQgdy0zIGgtMyB0ZXh0LW11dGVkLWZvcmVncm91bmQvNTAgc2hyaW5rLTAiPgogICAgPHBhdGggZD0ibTkgMTggNi02LTYtNiI+PC9wYXRoPgo8L3N2Zz4K';
|
|
2211
|
-
|
|
2212
|
-
const phirepassSftpClientFolderSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoNDYsIDE4NCwgMTM4KSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiCiAgICBjbGFzcz0ibHVjaWRlIGx1Y2lkZS1mb2xkZXIgdy0zLjUgaC0zLjUgdGV4dC1wcmltYXJ5IHNocmluay0wIj4KICAgIDxwYXRoCiAgICAgICAgZD0iTTIwIDIwYTIgMiAwIDAgMCAyLTJWOGEyIDIgMCAwIDAtMi0yaC03LjlhMiAyIDAgMCAxLTEuNjktLjlMOS42IDMuOUEyIDIgMCAwIDAgNy45MyAzSDRhMiAyIDAgMCAwLTIgMnYxM2EyIDIgMCAwIDAgMiAyWiI+PC9wYXRoPgo8L3N2Zz4K';
|
|
2213
|
-
|
|
2214
|
-
const phirepassSftpClientFileSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTE1LCAxMjMsIDE0MCkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtZmlsZSB3LTMuNSBoLTMuNSB0ZXh0LW11dGVkLWZvcmVncm91bmQgc2hyaW5rLTAiPgogICAgPHBhdGggZD0iTTE1IDJINmEyIDIgMCAwIDAtMiAydjE2YTIgMiAwIDAgMCAyIDJoMTJhMiAyIDAgMCAwIDItMlY3WiI+PC9wYXRoPgogICAgPHBhdGggZD0iTTE0IDJ2NGEyIDIgMCAwIDAgMiAyaDQiPjwvcGF0aD4KPC9zdmc+Cg==';
|
|
2215
|
-
|
|
2216
|
-
const phirepassSftpClientGoUpSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtYXJyb3ctdXAgdy0zLjUgaC0zLjUiPgogICAgPHBhdGggZD0ibTUgMTIgNy03IDcgNyI+PC9wYXRoPgogICAgPHBhdGggZD0iTTEyIDE5VjUiPjwvcGF0aD4KPC9zdmc+Cg==';
|
|
2217
|
-
|
|
2218
|
-
const phirepassSftpClientRefreshSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtcmVmcmVzaC1jdyB3LTMuNSBoLTMuNSI+CiAgICA8cGF0aCBkPSJNMyAxMmE5IDkgMCAwIDEgOS05IDkuNzUgOS43NSAwIDAgMSA2Ljc0IDIuNzRMMjEgOCI+PC9wYXRoPgogICAgPHBhdGggZD0iTTIxIDN2NWgtNSI+PC9wYXRoPgogICAgPHBhdGggZD0iTTIxIDEyYTkgOSAwIDAgMS05IDkgOS43NSA5Ljc1IDAgMCAxLTYuNzQtMi43NEwzIDE2Ij48L3BhdGg+CiAgICA8cGF0aCBkPSJNOCAxNkgzdjUiPjwvcGF0aD4KPC9zdmc+Cg==';
|
|
2219
|
-
|
|
2220
|
-
const phirepassSftpClientUploadSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtdXBsb2FkIHctMy41IGgtMy41Ij4KICAgIDxwYXRoIGQ9Ik0yMSAxNXY0YTIgMiAwIDAgMS0yIDJINWEyIDIgMCAwIDEtMi0ydi00Ij48L3BhdGg+CiAgICA8cG9seWxpbmUgcG9pbnRzPSIxNyA4IDEyIDMgNyA4Ij48L3BvbHlsaW5lPgogICAgPGxpbmUgeDE9IjEyIiB4Mj0iMTIiIHkxPSIzIiB5Mj0iMTUiPjwvbGluZT4KPC9zdmc+Cg==';
|
|
2221
|
-
|
|
2222
|
-
const phirepassSftpClientCss = () => `:host{--radius:0.375rem;--card:220 18% 10%;--border:220 15% 18%;--primary:160 60% 45%;--radius:0.375rem;--destructive:0 70% 50%;--muted:220 15% 13%;--muted-foreground:220 10% 50%;--primary-foreground:220 20% 7%;--scroll-track:220 16% 12%;--scroll-thumb:220 12% 34%;--scroll-thumb-hover:160 45% 44%;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;height:100%;width:100%;border:1px solid hsl(var(--border));background-color:hsl(var(--card));border-radius:var(--radius);overflow:hidden;display:flex;flex-direction:column;position:relative;container-type:inline-size;.listing{height:100%;display:flex;flex-direction:column;justify-content:space-between;min-height:0;header{height:30px;background:rgba(28, 31, 38, 0.6);border-bottom:1px solid hsl(var(--border));display:flex;align-items:center;justify-content:space-between;.actions{display:flex;align-items:center;.action{cursor:pointer;padding:4px;display:flex;align-items:center;z-index:1;img{height:14px;padding:4px;border-radius:4px}&:hover{background-color:hsl(var(--border) / 0.6)}}}.title{color:hsl(var(--primary));height:14px;padding:0 12px;display:flex;align-items:center;font-size:0.75rem;line-height:1rem;img{height:14px;margin-right:5px}.text{display:flex;flex-direction:row;justify-content:center;margin-top:2px;.name{margin-right:10px}.description{color:hsl(var(--muted-foreground))}}}}main{flex:1;display:flex;flex-direction:column;position:relative;min-height:0;overflow:hidden;.loader{color:hsl(var(--muted-foreground));font-size:13px;animation:pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;text-align:center;display:flex;align-items:center;justify-content:center;position:absolute;height:100%;width:100%;background:rgba(28, 31, 38, 0);backdrop-filter:blur(4px)}.error{font-size:13px;text-align:center;color:hsl(var(--destructive));height:100%;display:flex;align-items:center;justify-content:center}.navigation{height:25px;padding:10px;font-size:0.75rem;line-height:1rem;background-color:hsl(var(--card));display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid hsl(var(--border));position:sticky;top:0;z-index:3;.breadcrumbs{display:flex;align-items:center;margin-right:10px;.breadcrumb-container{white-space:nowrap;.breadcrumb{color:hsl(var(--primary));margin-right:4px;cursor:pointer;&:after{margin-left:4px}&:hover{color:rgb(189, 219, 209)}&:last-child{margin-right:0;color:rgb(189, 219, 209);cursor:default}}}.arrow{height:12px;width:12px;opacity:0.6;top:2px;margin-right:4px;position:relative}}.actions{display:flex;align-items:center;gap:8px}.filter{height:1.5rem;width:110px;padding:0 6px;font:inherit;font-size:0.68rem;color:rgb(189, 219, 209);background-color:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:calc(var(--radius) - 2px);outline:none;&::placeholder{color:hsl(var(--muted-foreground))}&:focus{border-color:hsl(var(--primary))}}.action{border:none;background:transparent;color:rgb(189, 219, 209);font-size:1.1rem;line-height:1;padding:2px 4px;border-radius:4px;cursor:pointer;&:hover{background-color:hsl(var(--border) / 0.6)}img{height:14px;width:14px;display:block}}.action.disconnect{color:#ff4d5f;font-size:0.65rem;letter-spacing:0.08em;padding:4px 8px;&:hover{color:#ff6b7a;background-color:hsl(var(--destructive) / 0.12)}}}.content{flex:1;min-height:0;outline:none;overflow:auto;font-size:0.75rem;line-height:1rem;scrollbar-width:thin;scrollbar-color:hsl(var(--scroll-thumb)) hsl(var(--scroll-track));&:focus-visible{box-shadow:inset 0 0 0 1px hsl(var(--primary) / 0.5)}&::-webkit-scrollbar{width:10px;height:10px}&::-webkit-scrollbar-track{background:hsl(var(--scroll-track))}&::-webkit-scrollbar-thumb{background:hsl(var(--scroll-thumb));border-radius:999px;border:2px solid hsl(var(--scroll-track))}&::-webkit-scrollbar-thumb:hover{background:hsl(var(--scroll-thumb-hover))}table{width:100%;border-collapse:separate;border-spacing:0;table-layout:auto;thead{background-color:hsl(var(--muted));border-bottom:1px solid hsl(var(--border));th.sortable{cursor:pointer;user-select:none;&:hover{color:hsl(var(--primary))}}th{padding:8px 10px;text-align:left;color:hsl(var(--muted-foreground));position:sticky;top:0;z-index:2;background-color:hsl(var(--muted));border-bottom:1px solid hsl(var(--border));line-height:0.95rem;&.action-col{width:58px;min-width:58px;padding:0 10px}&:first-child{width:30%;min-width:180px;max-width:195px}&:nth-child(2),&:nth-child(3),&:nth-child(4),&:nth-child(5){white-space:nowrap;width:1%}}}tbody{padding:10px 10px;tr.empty{cursor:default;td{color:hsl(var(--muted-foreground));text-align:center;padding:18px 8px}&:hover{background:transparent}}tr{border-bottom:1px solid hsl(var(--border) / 0.4);td{padding:10px 10px 9px;color:hsl(var(--muted-foreground));&:first-child{min-width:180px;max-width:195px;white-space:nowrap;.name{display:inline-block;max-width:calc(100% - 26px);overflow:hidden;text-overflow:ellipsis;vertical-align:middle}}&:nth-child(2),&:nth-child(3),&:nth-child(4),&:nth-child(5){white-space:nowrap}&.action-col{width:58px;min-width:58px;text-align:center;padding-left:1px;padding-right:1px;.file-actions{display:flex;align-items:center;justify-content:center;gap:8px}.file-action{border:none;background:transparent;color:hsl(var(--muted-foreground));width:16px;height:16px;border-radius:3px;cursor:pointer;opacity:0;visibility:hidden;pointer-events:none;transition:opacity 120ms ease;padding:0;svg{width:12px;height:12px;display:block;margin:0 auto}&:hover{color:hsl(var(--primary))}&.delete:hover{color:hsl(var(--destructive))}}}.name{&.file{color:rgb(189, 219, 209)}&.folder{color:hsl(var(--primary))}}.kind{height:14px;width:14px;margin-right:5px;top:3px;position:relative}}&:hover{cursor:pointer;background-color:hsl(var(--muted) / 0.4);td.action-col .file-action{opacity:1;visibility:visible;pointer-events:auto;color:hsl(var(--primary))}}&.selected{background-color:hsl(var(--primary) / 0.3);td.action-col .file-action{opacity:1;visibility:visible;pointer-events:auto}&:hover{background-color:hsl(var(--primary) / 0.4)}}}}}}}footer{height:25px;background:rgba(28, 31, 38, 0.6);border-top:1px solid hsl(var(--border));font-size:0.75rem;line-height:1rem;display:flex;align-items:center;justify-content:space-between;padding:0 10px;.status{font-size:0.65rem;color:hsl(var(--muted-foreground));.selected-item{margin-left:10px;color:hsl(var(--primary))}}.version{font-size:0.65rem;color:hsl(var(--muted-foreground))}}}.creds{position:absolute;top:0;left:0;height:100%;width:100%;display:flex;justify-content:center;align-items:center;;&.blurred{background:rgba(28, 31, 38, 0);backdrop-filter:blur(4px)}.auth{display:flex;flex-direction:column;background:hsl(var(--card));position:relative;background-color:rgba(21, 24, 30, 0.95);border:1px solid hsl(var(--border));padding:30px;box-shadow:rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0.5) 0px 25px 50px -12px;border-radius:var(--radius);.title{margin-bottom:12px;color:hsl(var(--primary))}label{font-size:0.75rem;line-height:1rem;margin-bottom:1rem;color:hsl(var(--muted-foreground))}input{font-size:0.875rem;line-height:1.25rem;padding-top:0.5rem;padding-bottom:0.5rem;padding-left:0.75rem;padding-right:0.75rem;background-color:rgb(28, 31, 38);border-color:rgb(39, 44, 53);border-width:1px;border-radius:calc(var(--radius) - 2px);width:100%;margin-bottom:12px;color:rgb(189, 219, 209);box-sizing:border-box;&:focus{outline:none;border-color:hsl(var(--primary));box-shadow:0 0 0 1px hsl(var(--primary))}}button[type='submit']{margin-top:12px;width:100%;background-color:hsl(var(--primary));color:hsl(var(--primary-foreground));letter-spacing:0.05em;font-size:13px;font-weight:500;padding:0.5rem 1rem;border-radius:calc(var(--radius) - 2px);height:2rem;cursor:pointer;border:none;&:hover{background-color:hsl(var(--primary) / 0.9)}}}}.upload-modal,.download-modal,.delete-modal,.prompt-modal{position:absolute;inset:0;display:none;align-items:center;justify-content:center;background:rgba(28, 31, 38, 0);backdrop-filter:blur(4px);z-index:6;&.visible{display:flex}.upload-dialog,.download-dialog,.delete-dialog,.prompt-dialog{width:min(360px, calc(100% - 24px));background-color:rgba(21, 24, 30, 0.96);border:1px solid hsl(var(--border));border-radius:var(--radius);padding:16px;box-shadow:rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0.5) 0px 25px 50px -12px;.title{color:hsl(var(--primary));font-size:0.8rem;margin-bottom:8px}.file-name{color:rgb(189, 219, 209);font-size:0.72rem;line-height:1rem;margin-bottom:10px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.progress-track{width:100%;height:10px;border-radius:999px;background-color:hsl(var(--muted));overflow:hidden;border:1px solid hsl(var(--border));.progress-fill{height:100%;width:0;background:linear-gradient(90deg, hsl(var(--primary) / 0.7), hsl(var(--primary)));transition:width 140ms ease}}.progress-meta{margin-top:8px;margin-bottom:12px;display:flex;align-items:center;justify-content:space-between;gap:10px}.progress-speed{color:hsl(var(--muted-foreground));font-size:0.75rem;font-variant-numeric:tabular-nums;line-height:1.4;text-align:left}.progress-value{color:hsl(var(--muted-foreground));font-size:0.75rem;font-variant-numeric:tabular-nums;line-height:1.4;text-align:right}.cancel{margin-top:14px;width:100%;height:2rem;border:1px solid hsl(var(--border));border-radius:calc(var(--radius) - 2px);background:hsl(var(--muted));color:rgb(189, 219, 209);font-size:0.75rem;letter-spacing:0.03em;cursor:pointer;&:hover{border-color:hsl(var(--primary));color:hsl(var(--primary))}&.finished{background-color:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground));&:hover{background-color:hsl(var(--primary) / 0.9);border-color:hsl(var(--primary) / 0.9);color:hsl(var(--primary-foreground))}}}.message{color:rgb(189, 219, 209);font-size:0.74rem;line-height:1rem;margin-bottom:8px}.modal-actions{margin-top:14px;display:grid;grid-template-columns:1fr 1fr;gap:8px;.btn{height:2rem;border:1px solid hsl(var(--border));border-radius:calc(var(--radius) - 2px);font-size:0.75rem;letter-spacing:0.03em;cursor:pointer;&:disabled{opacity:0.65;cursor:not-allowed}}.btn.secondary{background:hsl(var(--muted));color:rgb(189, 219, 209);&:hover{border-color:hsl(var(--primary));color:hsl(var(--primary))}}.btn.destructive{background:hsl(var(--destructive));border-color:hsl(var(--destructive));color:white;&:hover{background:hsl(var(--destructive) / 0.9);border-color:hsl(var(--destructive) / 0.9)}}}.dialog-input{width:100%;box-sizing:border-box;height:2rem;padding:0 8px;font:inherit;font-size:0.75rem;color:rgb(189, 219, 209);background-color:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:calc(var(--radius) - 2px);outline:none;&:focus{border-color:hsl(var(--primary))}&:disabled{opacity:0.65}}.dialog-error{margin-top:8px;font-size:0.7rem;line-height:0.95rem;color:#ff6b7a}.hint{margin-top:4px;font-size:0.66rem;line-height:0.9rem;color:hsl(var(--muted-foreground))}.checkline{margin-top:8px;display:flex;align-items:center;gap:6px;font-size:0.72rem;color:rgb(189, 219, 209);cursor:pointer;input{accent-color:hsl(var(--primary));margin:0}}.perm-grid{margin-top:10px;width:100%;border-collapse:collapse;font-size:0.68rem;th{color:hsl(var(--muted-foreground));font-weight:normal;text-align:center;padding:2px 0}th[scope='row']{text-align:left;color:rgb(189, 219, 209)}td{text-align:center;padding:2px 0}input{accent-color:hsl(var(--primary));margin:0}}.perm-special{margin-top:4px;display:flex;gap:12px;.checkline{margin-top:4px;font-size:0.66rem}}.perm-octal{margin-top:10px;display:flex;align-items:center;gap:8px;label{font-size:0.68rem;color:hsl(var(--muted-foreground))}.dialog-input{width:4.5rem;text-align:center;letter-spacing:0.1em}.perm-preview{font-size:0.7rem;color:hsl(var(--primary))}}.modal-actions .btn.primary{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground));&:hover:not(:disabled){background:hsl(var(--primary) / 0.9);border-color:hsl(var(--primary) / 0.9)}}.delete-loader{margin-top:4px;display:flex;justify-content:center;.spinner{width:16px;height:16px;border:2px solid hsl(var(--muted-foreground) / 0.35);border-top-color:hsl(var(--primary));border-radius:50%;animation:spin 0.7s linear infinite}}}}.editor-modal{position:absolute;inset:0;display:none;align-items:center;justify-content:center;background:rgba(28, 31, 38, 0);backdrop-filter:blur(4px);z-index:7;&.visible{display:flex}.editor-dialog{width:min(860px, calc(100% - 24px));height:min(620px, calc(100% - 24px));display:flex;flex-direction:column;background-color:rgba(21, 24, 30, 0.98);border:1px solid hsl(var(--border));border-radius:var(--radius);padding:16px;box-shadow:rgba(0, 0, 0, 0.5) 0px 25px 50px -12px;outline:none;.editor-head{display:flex;align-items:center;justify-content:space-between;gap:8px;.title{color:hsl(var(--primary));font-size:0.8rem;margin-bottom:8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.editor-close{border:none;background:transparent;color:hsl(var(--muted-foreground));font-size:0.85rem;line-height:1;padding:2px 6px;border-radius:4px;cursor:pointer;&:hover:not(:disabled){color:hsl(var(--primary));background-color:hsl(var(--border) / 0.6)}&:disabled{opacity:0.5;cursor:not-allowed}}}.editor-loading{flex:1;display:flex;align-items:center;justify-content:center;font-size:0.75rem;color:hsl(var(--muted-foreground))}.editor-text{flex:1;min-height:0;width:100%;box-sizing:border-box;resize:none;padding:10px;font:inherit;font-size:0.75rem;line-height:1.15rem;tab-size:4;white-space:pre;overflow:auto;color:rgb(189, 219, 209);background-color:hsl(var(--muted));border:1px solid hsl(var(--border));border-radius:calc(var(--radius) - 2px);outline:none;&:focus{border-color:hsl(var(--primary) / 0.6)}&:disabled{opacity:0.65}}.dialog-error{margin-top:8px;font-size:0.7rem;line-height:0.95rem;color:#ff6b7a}.modal-actions{margin-top:14px;display:flex;justify-content:flex-end;gap:8px;.btn{height:2rem;min-width:6rem;border:1px solid hsl(var(--border));border-radius:calc(var(--radius) - 2px);font-size:0.75rem;letter-spacing:0.03em;cursor:pointer;&:disabled{opacity:0.65;cursor:not-allowed}}.btn.secondary{background:hsl(var(--muted));color:rgb(189, 219, 209);&:hover:not(:disabled){border-color:hsl(var(--primary));color:hsl(var(--primary))}}.btn.destructive{background:hsl(var(--destructive));border-color:hsl(var(--destructive));color:white}.btn.primary{background:hsl(var(--primary));border-color:hsl(var(--primary));color:hsl(var(--primary-foreground));&:hover:not(:disabled){background:hsl(var(--primary) / 0.9);border-color:hsl(var(--primary) / 0.9)}}}}}}@keyframes spin{to{transform:rotate(360deg)}}:host(.max){height:100vh;width:100vw;position:fixed;top:0;left:0;z-index:9999}@container (max-width: 699px){:host .listing main .content table thead th:nth-child(4),:host .listing main .content table tbody td:nth-child(4){display:none}}@container (max-width: 635px){:host .listing main .content table thead th:nth-child(3),:host .listing main .content table tbody td:nth-child(3){display:none}}@container (max-width: 530px){:host .listing main .content table thead th:nth-child(5),:host .listing main .content table tbody td:nth-child(5){display:none}:host .listing footer .status{display:none}}@container (max-width: 370px){:host .listing main .content table thead th:nth-child(2),:host .listing main .content table tbody td:nth-child(2){display:none}:host .listing main .content table thead th:first-child,:host .listing main .content table tbody td:first-child{width:100%;min-width:0;max-width:none}:host .listing main .content table tbody td:first-child .name{max-width:100%}}@container (max-width: 295px){:host .listing main .content table tbody td:first-child .name{max-width:120px}}@container (max-width: 635px){:host .listing main .content table tbody tr td.action-col .file-action{opacity:1;visibility:visible;pointer-events:auto;width:36px;height:36px;border-radius:8px}:host .listing main .content table tbody tr td.action-col .file-action svg{width:17px;height:17px}:host .listing main .content table thead th.action-col,:host .listing main .content table tbody td.action-col{width:92px;min-width:92px}:host .listing main .content table tbody td.action-col .file-actions{gap:4px}:host .listing main .content table tbody tr:hover{background-color:transparent}:host .listing main .content table tbody tr.selected:hover{background-color:hsl(var(--primary) / 0.3)}:host .listing main .content table tbody td{padding:13px 10px 12px}:host .listing main .content table thead th{padding:12px 10px}:host .listing main .navigation{height:auto;min-height:44px;padding:6px 8px}:host .listing main .navigation .action{padding:10px;border-radius:8px}:host .listing main .navigation .action img{height:17px;width:17px}:host .listing main .navigation .action.disconnect{padding:10px 12px}:host .listing main .navigation .filter{height:2.25rem;font-size:16px;width:8rem}:host .listing header .actions .action{padding:8px}:host .listing header .actions .action img{height:17px}:host .modal .upload-dialog .cancel,:host .modal .download-dialog .cancel,:host .modal .delete-dialog .cancel,:host .modal .prompt-dialog .cancel,:host .modal .upload-dialog .modal-actions .btn,:host .modal .download-dialog .modal-actions .btn,:host .modal .delete-dialog .modal-actions .btn,:host .modal .prompt-dialog .modal-actions .btn{height:2.75rem}:host .modal .prompt-dialog .dialog-input,:host .auth input{height:2.5rem;font-size:16px}:host .modal .prompt-dialog .perm-grid input,:host .modal .prompt-dialog .perm-special input{width:20px;height:20px}:host .modal .prompt-dialog .perm-grid td,:host .modal .prompt-dialog .perm-grid th{padding:7px 0}}:host .listing main .navigation .action.fetch{position:relative;display:inline-grid;place-items:center;color:hsl(var(--primary))}:host .listing main .navigation .action.fetch .badge{position:absolute;top:-5px;right:-6px;min-width:15px;height:15px;padding:0 4px;border-radius:8px;background:hsl(var(--primary));color:hsl(var(--primary-foreground));font-size:9px;font-weight:700;line-height:15px;text-align:center}:host .listing main .content table tbody tr.part td{color:hsl(var(--muted-foreground));font-style:italic}:host .listing main .content table tbody tr.fresh{background-color:hsl(var(--primary) / 0.1)}:host .listing main .content table tbody tr.fresh .name::after{content:'new';margin-left:8px;font-size:10px;padding:1px 6px;border-radius:3px;background:hsl(var(--primary));color:hsl(var(--primary-foreground));font-weight:600;font-style:normal}:host .delete-dialog .file-name.inline{display:inline;padding:0;border:0;background:none}:host .context-backdrop{position:absolute;inset:0;z-index:8}:host .context-menu{position:absolute;min-width:220px;max-width:calc(100% - 16px);padding:4px;background:hsl(var(--card));border:1px solid hsl(var(--border));border-radius:6px;box-shadow:0 12px 30px -10px rgba(0, 0, 0, 0.7);display:flex;flex-direction:column;font-size:12px;button{display:flex;align-items:center;gap:8px;text-align:left;padding:6px 10px;border:0;border-radius:4px;background:transparent;color:rgb(189, 219, 209);font:inherit;cursor:pointer;&:hover,&:focus-visible{background:hsl(var(--muted));outline:none}&.primary{color:hsl(var(--primary))}&.danger{color:hsl(var(--destructive))}}hr{border:0;border-top:1px solid hsl(var(--border));margin:4px 0}}:host .player-modal{position:absolute;inset:0;z-index:7;display:grid;place-items:center;padding:10px;background:rgba(5, 7, 9, 0.6);phirepass-media-player{width:min(100%, 880px)}}`;
|
|
2223
|
-
|
|
2224
|
-
const PhirepassSftpClient = class {
|
|
2225
|
-
constructor(hostRef) {
|
|
2226
|
-
if (new.target === PhirepassSftpClient)
|
|
2227
|
-
index.registerInstance(this, hostRef);
|
|
2228
|
-
this.maximizeEvent = index.createEvent(this, "maximize");
|
|
2229
|
-
this.connectionStateChanged = index.createEvent(this, "connectionStateChanged");
|
|
2230
|
-
}
|
|
2231
|
-
get el_host() { return index.getElement(this); }
|
|
2232
|
-
channel;
|
|
2233
|
-
domReady = false;
|
|
2234
|
-
runtimeReady = false;
|
|
2235
|
-
connected = false;
|
|
2236
|
-
uploadInputEl;
|
|
2237
|
-
msgId = 1;
|
|
2238
|
-
activeUploadToken = 0;
|
|
2239
|
-
pendingUploadStarts = new Map();
|
|
2240
|
-
pendingUploadAcks = new Map();
|
|
2241
|
-
pendingDownloadStarts = new Map();
|
|
2242
|
-
activeDownloads = new Map();
|
|
2243
|
-
activeDownloadMsgId;
|
|
2244
|
-
pendingOps = new Map();
|
|
2245
|
-
promptInputEl;
|
|
2246
|
-
editorPath = '';
|
|
2247
|
-
editorTextEl;
|
|
2248
|
-
// private inputMode: InputMode = InputMode.Default;
|
|
2249
|
-
session_id;
|
|
2250
|
-
// private usernameBuffer = "";
|
|
2251
|
-
// private passwordBuffer = "";
|
|
2252
|
-
name = 'SFTP';
|
|
2253
|
-
description = 'Client';
|
|
2254
|
-
hideHeader = false;
|
|
2255
|
-
serverHost = "phirepass.com";
|
|
2256
|
-
serverPort = 443;
|
|
2257
|
-
allowInsecure = false;
|
|
2258
|
-
heartbeatInterval = 30_000;
|
|
2259
|
-
nodeId;
|
|
2260
|
-
serviceId;
|
|
2261
|
-
token;
|
|
2262
|
-
onNodeIdChange(newValue, _oldValue) {
|
|
2263
|
-
// Handle the change in node_id here
|
|
2264
|
-
// console.log(`node_id changed from ${oldValue} to ${newValue}`);
|
|
2265
|
-
// Always clear local session state and reset terminal view
|
|
2266
|
-
this.reset_session_state();
|
|
2267
|
-
// this.terminal.reset();
|
|
2268
|
-
// Close existing comms if connected
|
|
2269
|
-
if (this.channel && this.channel.is_connected()) {
|
|
2270
|
-
this.close_comms();
|
|
2271
|
-
}
|
|
2272
|
-
// Open new comms for the updated node
|
|
2273
|
-
if (newValue) {
|
|
2274
|
-
this.open_comms();
|
|
2275
|
-
this.channel.connect();
|
|
2276
|
-
this.status = 'Connecting...';
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
serverId;
|
|
2280
|
-
/**
|
|
2281
|
-
* Supplies the channel instead of a WebSocket to the server — for demos,
|
|
2282
|
-
* screenshots and tests. A property only (a function cannot be an
|
|
2283
|
-
* attribute); read once, when the widget connects. See `ChannelFactory`.
|
|
2284
|
-
*/
|
|
2285
|
-
channelFactory;
|
|
2286
|
-
onServerIdChange(_newValue, _oldValue) {
|
|
2287
|
-
this.onNodeIdChange(this.nodeId, this.nodeId);
|
|
2288
|
-
}
|
|
2289
|
-
maximizeEvent;
|
|
2290
|
-
async maximize() {
|
|
2291
|
-
this.max = !this.max;
|
|
2292
|
-
}
|
|
2293
|
-
async minimize() {
|
|
2294
|
-
this.max = false;
|
|
2295
|
-
}
|
|
2296
|
-
connectionStateChanged;
|
|
2297
|
-
max = false;
|
|
2298
|
-
show_login_screen = false;
|
|
2299
|
-
show_login_screen_username = false;
|
|
2300
|
-
show_error = false;
|
|
2301
|
-
error_message = '';
|
|
2302
|
-
show_login_screen_password = false;
|
|
2303
|
-
show_navigation = false;
|
|
2304
|
-
breadcrumbs = [];
|
|
2305
|
-
current_dir = '.';
|
|
2306
|
-
listing = [];
|
|
2307
|
-
show_content = false;
|
|
2308
|
-
show_loader = false;
|
|
2309
|
-
version = '';
|
|
2310
|
-
status = 'Disconnected';
|
|
2311
|
-
selected_item = null;
|
|
2312
|
-
show_upload_modal = false;
|
|
2313
|
-
upload_progress = 0;
|
|
2314
|
-
upload_file_name = '';
|
|
2315
|
-
upload_speed = '--';
|
|
2316
|
-
upload_finished = false;
|
|
2317
|
-
show_download_modal = false;
|
|
2318
|
-
download_progress = 0;
|
|
2319
|
-
download_file_name = '';
|
|
2320
|
-
download_speed = '--';
|
|
2321
|
-
download_finished = false;
|
|
2322
|
-
show_delete_modal = false;
|
|
2323
|
-
delete_file_name = '';
|
|
2324
|
-
delete_loading = false;
|
|
2325
|
-
delete_is_dir = false;
|
|
2326
|
-
delete_recursive = false;
|
|
2327
|
-
delete_error = '';
|
|
2328
|
-
/** `mkdir` and `rename` share one dialog: both take a single name. */
|
|
2329
|
-
prompt_kind = null;
|
|
2330
|
-
prompt_value = '';
|
|
2331
|
-
prompt_error = '';
|
|
2332
|
-
prompt_busy = false;
|
|
2333
|
-
chmod_target = null;
|
|
2334
|
-
/** Permission bits under edit, masked to 0o7777. */
|
|
2335
|
-
chmod_mode = 0;
|
|
2336
|
-
chmod_error = '';
|
|
2337
|
-
chmod_busy = false;
|
|
2338
|
-
show_editor = false;
|
|
2339
|
-
editor_name = '';
|
|
2340
|
-
editor_text = '';
|
|
2341
|
-
/** What is on the remote, so the dialog knows whether it has edits. */
|
|
2342
|
-
editor_saved_text = '';
|
|
2343
|
-
editor_busy = '';
|
|
2344
|
-
editor_error = '';
|
|
2345
|
-
editor_confirm_discard = false;
|
|
2346
|
-
/** False until the file's contents are in hand, so a failed open is read-only. */
|
|
2347
|
-
editor_loaded = false;
|
|
2348
|
-
filter = '';
|
|
2349
|
-
sort_key = 'name';
|
|
2350
|
-
sort_asc = true;
|
|
2351
|
-
// ---- Remote Fetch (hosted <phirepass-downloader>) ----
|
|
2352
|
-
/** True once the channel is authenticated: the downloader shares it from then on. */
|
|
2353
|
-
channel_ready = false;
|
|
2354
|
-
/** Running downloads, for the Fetch button's badge. */
|
|
2355
|
-
fetch_count = 0;
|
|
2356
|
-
/** Files a download just finished into the open folder, highlighted as new. */
|
|
2357
|
-
fresh_names = [];
|
|
2358
|
-
/** K3: a part file whose download a delete would end. */
|
|
2359
|
-
part_delete = null;
|
|
2360
|
-
torrent_menu = null;
|
|
2361
|
-
/** A listing file open in the player (not a download). */
|
|
2362
|
-
listing_player = null;
|
|
2363
|
-
downloaderEl;
|
|
2364
|
-
fetch_enabled() {
|
|
2365
|
-
return supportsDownloads(this.channel);
|
|
2366
|
-
}
|
|
2367
|
-
stream_base() {
|
|
2368
|
-
const protocol = this.allowInsecure ? 'http' : 'https';
|
|
2369
|
-
const standard = (!this.allowInsecure && this.serverPort === 443) || (this.allowInsecure && this.serverPort === 80);
|
|
2370
|
-
return `${protocol}://${this.serverHost}${standard ? '' : `:${this.serverPort}`}`;
|
|
2371
|
-
}
|
|
2372
|
-
on_fetch_completed(detail) {
|
|
2373
|
-
if (!sameFolder(folderOfCompleted(detail), this.current_dir)) {
|
|
2374
|
-
return;
|
|
2375
|
-
}
|
|
2376
|
-
this.fresh_names = [...this.fresh_names.filter((n) => n !== detail.name), detail.name];
|
|
2377
|
-
this.refresh_directory();
|
|
2378
|
-
}
|
|
2379
|
-
on_show_in_folder(detail) {
|
|
2380
|
-
this.fresh_names = [detail.name];
|
|
2381
|
-
if (!sameFolder(detail.path, this.current_dir)) {
|
|
2382
|
-
this.list_breadcrumb(detail.path);
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
|
-
async on_row_context_menu(item, event) {
|
|
2386
|
-
if (item.kind !== 'File' || !/\.torrent$/i.test(item.name) || !this.downloaderEl) {
|
|
2387
|
-
return;
|
|
2388
|
-
}
|
|
2389
|
-
const path = this.item_path(item);
|
|
2390
|
-
event.preventDefault();
|
|
2391
|
-
const rel = await this.downloaderEl.torrentPathFor(path);
|
|
2392
|
-
if (rel === null) {
|
|
2393
|
-
return;
|
|
2394
|
-
}
|
|
2395
|
-
const box = this.el_host.getBoundingClientRect();
|
|
2396
|
-
this.selected_item = item;
|
|
2397
|
-
this.torrent_menu = { x: event.clientX - box.left, y: event.clientY - box.top, path, name: item.name };
|
|
2398
|
-
}
|
|
2399
|
-
async play_listing_file(item, event) {
|
|
2400
|
-
event.preventDefault();
|
|
2401
|
-
event.stopPropagation();
|
|
2402
|
-
const channel = this.channel;
|
|
2403
|
-
if (typeof channel.send_sftp_open_stream !== 'function') {
|
|
2404
|
-
return;
|
|
2405
|
-
}
|
|
2406
|
-
const path = this.item_path(item);
|
|
2407
|
-
try {
|
|
2408
|
-
const answer = (await this.run_op('play', (msgId) => channel.send_sftp_open_stream(this.nodeId, this.session_id, path, msgId)));
|
|
2409
|
-
if (answer.result !== 'Stream' || !answer.token) {
|
|
2410
|
-
throw new Error('The node did not open a stream.');
|
|
2411
|
-
}
|
|
2412
|
-
this.listing_player = {
|
|
2413
|
-
src: `${this.stream_base()}/api/web/stream/${encodeURIComponent(this.nodeId)}/t/${encodeURIComponent(answer.token)}`,
|
|
2414
|
-
name: item.name,
|
|
2415
|
-
key: `node:${this.nodeId}:${path}`,
|
|
2416
|
-
};
|
|
2417
|
-
}
|
|
2418
|
-
catch (err) {
|
|
2419
|
-
this.error_message = this.error_text(err);
|
|
2420
|
-
this.show_error = true;
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
listing_can_play() {
|
|
2424
|
-
return typeof this.channel?.send_sftp_open_stream === 'function';
|
|
2425
|
-
}
|
|
2426
|
-
toggle_max() {
|
|
2427
|
-
this.maximizeEvent?.emit(!this.max);
|
|
2428
|
-
}
|
|
2429
|
-
async connectedCallback() {
|
|
2430
|
-
if (!this.channelFactory) {
|
|
2431
|
-
await protocol.__wbg_init();
|
|
2432
|
-
}
|
|
2433
|
-
// this.setup_terminal();
|
|
2434
|
-
this.open_comms();
|
|
2435
|
-
this.runtimeReady = true;
|
|
2436
|
-
if (!this.nodeId) {
|
|
2437
|
-
console.warn('Prop node_id is not set. Cannot connect to terminal.');
|
|
2438
|
-
return;
|
|
2439
|
-
}
|
|
2440
|
-
this.try_connect();
|
|
2441
|
-
}
|
|
2442
|
-
componentDidLoad() {
|
|
2443
|
-
this.domReady = true;
|
|
2444
|
-
this.try_connect();
|
|
2445
|
-
}
|
|
2446
|
-
async disconnectedCallback() {
|
|
2447
|
-
// if (this.resizeDebounceHandle) {
|
|
2448
|
-
// clearTimeout(this.resizeDebounceHandle);
|
|
2449
|
-
// this.resizeDebounceHandle = undefined;
|
|
2450
|
-
// }
|
|
2451
|
-
//
|
|
2452
|
-
// if (this.resizeObserver) {
|
|
2453
|
-
// this.resizeObserver.disconnect();
|
|
2454
|
-
// }
|
|
2455
|
-
this.connected = false;
|
|
2456
|
-
this.domReady = false;
|
|
2457
|
-
this.runtimeReady = false;
|
|
2458
|
-
this.cancel_active_upload();
|
|
2459
|
-
this.cancel_active_download();
|
|
2460
|
-
this.clear_pending_operations();
|
|
2461
|
-
this.close_comms();
|
|
2462
|
-
// this.destroy_terminal();
|
|
2463
|
-
}
|
|
2464
|
-
next_msg_id() {
|
|
2465
|
-
const id = this.msgId;
|
|
2466
|
-
this.msgId += 1;
|
|
2467
|
-
return id;
|
|
2468
|
-
}
|
|
2469
|
-
clear_pending_operations() {
|
|
2470
|
-
this.pendingUploadStarts.forEach((pending) => {
|
|
2471
|
-
window.clearTimeout(pending.timeout);
|
|
2472
|
-
pending.reject(new Error('Upload start aborted'));
|
|
2473
|
-
});
|
|
2474
|
-
this.pendingUploadStarts.clear();
|
|
2475
|
-
this.pendingUploadAcks.forEach((pending) => {
|
|
2476
|
-
window.clearTimeout(pending.timeout);
|
|
2477
|
-
pending.reject(new Error('Upload chunk aborted'));
|
|
2478
|
-
});
|
|
2479
|
-
this.pendingUploadAcks.clear();
|
|
2480
|
-
this.pendingDownloadStarts.forEach((pending) => {
|
|
2481
|
-
window.clearTimeout(pending.timeout);
|
|
2482
|
-
pending.reject(new Error('Download start aborted'));
|
|
2483
|
-
});
|
|
2484
|
-
this.pendingDownloadStarts.clear();
|
|
2485
|
-
this.pendingOps.forEach((pending) => {
|
|
2486
|
-
window.clearTimeout(pending.timeout);
|
|
2487
|
-
pending.reject(new Error(`Could not ${pending.verb}: the session ended.`));
|
|
2488
|
-
});
|
|
2489
|
-
this.pendingOps.clear();
|
|
2490
|
-
this.activeDownloads.clear();
|
|
2491
|
-
}
|
|
2492
|
-
cancel_active_upload() {
|
|
2493
|
-
this.activeUploadToken += 1;
|
|
2494
|
-
this.upload_progress = 0;
|
|
2495
|
-
this.upload_finished = false;
|
|
2496
|
-
this.upload_speed = '--';
|
|
2497
|
-
}
|
|
2498
|
-
cancel_active_download() {
|
|
2499
|
-
if (this.activeDownloadMsgId !== undefined) {
|
|
2500
|
-
this.activeDownloads.delete(this.activeDownloadMsgId);
|
|
2501
|
-
}
|
|
2502
|
-
this.activeDownloadMsgId = undefined;
|
|
2503
|
-
this.download_progress = 0;
|
|
2504
|
-
this.download_finished = false;
|
|
2505
|
-
this.download_speed = '--';
|
|
2506
|
-
}
|
|
2507
|
-
format_duration(seconds) {
|
|
2508
|
-
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
2509
|
-
return '--';
|
|
2510
|
-
}
|
|
2511
|
-
if (seconds < 60) {
|
|
2512
|
-
return `${seconds.toFixed(0)}s`;
|
|
2513
|
-
}
|
|
2514
|
-
const minutes = Math.floor(seconds / 60);
|
|
2515
|
-
const remainderSeconds = Math.floor(seconds % 60);
|
|
2516
|
-
if (minutes < 60) {
|
|
2517
|
-
return `${minutes}m ${remainderSeconds}s`;
|
|
2518
|
-
}
|
|
2519
|
-
const hours = Math.floor(minutes / 60);
|
|
2520
|
-
const remainderMinutes = minutes % 60;
|
|
2521
|
-
return `${hours}h ${remainderMinutes}m`;
|
|
2522
|
-
}
|
|
2523
|
-
format_percent(value) {
|
|
2524
|
-
const safe = Number.isFinite(value) ? value : 0;
|
|
2525
|
-
return `${safe.toFixed(2)}%`;
|
|
2526
|
-
}
|
|
2527
|
-
format_transfer_rate(bytesPerSecond) {
|
|
2528
|
-
if (!Number.isFinite(bytesPerSecond) || bytesPerSecond <= 0) {
|
|
2529
|
-
return '--';
|
|
2530
|
-
}
|
|
2531
|
-
return `${this.format_size(bytesPerSecond)}/s`;
|
|
2532
|
-
}
|
|
2533
|
-
update_upload_progress(uploadedBytes, totalBytes, startTime) {
|
|
2534
|
-
const progress = totalBytes > 0 ? (uploadedBytes / totalBytes) * 100 : 0;
|
|
2535
|
-
this.upload_progress = Math.max(0, Math.min(100, progress));
|
|
2536
|
-
if (uploadedBytes >= totalBytes) {
|
|
2537
|
-
this.upload_finished = true;
|
|
2538
|
-
this.upload_speed = '--';
|
|
2539
|
-
return;
|
|
2540
|
-
}
|
|
2541
|
-
const elapsedSeconds = (performance.now() - startTime) / 1000;
|
|
2542
|
-
const speed = elapsedSeconds > 0 ? uploadedBytes / elapsedSeconds : 0;
|
|
2543
|
-
this.upload_speed = this.format_transfer_rate(speed);
|
|
2544
|
-
const remaining = totalBytes - uploadedBytes;
|
|
2545
|
-
const eta = speed > 0 ? remaining / speed : NaN;
|
|
2546
|
-
this.status = `Uploading ${this.format_size(uploadedBytes)} / ${this.format_size(totalBytes)} (ETA ${this.format_duration(eta)})`;
|
|
2547
|
-
}
|
|
2548
|
-
update_download_progress(receivedBytes, totalBytes, startTime) {
|
|
2549
|
-
const progress = totalBytes > 0 ? (receivedBytes / totalBytes) * 100 : 0;
|
|
2550
|
-
this.download_progress = Math.max(0, Math.min(100, progress));
|
|
2551
|
-
if (receivedBytes >= totalBytes) {
|
|
2552
|
-
this.download_finished = true;
|
|
2553
|
-
this.download_speed = '--';
|
|
2554
|
-
return;
|
|
2555
|
-
}
|
|
2556
|
-
const elapsedSeconds = (Date.now() - startTime) / 1000;
|
|
2557
|
-
const speed = elapsedSeconds > 0 ? receivedBytes / elapsedSeconds : 0;
|
|
2558
|
-
this.download_speed = this.format_transfer_rate(speed);
|
|
2559
|
-
const remaining = totalBytes - receivedBytes;
|
|
2560
|
-
const eta = speed > 0 ? remaining / speed : NaN;
|
|
2561
|
-
this.status = `Downloading ${this.format_size(receivedBytes)} / ${this.format_size(totalBytes)} (ETA ${this.format_duration(eta)})`;
|
|
2562
|
-
}
|
|
2563
|
-
connect() {
|
|
2564
|
-
this.connected = true;
|
|
2565
|
-
this.channel.connect();
|
|
2566
|
-
this.status = 'Connecting...';
|
|
2567
|
-
// const container = this.containerEl;
|
|
2568
|
-
// console.log('Attempting to connect terminal to container:', container);
|
|
2569
|
-
// if (container) {
|
|
2570
|
-
// this.terminal.open(container);
|
|
2571
|
-
// console.log('Terminal opened in container');
|
|
2572
|
-
// this.connected = true;
|
|
2573
|
-
// this.fit_terminal_safely();
|
|
2574
|
-
// this.terminal.focus();
|
|
2575
|
-
// this.terminal.onData(this.handle_terminal_data.bind(this));
|
|
2576
|
-
// this.channel.connect();
|
|
2577
|
-
// this.setup_resize_observer();
|
|
2578
|
-
// console.log('Terminal connected and ready');
|
|
2579
|
-
// }
|
|
2580
|
-
}
|
|
2581
|
-
try_connect() {
|
|
2582
|
-
if (this.connected || !this.domReady || !this.runtimeReady) {
|
|
2583
|
-
return;
|
|
2584
|
-
}
|
|
2585
|
-
if (!this.channel) {
|
|
2586
|
-
return;
|
|
2587
|
-
}
|
|
2588
|
-
this.connect();
|
|
2589
|
-
}
|
|
2590
|
-
create_web_socket_endpoint() {
|
|
2591
|
-
const protocol = this.allowInsecure ? 'ws' : 'wss';
|
|
2592
|
-
if (!this.allowInsecure && this.serverPort === 443) {
|
|
2593
|
-
return `${protocol}://${this.serverHost}`;
|
|
2594
|
-
}
|
|
2595
|
-
if (this.allowInsecure && this.serverPort === 80) {
|
|
2596
|
-
return `${protocol}://${this.serverHost}`;
|
|
2597
|
-
}
|
|
2598
|
-
return `${protocol}://${this.serverHost}:${this.serverPort}`;
|
|
2599
|
-
}
|
|
2600
|
-
handle_error(error) {
|
|
2601
|
-
if (error.msg_id !== undefined) {
|
|
2602
|
-
const pendingUploadStart = this.pendingUploadStarts.get(error.msg_id);
|
|
2603
|
-
if (pendingUploadStart) {
|
|
2604
|
-
window.clearTimeout(pendingUploadStart.timeout);
|
|
2605
|
-
pendingUploadStart.reject(new Error(error.message || 'Upload start failed'));
|
|
2606
|
-
this.pendingUploadStarts.delete(error.msg_id);
|
|
2607
|
-
}
|
|
2608
|
-
const pendingDownloadStart = this.pendingDownloadStarts.get(error.msg_id);
|
|
2609
|
-
if (pendingDownloadStart) {
|
|
2610
|
-
window.clearTimeout(pendingDownloadStart.timeout);
|
|
2611
|
-
pendingDownloadStart.reject(new Error(error.message || 'Download start failed'));
|
|
2612
|
-
this.pendingDownloadStarts.delete(error.msg_id);
|
|
2613
|
-
}
|
|
2614
|
-
if (this.activeDownloads.has(error.msg_id)) {
|
|
2615
|
-
this.activeDownloads.delete(error.msg_id);
|
|
2616
|
-
if (this.activeDownloadMsgId === error.msg_id) {
|
|
2617
|
-
this.activeDownloadMsgId = undefined;
|
|
2618
|
-
}
|
|
2619
|
-
this.download_finished = false;
|
|
2620
|
-
}
|
|
2621
|
-
const pendingOp = this.pendingOps.get(error.msg_id);
|
|
2622
|
-
if (pendingOp) {
|
|
2623
|
-
window.clearTimeout(pendingOp.timeout);
|
|
2624
|
-
this.pendingOps.delete(error.msg_id);
|
|
2625
|
-
pendingOp.reject(new Error(error.message || `Could not ${pendingOp.verb}.`));
|
|
2626
|
-
// The caller puts this message in the dialog the user is
|
|
2627
|
-
// looking at. Raising the page-level banner as well would say
|
|
2628
|
-
// the same thing twice, in the place they are not looking.
|
|
2629
|
-
this.show_loader = false;
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
switch (error.kind) {
|
|
2634
|
-
case protocol.ErrorType.Generic:
|
|
2635
|
-
case protocol.ErrorType.Authentication:
|
|
2636
|
-
this.error_message = error.message || 'An unknown error occurred.';
|
|
2637
|
-
this.show_error = true;
|
|
2638
|
-
break;
|
|
2639
|
-
case protocol.ErrorType.RequiresUsername:
|
|
2640
|
-
this.show_login_screen_username = true;
|
|
2641
|
-
this.show_login_screen_password = false;
|
|
2642
|
-
this.show_login_screen = true;
|
|
2643
|
-
break;
|
|
2644
|
-
case protocol.ErrorType.RequiresPassword:
|
|
2645
|
-
this.show_login_screen_username = false;
|
|
2646
|
-
this.show_login_screen_password = true;
|
|
2647
|
-
this.show_login_screen = true;
|
|
2648
|
-
break;
|
|
2649
|
-
case protocol.ErrorType.RequiresUsernamePassword:
|
|
2650
|
-
this.show_login_screen_username = true;
|
|
2651
|
-
this.show_login_screen_password = true;
|
|
2652
|
-
this.show_login_screen = true;
|
|
2653
|
-
break;
|
|
2654
|
-
}
|
|
2655
|
-
setTimeout(() => {
|
|
2656
|
-
this.show_loader = false;
|
|
2657
|
-
}, 1_000);
|
|
2658
|
-
}
|
|
2659
|
-
handle_auth_success(auth) {
|
|
2660
|
-
this.clear_creds_buffer();
|
|
2661
|
-
this.version = auth.version;
|
|
2662
|
-
this.channel.start_heartbeat(this.heartbeatInterval <= 15_000 ? 30_000 : this.heartbeatInterval);
|
|
2663
|
-
this.channel.open_sftp_tunnel(this.nodeId, this.serviceId);
|
|
2664
|
-
this.status = 'Connected';
|
|
2665
|
-
this.channel_ready = true;
|
|
2666
|
-
}
|
|
2667
|
-
handle_tunnel_opened(web) {
|
|
2668
|
-
this.session_id = web.sid;
|
|
2669
|
-
// this.terminal.reset();
|
|
2670
|
-
// this.fit_terminal_safely();
|
|
2671
|
-
// this.send_ssh_terminal_resize();
|
|
2672
|
-
this.channel.send_sftp_list_data(this.nodeId, this.session_id, this.current_dir);
|
|
2673
|
-
}
|
|
2674
|
-
handle_sftp_list_items(web) {
|
|
2675
|
-
setTimeout(() => {
|
|
2676
|
-
this.show_loader = false;
|
|
2677
|
-
}, 500);
|
|
2678
|
-
// A filter is about the directory you typed it in; carrying it into
|
|
2679
|
-
// the next one hides most of what you just navigated to.
|
|
2680
|
-
if (web.path !== this.current_dir) {
|
|
2681
|
-
this.filter = '';
|
|
2682
|
-
}
|
|
2683
|
-
if (web.path !== this.current_dir) {
|
|
2684
|
-
this.fresh_names = [];
|
|
2685
|
-
}
|
|
2686
|
-
this.listing = web.dir.items;
|
|
2687
|
-
this.current_dir = web.path;
|
|
2688
|
-
this.breadcrumbs = web.path.split('/').map((path, index, arr) => {
|
|
2689
|
-
if (path === '' && index === 0) {
|
|
2690
|
-
return { label: '/', path: '/' };
|
|
2691
|
-
}
|
|
2692
|
-
return { label: path, path: arr.slice(0, index + 1).join('/') };
|
|
2693
|
-
});
|
|
2694
|
-
this.show_content = true;
|
|
2695
|
-
this.show_navigation = true;
|
|
2696
|
-
console.log('Received SFTP list items:', web);
|
|
2697
|
-
}
|
|
2698
|
-
handle_upload_start_response(web) {
|
|
2699
|
-
if (web.msg_id === undefined) {
|
|
2700
|
-
return;
|
|
2701
|
-
}
|
|
2702
|
-
const pending = this.pendingUploadStarts.get(web.msg_id);
|
|
2703
|
-
if (!pending) {
|
|
2704
|
-
return;
|
|
2705
|
-
}
|
|
2706
|
-
window.clearTimeout(pending.timeout);
|
|
2707
|
-
pending.resolve(web.response.upload_id);
|
|
2708
|
-
this.pendingUploadStarts.delete(web.msg_id);
|
|
2709
|
-
}
|
|
2710
|
-
handle_upload_chunk_ack(web) {
|
|
2711
|
-
const key = `${web.upload_id}_${web.chunk_index}`;
|
|
2712
|
-
const pending = this.pendingUploadAcks.get(key);
|
|
2713
|
-
if (!pending) {
|
|
2714
|
-
return;
|
|
2715
|
-
}
|
|
2716
|
-
window.clearTimeout(pending.timeout);
|
|
2717
|
-
pending.resolve();
|
|
2718
|
-
this.pendingUploadAcks.delete(key);
|
|
2719
|
-
}
|
|
2720
|
-
handle_download_start_response(web) {
|
|
2721
|
-
if (web.msg_id === undefined) {
|
|
2722
|
-
return;
|
|
2723
|
-
}
|
|
2724
|
-
const pending = this.pendingDownloadStarts.get(web.msg_id);
|
|
2725
|
-
if (!pending) {
|
|
2726
|
-
return;
|
|
2727
|
-
}
|
|
2728
|
-
window.clearTimeout(pending.timeout);
|
|
2729
|
-
pending.resolve({
|
|
2730
|
-
download_id: web.response.download_id,
|
|
2731
|
-
total_size: web.response.total_size,
|
|
2732
|
-
total_chunks: web.response.total_chunks,
|
|
2733
|
-
});
|
|
2734
|
-
this.pendingDownloadStarts.delete(web.msg_id);
|
|
2735
|
-
}
|
|
2736
|
-
finalize_download(msgId) {
|
|
2737
|
-
const download = this.activeDownloads.get(msgId);
|
|
2738
|
-
if (!download) {
|
|
2739
|
-
return;
|
|
2740
|
-
}
|
|
2741
|
-
const sortedChunks = Array.from(download.chunks.entries())
|
|
2742
|
-
.sort((a, b) => a[0] - b[0])
|
|
2743
|
-
.map(([, data]) => data);
|
|
2744
|
-
// Normalize to fresh ArrayBuffer-backed views for BlobPart compatibility.
|
|
2745
|
-
const blobParts = sortedChunks.map((chunk) => new Uint8Array(chunk));
|
|
2746
|
-
const blob = new Blob(blobParts, { type: 'application/octet-stream' });
|
|
2747
|
-
const objectUrl = URL.createObjectURL(blob);
|
|
2748
|
-
const anchor = document.createElement('a');
|
|
2749
|
-
anchor.href = objectUrl;
|
|
2750
|
-
anchor.download = download.filename;
|
|
2751
|
-
document.body.appendChild(anchor);
|
|
2752
|
-
anchor.click();
|
|
2753
|
-
document.body.removeChild(anchor);
|
|
2754
|
-
URL.revokeObjectURL(objectUrl);
|
|
2755
|
-
this.activeDownloads.delete(msgId);
|
|
2756
|
-
if (this.activeDownloadMsgId === msgId) {
|
|
2757
|
-
this.activeDownloadMsgId = undefined;
|
|
2758
|
-
}
|
|
2759
|
-
this.download_finished = true;
|
|
2760
|
-
this.status = 'Connected';
|
|
2761
|
-
}
|
|
2762
|
-
handle_download_chunk(web) {
|
|
2763
|
-
if (web.msg_id === undefined) {
|
|
2764
|
-
return;
|
|
2765
|
-
}
|
|
2766
|
-
const download = this.activeDownloads.get(web.msg_id);
|
|
2767
|
-
if (!download || !this.session_id) {
|
|
2768
|
-
return;
|
|
2769
|
-
}
|
|
2770
|
-
const chunkData = new Uint8Array(web.chunk.data);
|
|
2771
|
-
download.chunks.set(web.chunk.chunk_index, chunkData);
|
|
2772
|
-
const receivedBytes = Array.from(download.chunks.values()).reduce((sum, data) => sum + data.length, 0);
|
|
2773
|
-
this.update_download_progress(receivedBytes, download.total_size, download.startTime);
|
|
2774
|
-
// Pipeline ACK: advance the agent's sliding window so it can push the next
|
|
2775
|
-
// batch of chunks without waiting for an explicit per-chunk request.
|
|
2776
|
-
this.channel.send_sftp_download_ack(this.nodeId, this.session_id, download.download_id, web.chunk.chunk_index);
|
|
2777
|
-
if (download.chunks.size >= download.total_chunks) {
|
|
2778
|
-
this.finalize_download(web.msg_id);
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2781
|
-
async start_download(item) {
|
|
2782
|
-
if (!this.session_id) {
|
|
2783
|
-
return;
|
|
2784
|
-
}
|
|
2785
|
-
this.selected_item = item;
|
|
2786
|
-
this.download_file_name = item.name;
|
|
2787
|
-
this.download_progress = 0;
|
|
2788
|
-
this.download_finished = false;
|
|
2789
|
-
this.download_speed = '--';
|
|
2790
|
-
this.show_download_modal = true;
|
|
2791
|
-
this.show_error = false;
|
|
2792
|
-
const msgId = this.next_msg_id();
|
|
2793
|
-
this.activeDownloadMsgId = msgId;
|
|
2794
|
-
this.activeDownloads.set(msgId, {
|
|
2795
|
-
filename: item.name,
|
|
2796
|
-
chunks: new Map(),
|
|
2797
|
-
total_chunks: 0,
|
|
2798
|
-
total_size: 0,
|
|
2799
|
-
download_id: 0,
|
|
2800
|
-
startTime: Date.now(),
|
|
2801
|
-
});
|
|
2802
|
-
const downloadStart = new Promise((resolve, reject) => {
|
|
2803
|
-
const timeout = window.setTimeout(() => {
|
|
2804
|
-
this.pendingDownloadStarts.delete(msgId);
|
|
2805
|
-
reject(new Error('Download start timeout'));
|
|
2806
|
-
}, 10_000);
|
|
2807
|
-
this.pendingDownloadStarts.set(msgId, {
|
|
2808
|
-
timeout,
|
|
2809
|
-
resolve,
|
|
2810
|
-
reject,
|
|
2811
|
-
});
|
|
2812
|
-
});
|
|
2813
|
-
try {
|
|
2814
|
-
this.channel.send_sftp_download_start(this.nodeId, this.session_id, item.path, item.name, msgId);
|
|
2815
|
-
const { download_id, total_chunks, total_size } = await downloadStart;
|
|
2816
|
-
const download = this.activeDownloads.get(msgId);
|
|
2817
|
-
if (!download) {
|
|
2818
|
-
return;
|
|
2819
|
-
}
|
|
2820
|
-
download.download_id = download_id;
|
|
2821
|
-
download.total_chunks = total_chunks;
|
|
2822
|
-
download.total_size = total_size;
|
|
2823
|
-
// Pipelined: agent pushes chunks immediately after SFTPDownloadStartResponse;
|
|
2824
|
-
// no explicit per-chunk request is needed to start the flow.
|
|
2825
|
-
}
|
|
2826
|
-
catch (err) {
|
|
2827
|
-
this.activeDownloads.delete(msgId);
|
|
2828
|
-
if (this.activeDownloadMsgId === msgId) {
|
|
2829
|
-
this.activeDownloadMsgId = undefined;
|
|
2830
|
-
}
|
|
2831
|
-
this.show_error = true;
|
|
2832
|
-
this.error_message = err instanceof Error ? err.message : 'Failed to start download';
|
|
2833
|
-
this.cancel_download();
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
async upload_file(fileToUpload) {
|
|
2837
|
-
if (!this.session_id) {
|
|
2838
|
-
return;
|
|
2839
|
-
}
|
|
2840
|
-
const uploadToken = this.activeUploadToken + 1;
|
|
2841
|
-
this.activeUploadToken = uploadToken;
|
|
2842
|
-
this.upload_file_name = fileToUpload.name;
|
|
2843
|
-
this.upload_progress = 0;
|
|
2844
|
-
this.upload_finished = false;
|
|
2845
|
-
this.upload_speed = '--';
|
|
2846
|
-
this.show_upload_modal = true;
|
|
2847
|
-
this.show_error = false;
|
|
2848
|
-
this.status = 'Uploading...';
|
|
2849
|
-
const chunkSize = 64 * 1024;
|
|
2850
|
-
const totalChunks = Math.max(1, Math.ceil(fileToUpload.size / chunkSize));
|
|
2851
|
-
const msgId = this.next_msg_id();
|
|
2852
|
-
const uploadStart = new Promise((resolve, reject) => {
|
|
2853
|
-
const timeout = window.setTimeout(() => {
|
|
2854
|
-
this.pendingUploadStarts.delete(msgId);
|
|
2855
|
-
reject(new Error('Upload start timeout'));
|
|
2856
|
-
}, 10_000);
|
|
2857
|
-
this.pendingUploadStarts.set(msgId, {
|
|
2858
|
-
timeout,
|
|
2859
|
-
resolve,
|
|
2860
|
-
reject,
|
|
2861
|
-
});
|
|
2862
|
-
});
|
|
2863
|
-
try {
|
|
2864
|
-
this.channel.send_sftp_upload_start(this.nodeId, this.session_id, fileToUpload.name, this.current_dir, totalChunks, BigInt(fileToUpload.size), msgId);
|
|
2865
|
-
const uploadId = await uploadStart;
|
|
2866
|
-
let uploadedBytes = 0;
|
|
2867
|
-
const startedAt = performance.now();
|
|
2868
|
-
for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex += 1) {
|
|
2869
|
-
if (uploadToken !== this.activeUploadToken) {
|
|
2870
|
-
throw new Error('Upload cancelled');
|
|
2871
|
-
}
|
|
2872
|
-
const start = chunkIndex * chunkSize;
|
|
2873
|
-
const end = Math.min(start + chunkSize, fileToUpload.size);
|
|
2874
|
-
const chunkBuffer = new Uint8Array(await fileToUpload.slice(start, end).arrayBuffer());
|
|
2875
|
-
await new Promise((resolve, reject) => {
|
|
2876
|
-
const key = `${uploadId}_${chunkIndex}`;
|
|
2877
|
-
const timeout = window.setTimeout(() => {
|
|
2878
|
-
this.pendingUploadAcks.delete(key);
|
|
2879
|
-
reject(new Error(`Upload chunk ${chunkIndex + 1} timed out`));
|
|
2880
|
-
}, 30_000);
|
|
2881
|
-
this.pendingUploadAcks.set(key, {
|
|
2882
|
-
timeout,
|
|
2883
|
-
resolve,
|
|
2884
|
-
reject,
|
|
2885
|
-
});
|
|
2886
|
-
this.channel.send_sftp_upload_chunk(this.nodeId, this.session_id, uploadId, chunkIndex, chunkBuffer.length, chunkBuffer, null);
|
|
2887
|
-
});
|
|
2888
|
-
uploadedBytes += chunkBuffer.length;
|
|
2889
|
-
this.update_upload_progress(uploadedBytes, fileToUpload.size, startedAt);
|
|
2890
|
-
}
|
|
2891
|
-
this.upload_progress = 100;
|
|
2892
|
-
this.upload_finished = true;
|
|
2893
|
-
this.status = 'Connected';
|
|
2894
|
-
this.refresh_directory();
|
|
2895
|
-
}
|
|
2896
|
-
catch (err) {
|
|
2897
|
-
if (err.message !== 'Upload cancelled') {
|
|
2898
|
-
this.show_error = true;
|
|
2899
|
-
this.error_message = err instanceof Error ? err.message : 'Upload failed';
|
|
2900
|
-
}
|
|
2901
|
-
this.upload_finished = false;
|
|
2902
|
-
this.status = 'Connected';
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
handle_op_result(web) {
|
|
2906
|
-
if (web.msg_id === undefined) {
|
|
2907
|
-
return;
|
|
2908
|
-
}
|
|
2909
|
-
const pending = this.pendingOps.get(web.msg_id);
|
|
2910
|
-
if (!pending) {
|
|
2911
|
-
return;
|
|
2912
|
-
}
|
|
2913
|
-
window.clearTimeout(pending.timeout);
|
|
2914
|
-
this.pendingOps.delete(web.msg_id);
|
|
2915
|
-
pending.resolve(web.result);
|
|
2916
|
-
}
|
|
2917
|
-
/**
|
|
2918
|
-
* Send one filesystem operation and wait for its single answer.
|
|
2919
|
-
*
|
|
2920
|
-
* There are three outcomes: an `SFTPOpResult` resolves it, an `Error` frame
|
|
2921
|
-
* carrying the same `msg_id` rejects it, and the timeout covers the case
|
|
2922
|
-
* worth naming — an agent built before these frames existed logs the
|
|
2923
|
-
* unknown frame and drops it, so silence usually means "too old" rather
|
|
2924
|
-
* than "slow", and the message says so.
|
|
2925
|
-
*/
|
|
2926
|
-
run_op(verb, send, timeoutMs = 30_000) {
|
|
2927
|
-
if (!this.session_id) {
|
|
2928
|
-
return Promise.reject(new Error('No active SFTP session.'));
|
|
2929
|
-
}
|
|
2930
|
-
const msgId = this.next_msg_id();
|
|
2931
|
-
return new Promise((resolve, reject) => {
|
|
2932
|
-
const timeout = window.setTimeout(() => {
|
|
2933
|
-
this.pendingOps.delete(msgId);
|
|
2934
|
-
reject(new Error(`Timed out trying to ${verb}. This node's agent may be too old to support it.`));
|
|
2935
|
-
}, timeoutMs);
|
|
2936
|
-
this.pendingOps.set(msgId, { verb, timeout, resolve, reject });
|
|
2937
|
-
try {
|
|
2938
|
-
send(msgId);
|
|
2939
|
-
}
|
|
2940
|
-
catch (err) {
|
|
2941
|
-
window.clearTimeout(timeout);
|
|
2942
|
-
this.pendingOps.delete(msgId);
|
|
2943
|
-
reject(err instanceof Error ? err : new Error(String(err)));
|
|
2944
|
-
}
|
|
2945
|
-
});
|
|
2946
|
-
}
|
|
2947
|
-
error_text(err) {
|
|
2948
|
-
return err instanceof Error ? err.message : String(err);
|
|
2949
|
-
}
|
|
2950
|
-
/**
|
|
2951
|
-
* A listing entry carries its *parent* directory in `path`, so a full path
|
|
2952
|
-
* is always the join of the two.
|
|
2953
|
-
*/
|
|
2954
|
-
item_path(item) {
|
|
2955
|
-
return this.join_path(item.path, item.name);
|
|
2956
|
-
}
|
|
2957
|
-
join_path(dir, name) {
|
|
2958
|
-
if (!dir || dir === '/') {
|
|
2959
|
-
return `/${name}`;
|
|
2960
|
-
}
|
|
2961
|
-
return dir.endsWith('/') ? `${dir}${name}` : `${dir}/${name}`;
|
|
2962
|
-
}
|
|
2963
|
-
/** Names the remote would reject, or that would silently mean something else. */
|
|
2964
|
-
invalid_name(name) {
|
|
2965
|
-
if (!name) {
|
|
2966
|
-
return 'Enter a name.';
|
|
2967
|
-
}
|
|
2968
|
-
if (name === '.' || name === '..') {
|
|
2969
|
-
return 'That name is reserved.';
|
|
2970
|
-
}
|
|
2971
|
-
if (name.includes('/')) {
|
|
2972
|
-
return 'A name cannot contain "/".';
|
|
2973
|
-
}
|
|
2974
|
-
if (name.includes('\u0000')) {
|
|
2975
|
-
return 'A name cannot contain a null byte.';
|
|
2976
|
-
}
|
|
2977
|
-
return '';
|
|
2978
|
-
}
|
|
2979
|
-
handle_tunnel_data(web) {
|
|
2980
|
-
console.log('received tunnel data:', web);
|
|
2981
|
-
}
|
|
2982
|
-
handle_tunnel_closed(_web_) {
|
|
2983
|
-
// this.session_id = undefined;
|
|
2984
|
-
// this.inputMode = InputMode.Default;
|
|
2985
|
-
this.clear_creds_buffer();
|
|
2986
|
-
// this.terminal.reset();
|
|
2987
|
-
// this.terminal.writeln("Connection closed.");
|
|
2988
|
-
this.close_comms();
|
|
2989
|
-
}
|
|
2990
|
-
open_comms() {
|
|
2991
|
-
const endpoint = `${this.create_web_socket_endpoint()}/api/web/ws`;
|
|
2992
|
-
if (this.channelFactory) {
|
|
2993
|
-
this.channel = this.channelFactory(endpoint, this.nodeId, this.serverId || undefined);
|
|
2994
|
-
}
|
|
2995
|
-
else if (this.serverId) {
|
|
2996
|
-
this.channel = new protocol.Channel(endpoint, this.nodeId, this.serverId);
|
|
2997
|
-
}
|
|
2998
|
-
else {
|
|
2999
|
-
this.channel = new protocol.Channel(endpoint, this.nodeId);
|
|
3000
|
-
}
|
|
3001
|
-
this.channel.on_connection_open(() => {
|
|
3002
|
-
this.connectionStateChanged.emit([protocol.ConnectionState.Connected]);
|
|
3003
|
-
this.channel.authenticate(this.token, this.nodeId);
|
|
3004
|
-
this.status = 'Authenticating...';
|
|
3005
|
-
});
|
|
3006
|
-
this.channel.on_connection_close(() => {
|
|
3007
|
-
this.connectionStateChanged.emit([protocol.ConnectionState.Disconnected]);
|
|
3008
|
-
this.status = 'Disconnected';
|
|
3009
|
-
this.channel_ready = false;
|
|
3010
|
-
});
|
|
3011
|
-
this.channel.on_connection_error((err) => {
|
|
3012
|
-
this.connectionStateChanged.emit([protocol.ConnectionState.Error, err]);
|
|
3013
|
-
this.status = 'Error ' + err.message;
|
|
3014
|
-
});
|
|
3015
|
-
this.channel.on_connection_message((_raw_) => {
|
|
3016
|
-
//
|
|
3017
|
-
});
|
|
3018
|
-
this.channel.on_protocol_message((msg) => {
|
|
3019
|
-
const { web } = msg.data;
|
|
3020
|
-
// The downloader shares this channel: hand it what it asked for.
|
|
3021
|
-
if (isDownloadFrame(web) || (web.type === protocol.ProtocolMessageType.Error && (web.msg_id ?? 0) >= DOWNLOADER_MSG_ID_BASE)) {
|
|
3022
|
-
void this.downloaderEl?.receive(msg);
|
|
3023
|
-
return;
|
|
3024
|
-
}
|
|
3025
|
-
switch (web.type) {
|
|
3026
|
-
case protocol.ProtocolMessageType.Error:
|
|
3027
|
-
this.handle_error(web);
|
|
3028
|
-
break;
|
|
3029
|
-
case protocol.ProtocolMessageType.AuthSuccess:
|
|
3030
|
-
this.handle_auth_success(web);
|
|
3031
|
-
break;
|
|
3032
|
-
case protocol.ProtocolMessageType.TunnelOpened:
|
|
3033
|
-
this.handle_tunnel_opened(web);
|
|
3034
|
-
break;
|
|
3035
|
-
case protocol.ProtocolMessageType.TunnelClosed:
|
|
3036
|
-
this.handle_tunnel_closed(web);
|
|
3037
|
-
break;
|
|
3038
|
-
case protocol.ProtocolMessageType.TunnelData:
|
|
3039
|
-
this.handle_tunnel_data(web);
|
|
3040
|
-
break;
|
|
3041
|
-
case protocol.ProtocolMessageType.SFTPListItems:
|
|
3042
|
-
this.handle_sftp_list_items(web);
|
|
3043
|
-
break;
|
|
3044
|
-
case protocol.ProtocolMessageType.SFTPUploadStartResponse:
|
|
3045
|
-
this.handle_upload_start_response(web);
|
|
3046
|
-
break;
|
|
3047
|
-
case protocol.ProtocolMessageType.SFTPUploadChunkAck:
|
|
3048
|
-
this.handle_upload_chunk_ack(web);
|
|
3049
|
-
break;
|
|
3050
|
-
case protocol.ProtocolMessageType.SFTPDownloadStartResponse:
|
|
3051
|
-
this.handle_download_start_response(web);
|
|
3052
|
-
break;
|
|
3053
|
-
case protocol.ProtocolMessageType.SFTPDownloadChunk:
|
|
3054
|
-
this.handle_download_chunk(web);
|
|
3055
|
-
break;
|
|
3056
|
-
case protocol.ProtocolMessageType.SFTPOpResult:
|
|
3057
|
-
this.handle_op_result(web);
|
|
3058
|
-
break;
|
|
3059
|
-
default:
|
|
3060
|
-
console.warn('Unhandled protocol message type:', web);
|
|
3061
|
-
}
|
|
3062
|
-
});
|
|
3063
|
-
}
|
|
3064
|
-
close_comms() {
|
|
3065
|
-
this.cancel_active_upload();
|
|
3066
|
-
this.cancel_active_download();
|
|
3067
|
-
this.clear_pending_operations();
|
|
3068
|
-
if (!this.channel) {
|
|
3069
|
-
return;
|
|
3070
|
-
}
|
|
3071
|
-
this.channel.stop_heartbeat();
|
|
3072
|
-
this.channel.disconnect();
|
|
3073
|
-
}
|
|
3074
|
-
clear_creds_buffer() {
|
|
3075
|
-
// this.usernameBuffer = "";
|
|
3076
|
-
// this.passwordBuffer = "";
|
|
3077
|
-
}
|
|
3078
|
-
reset_session_state() {
|
|
3079
|
-
// this.session_id = undefined;
|
|
3080
|
-
// this.inputMode = InputMode.Default;
|
|
3081
|
-
this.clear_creds_buffer();
|
|
3082
|
-
}
|
|
3083
|
-
list_breadcrumb(path) {
|
|
3084
|
-
this.show_loader = true;
|
|
3085
|
-
this.selected_item = null;
|
|
3086
|
-
this.channel.send_sftp_list_data(this.nodeId, this.session_id, path);
|
|
3087
|
-
}
|
|
3088
|
-
go_to_parent_directory() {
|
|
3089
|
-
if (!this.session_id) {
|
|
3090
|
-
return;
|
|
3091
|
-
}
|
|
3092
|
-
if (this.current_dir === '/') {
|
|
3093
|
-
return;
|
|
3094
|
-
}
|
|
3095
|
-
const parent = this.breadcrumbs[this.breadcrumbs.length - 2]?.path || '/';
|
|
3096
|
-
this.list_breadcrumb(parent);
|
|
3097
|
-
}
|
|
3098
|
-
refresh_directory() {
|
|
3099
|
-
if (!this.session_id) {
|
|
3100
|
-
return;
|
|
3101
|
-
}
|
|
3102
|
-
this.list_breadcrumb(this.current_dir);
|
|
3103
|
-
}
|
|
3104
|
-
disconnect_session() {
|
|
3105
|
-
this.close_comms();
|
|
3106
|
-
this.session_id = undefined;
|
|
3107
|
-
this.show_loader = false;
|
|
3108
|
-
this.show_content = false;
|
|
3109
|
-
this.breadcrumbs = [];
|
|
3110
|
-
this.current_dir = '.';
|
|
3111
|
-
this.listing = [];
|
|
3112
|
-
this.show_navigation = false;
|
|
3113
|
-
this.show_login_screen_username = false;
|
|
3114
|
-
this.show_login_screen_password = false;
|
|
3115
|
-
this.show_login_screen = false;
|
|
3116
|
-
this.show_upload_modal = false;
|
|
3117
|
-
this.show_download_modal = false;
|
|
3118
|
-
this.show_delete_modal = false;
|
|
3119
|
-
this.upload_progress = 0;
|
|
3120
|
-
this.download_progress = 0;
|
|
3121
|
-
this.upload_finished = false;
|
|
3122
|
-
this.download_finished = false;
|
|
3123
|
-
this.delete_loading = false;
|
|
3124
|
-
this.delete_file_name = '';
|
|
3125
|
-
this.delete_error = '';
|
|
3126
|
-
this.delete_is_dir = false;
|
|
3127
|
-
this.delete_recursive = false;
|
|
3128
|
-
this.prompt_kind = null;
|
|
3129
|
-
this.prompt_value = '';
|
|
3130
|
-
this.prompt_error = '';
|
|
3131
|
-
this.prompt_busy = false;
|
|
3132
|
-
this.chmod_target = null;
|
|
3133
|
-
this.chmod_error = '';
|
|
3134
|
-
this.chmod_busy = false;
|
|
3135
|
-
this.show_editor = false;
|
|
3136
|
-
this.editor_busy = '';
|
|
3137
|
-
this.editor_error = '';
|
|
3138
|
-
this.editor_confirm_discard = false;
|
|
3139
|
-
this.editor_loaded = false;
|
|
3140
|
-
this.filter = '';
|
|
3141
|
-
this.version = '';
|
|
3142
|
-
this.status = 'Disconnected';
|
|
3143
|
-
this.channel_ready = false;
|
|
3144
|
-
this.part_delete = null;
|
|
3145
|
-
this.torrent_menu = null;
|
|
3146
|
-
this.listing_player = null;
|
|
3147
|
-
}
|
|
3148
|
-
on_file_row_action(item, event) {
|
|
3149
|
-
event.preventDefault();
|
|
3150
|
-
event.stopPropagation();
|
|
3151
|
-
if (item.kind !== 'File') {
|
|
3152
|
-
return;
|
|
3153
|
-
}
|
|
3154
|
-
void this.start_download(item);
|
|
3155
|
-
}
|
|
3156
|
-
on_file_delete_action(item, event) {
|
|
3157
|
-
event.preventDefault();
|
|
3158
|
-
event.stopPropagation();
|
|
3159
|
-
this.selected_item = item;
|
|
3160
|
-
// A plain SFTP delete of a running download's part file would only
|
|
3161
|
-
// make the job retry: ask the downloader to delete the download.
|
|
3162
|
-
if (item.kind === 'File' && isPartFile(item.name) && this.downloaderEl) {
|
|
3163
|
-
const downloader = this.downloaderEl;
|
|
3164
|
-
void downloader.jobForPath(this.item_path(item)).then((job) => {
|
|
3165
|
-
if (job) {
|
|
3166
|
-
this.part_delete = { download_id: job.download_id, name: item.name, busy: false };
|
|
3167
|
-
}
|
|
3168
|
-
else {
|
|
3169
|
-
this.open_delete_prompt(item);
|
|
3170
|
-
}
|
|
3171
|
-
});
|
|
3172
|
-
return;
|
|
3173
|
-
}
|
|
3174
|
-
this.open_delete_prompt(item);
|
|
3175
|
-
}
|
|
3176
|
-
open_delete_prompt(item) {
|
|
3177
|
-
this.delete_file_name = item.name;
|
|
3178
|
-
this.delete_is_dir = item.kind === 'Folder';
|
|
3179
|
-
this.delete_recursive = false;
|
|
3180
|
-
this.delete_error = '';
|
|
3181
|
-
this.delete_loading = false;
|
|
3182
|
-
this.show_delete_modal = true;
|
|
3183
|
-
}
|
|
3184
|
-
cancel_delete() {
|
|
3185
|
-
if (this.delete_loading) {
|
|
3186
|
-
return;
|
|
3187
|
-
}
|
|
3188
|
-
this.show_delete_modal = false;
|
|
3189
|
-
this.delete_file_name = '';
|
|
3190
|
-
this.delete_error = '';
|
|
3191
|
-
this.delete_is_dir = false;
|
|
3192
|
-
this.delete_recursive = false;
|
|
3193
|
-
}
|
|
3194
|
-
async confirm_delete() {
|
|
3195
|
-
if (this.delete_loading) {
|
|
3196
|
-
return;
|
|
3197
|
-
}
|
|
3198
|
-
const target = this.selected_item;
|
|
3199
|
-
if (!this.session_id || !target) {
|
|
3200
|
-
this.show_delete_modal = false;
|
|
3201
|
-
return;
|
|
3202
|
-
}
|
|
3203
|
-
const path = this.item_path(target);
|
|
3204
|
-
const recursive = this.delete_is_dir && this.delete_recursive;
|
|
3205
|
-
this.delete_loading = true;
|
|
3206
|
-
this.delete_error = '';
|
|
3207
|
-
this.show_error = false;
|
|
3208
|
-
this.status = `Deleting ${target.name}...`;
|
|
3209
|
-
try {
|
|
3210
|
-
// A recursive delete walks the tree one entry at a time over SSH,
|
|
3211
|
-
// so it earns a far longer leash than the other operations.
|
|
3212
|
-
await this.run_op('delete', (msgId) => this.channel.send_sftp_remove(this.nodeId, this.session_id, path, recursive, msgId), recursive ? 300_000 : 30_000);
|
|
3213
|
-
this.delete_loading = false;
|
|
3214
|
-
this.show_delete_modal = false;
|
|
3215
|
-
this.delete_file_name = '';
|
|
3216
|
-
this.delete_is_dir = false;
|
|
3217
|
-
this.delete_recursive = false;
|
|
3218
|
-
this.status = 'Connected';
|
|
3219
|
-
this.refresh_directory();
|
|
3220
|
-
}
|
|
3221
|
-
catch (err) {
|
|
3222
|
-
this.delete_loading = false;
|
|
3223
|
-
this.delete_error = this.error_text(err);
|
|
3224
|
-
this.status = 'Connected';
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
open_mkdir() {
|
|
3228
|
-
if (!this.session_id) {
|
|
3229
|
-
return;
|
|
3230
|
-
}
|
|
3231
|
-
this.prompt_kind = 'mkdir';
|
|
3232
|
-
this.prompt_value = '';
|
|
3233
|
-
this.prompt_error = '';
|
|
3234
|
-
this.prompt_busy = false;
|
|
3235
|
-
}
|
|
3236
|
-
on_rename_action(item, event) {
|
|
3237
|
-
event.preventDefault();
|
|
3238
|
-
event.stopPropagation();
|
|
3239
|
-
if (!this.session_id) {
|
|
3240
|
-
return;
|
|
3241
|
-
}
|
|
3242
|
-
this.selected_item = item;
|
|
3243
|
-
this.prompt_kind = 'rename';
|
|
3244
|
-
this.prompt_value = item.name;
|
|
3245
|
-
this.prompt_error = '';
|
|
3246
|
-
this.prompt_busy = false;
|
|
3247
|
-
}
|
|
3248
|
-
close_prompt() {
|
|
3249
|
-
if (this.prompt_busy) {
|
|
3250
|
-
return;
|
|
3251
|
-
}
|
|
3252
|
-
this.prompt_kind = null;
|
|
3253
|
-
this.prompt_value = '';
|
|
3254
|
-
this.prompt_error = '';
|
|
3255
|
-
this.promptInputEl = undefined;
|
|
3256
|
-
}
|
|
3257
|
-
async submit_prompt() {
|
|
3258
|
-
if (this.prompt_busy || !this.session_id) {
|
|
3259
|
-
return;
|
|
3260
|
-
}
|
|
3261
|
-
const kind = this.prompt_kind;
|
|
3262
|
-
const name = this.prompt_value.trim();
|
|
3263
|
-
const invalid = this.invalid_name(name);
|
|
3264
|
-
if (invalid) {
|
|
3265
|
-
this.prompt_error = invalid;
|
|
3266
|
-
return;
|
|
3267
|
-
}
|
|
3268
|
-
const target = this.selected_item;
|
|
3269
|
-
if (kind === 'rename' && target && name === target.name) {
|
|
3270
|
-
this.close_prompt();
|
|
3271
|
-
return;
|
|
3272
|
-
}
|
|
3273
|
-
this.prompt_busy = true;
|
|
3274
|
-
this.prompt_error = '';
|
|
3275
|
-
this.show_error = false;
|
|
3276
|
-
try {
|
|
3277
|
-
if (kind === 'mkdir') {
|
|
3278
|
-
const path = this.join_path(this.current_dir, name);
|
|
3279
|
-
this.status = `Creating ${name}...`;
|
|
3280
|
-
await this.run_op('create the folder', (msgId) => this.channel.send_sftp_mkdir(this.nodeId, this.session_id, path, msgId));
|
|
3281
|
-
}
|
|
3282
|
-
else if (kind === 'rename' && target) {
|
|
3283
|
-
// `to` is a full path, so the same call would move the entry if
|
|
3284
|
-
// the dialog ever offered a destination directory.
|
|
3285
|
-
const from = this.item_path(target);
|
|
3286
|
-
const to = this.join_path(target.path, name);
|
|
3287
|
-
this.status = `Renaming ${target.name}...`;
|
|
3288
|
-
await this.run_op('rename', (msgId) => this.channel.send_sftp_rename(this.nodeId, this.session_id, from, to, msgId));
|
|
3289
|
-
}
|
|
3290
|
-
else {
|
|
3291
|
-
this.prompt_busy = false;
|
|
3292
|
-
this.close_prompt();
|
|
3293
|
-
return;
|
|
3294
|
-
}
|
|
3295
|
-
this.prompt_busy = false;
|
|
3296
|
-
this.prompt_kind = null;
|
|
3297
|
-
this.prompt_value = '';
|
|
3298
|
-
this.promptInputEl = undefined;
|
|
3299
|
-
this.status = 'Connected';
|
|
3300
|
-
this.refresh_directory();
|
|
3301
|
-
}
|
|
3302
|
-
catch (err) {
|
|
3303
|
-
this.prompt_busy = false;
|
|
3304
|
-
this.prompt_error = this.error_text(err);
|
|
3305
|
-
this.status = 'Connected';
|
|
3306
|
-
}
|
|
3307
|
-
}
|
|
3308
|
-
on_chmod_action(item, event) {
|
|
3309
|
-
event.preventDefault();
|
|
3310
|
-
event.stopPropagation();
|
|
3311
|
-
if (!this.session_id) {
|
|
3312
|
-
return;
|
|
3313
|
-
}
|
|
3314
|
-
this.selected_item = item;
|
|
3315
|
-
this.chmod_target = item;
|
|
3316
|
-
this.chmod_mode = (item.attributes.permissions ?? 0) & 0o7777;
|
|
3317
|
-
this.chmod_error = '';
|
|
3318
|
-
this.chmod_busy = false;
|
|
3319
|
-
}
|
|
3320
|
-
close_chmod() {
|
|
3321
|
-
if (this.chmod_busy) {
|
|
3322
|
-
return;
|
|
3323
|
-
}
|
|
3324
|
-
this.chmod_target = null;
|
|
3325
|
-
this.chmod_error = '';
|
|
3326
|
-
}
|
|
3327
|
-
toggle_chmod_bit(bit) {
|
|
3328
|
-
if (this.chmod_busy) {
|
|
3329
|
-
return;
|
|
3330
|
-
}
|
|
3331
|
-
this.chmod_mode = (this.chmod_mode ^ bit) & 0o7777;
|
|
3332
|
-
}
|
|
3333
|
-
on_chmod_octal_input(value) {
|
|
3334
|
-
const digits = value.trim();
|
|
3335
|
-
if (!/^[0-7]{1,4}$/.test(digits)) {
|
|
3336
|
-
this.chmod_error = 'Enter up to four octal digits, 0-7.';
|
|
3337
|
-
return;
|
|
3338
|
-
}
|
|
3339
|
-
this.chmod_error = '';
|
|
3340
|
-
this.chmod_mode = parseInt(digits, 8) & 0o7777;
|
|
3341
|
-
}
|
|
3342
|
-
async submit_chmod() {
|
|
3343
|
-
const target = this.chmod_target;
|
|
3344
|
-
if (this.chmod_busy || !this.session_id || !target) {
|
|
3345
|
-
return;
|
|
3346
|
-
}
|
|
3347
|
-
const path = this.item_path(target);
|
|
3348
|
-
const mode = this.chmod_mode & 0o7777;
|
|
3349
|
-
this.chmod_busy = true;
|
|
3350
|
-
this.chmod_error = '';
|
|
3351
|
-
this.show_error = false;
|
|
3352
|
-
this.status = `Setting permissions on ${target.name}...`;
|
|
3353
|
-
try {
|
|
3354
|
-
await this.run_op('change permissions', (msgId) => this.channel.send_sftp_chmod(this.nodeId, this.session_id, path, mode, msgId));
|
|
3355
|
-
this.chmod_busy = false;
|
|
3356
|
-
this.chmod_target = null;
|
|
3357
|
-
this.status = 'Connected';
|
|
3358
|
-
this.refresh_directory();
|
|
3359
|
-
}
|
|
3360
|
-
catch (err) {
|
|
3361
|
-
this.chmod_busy = false;
|
|
3362
|
-
this.chmod_error = this.error_text(err);
|
|
3363
|
-
this.status = 'Connected';
|
|
3364
|
-
}
|
|
3365
|
-
}
|
|
3366
|
-
async on_edit_action(item, event) {
|
|
3367
|
-
event.preventDefault();
|
|
3368
|
-
event.stopPropagation();
|
|
3369
|
-
if (!this.session_id || item.kind !== 'File') {
|
|
3370
|
-
return;
|
|
3371
|
-
}
|
|
3372
|
-
const path = this.item_path(item);
|
|
3373
|
-
this.selected_item = item;
|
|
3374
|
-
this.show_editor = true;
|
|
3375
|
-
this.editorPath = path;
|
|
3376
|
-
this.editor_name = item.name;
|
|
3377
|
-
this.editor_text = '';
|
|
3378
|
-
this.editor_saved_text = '';
|
|
3379
|
-
this.editor_error = '';
|
|
3380
|
-
this.editor_confirm_discard = false;
|
|
3381
|
-
this.editor_loaded = false;
|
|
3382
|
-
this.editor_busy = 'loading';
|
|
3383
|
-
this.status = `Opening ${item.name}...`;
|
|
3384
|
-
try {
|
|
3385
|
-
const answer = await this.run_op('open the file', (msgId) => this.channel.send_sftp_read_file(this.nodeId, this.session_id, path, msgId), 60_000);
|
|
3386
|
-
if (answer.result !== 'FileContents') {
|
|
3387
|
-
throw new Error('The agent answered without any file contents.');
|
|
3388
|
-
}
|
|
3389
|
-
const text = this.decode_text(answer.contents instanceof Uint8Array ? answer.contents : new Uint8Array(answer.contents));
|
|
3390
|
-
this.editor_text = text;
|
|
3391
|
-
this.editor_saved_text = text;
|
|
3392
|
-
this.editor_loaded = true;
|
|
3393
|
-
this.editor_busy = '';
|
|
3394
|
-
this.status = 'Connected';
|
|
3395
|
-
}
|
|
3396
|
-
catch (err) {
|
|
3397
|
-
this.editor_busy = '';
|
|
3398
|
-
this.editor_error = this.error_text(err);
|
|
3399
|
-
this.status = 'Connected';
|
|
3400
|
-
}
|
|
3401
|
-
}
|
|
3402
|
-
/**
|
|
3403
|
-
* Refuse binary rather than mangle it. A lossy decode looks fine on screen
|
|
3404
|
-
* and then writes replacement characters over the real bytes on save, so
|
|
3405
|
-
* anything that is not valid UTF-8 is sent to the download button instead.
|
|
3406
|
-
*/
|
|
3407
|
-
decode_text(bytes) {
|
|
3408
|
-
if (bytes.includes(0)) {
|
|
3409
|
-
throw new Error('This looks like a binary file. Download it instead of editing it here.');
|
|
3410
|
-
}
|
|
3411
|
-
try {
|
|
3412
|
-
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
3413
|
-
}
|
|
3414
|
-
catch {
|
|
3415
|
-
throw new Error('This file is not valid UTF-8. Download it instead of editing it here.');
|
|
3416
|
-
}
|
|
3417
|
-
}
|
|
3418
|
-
editor_is_dirty() {
|
|
3419
|
-
return this.editor_loaded && this.editor_text !== this.editor_saved_text;
|
|
3420
|
-
}
|
|
3421
|
-
close_editor(force = false) {
|
|
3422
|
-
if (this.editor_busy === 'saving') {
|
|
3423
|
-
return;
|
|
3424
|
-
}
|
|
3425
|
-
if (!force && this.editor_is_dirty()) {
|
|
3426
|
-
this.editor_confirm_discard = true;
|
|
3427
|
-
return;
|
|
3428
|
-
}
|
|
3429
|
-
this.show_editor = false;
|
|
3430
|
-
this.editor_confirm_discard = false;
|
|
3431
|
-
this.editor_loaded = false;
|
|
3432
|
-
this.editorPath = '';
|
|
3433
|
-
this.editor_name = '';
|
|
3434
|
-
this.editor_text = '';
|
|
3435
|
-
this.editor_saved_text = '';
|
|
3436
|
-
this.editor_error = '';
|
|
3437
|
-
this.editor_busy = '';
|
|
3438
|
-
this.editorTextEl = undefined;
|
|
3439
|
-
}
|
|
3440
|
-
async save_editor() {
|
|
3441
|
-
if (this.editor_busy || !this.session_id || !this.editorPath) {
|
|
3442
|
-
return;
|
|
3443
|
-
}
|
|
3444
|
-
const path = this.editorPath;
|
|
3445
|
-
const text = this.editor_text;
|
|
3446
|
-
this.editor_busy = 'saving';
|
|
3447
|
-
this.editor_error = '';
|
|
3448
|
-
this.show_error = false;
|
|
3449
|
-
this.status = `Saving ${this.editor_name}...`;
|
|
3450
|
-
try {
|
|
3451
|
-
await this.run_op('save the file', (msgId) => this.channel.send_sftp_write_file(this.nodeId, this.session_id, path, new TextEncoder().encode(text), msgId), 60_000);
|
|
3452
|
-
this.editor_saved_text = text;
|
|
3453
|
-
this.editor_busy = '';
|
|
3454
|
-
this.status = 'Connected';
|
|
3455
|
-
this.refresh_directory();
|
|
3456
|
-
}
|
|
3457
|
-
catch (err) {
|
|
3458
|
-
this.editor_busy = '';
|
|
3459
|
-
this.editor_error = this.error_text(err);
|
|
3460
|
-
this.status = 'Connected';
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
toggle_sort(key) {
|
|
3464
|
-
if (this.sort_key === key) {
|
|
3465
|
-
this.sort_asc = !this.sort_asc;
|
|
3466
|
-
return;
|
|
3467
|
-
}
|
|
3468
|
-
this.sort_key = key;
|
|
3469
|
-
this.sort_asc = true;
|
|
3470
|
-
}
|
|
3471
|
-
/**
|
|
3472
|
-
* Folders stay above files whichever way the sort runs: a listing that
|
|
3473
|
-
* scatters directories through the files is harder to scan, not more sorted.
|
|
3474
|
-
*/
|
|
3475
|
-
visible_listing() {
|
|
3476
|
-
const needle = this.filter.trim().toLowerCase();
|
|
3477
|
-
const rows = needle
|
|
3478
|
-
? this.listing.filter((item) => item.name.toLowerCase().includes(needle))
|
|
3479
|
-
: [...this.listing];
|
|
3480
|
-
const direction = this.sort_asc ? 1 : -1;
|
|
3481
|
-
return rows.sort((a, b) => {
|
|
3482
|
-
if (a.kind !== b.kind) {
|
|
3483
|
-
return a.kind === 'Folder' ? -1 : 1;
|
|
3484
|
-
}
|
|
3485
|
-
switch (this.sort_key) {
|
|
3486
|
-
case 'size':
|
|
3487
|
-
return direction * ((a.attributes.size ?? 0) - (b.attributes.size ?? 0));
|
|
3488
|
-
case 'modified':
|
|
3489
|
-
return direction * ((a.attributes.modified ?? 0) - (b.attributes.modified ?? 0));
|
|
3490
|
-
default:
|
|
3491
|
-
return direction * a.name.localeCompare(b.name, undefined, {
|
|
3492
|
-
numeric: true,
|
|
3493
|
-
sensitivity: 'base',
|
|
3494
|
-
});
|
|
3495
|
-
}
|
|
3496
|
-
});
|
|
3497
|
-
}
|
|
3498
|
-
sort_indicator(key) {
|
|
3499
|
-
if (this.sort_key !== key) {
|
|
3500
|
-
return '';
|
|
3501
|
-
}
|
|
3502
|
-
return this.sort_asc ? ' \u25b2' : ' \u25bc';
|
|
3503
|
-
}
|
|
3504
|
-
/** Keyboard shortcuts, scoped to the file table so the page keeps its own. */
|
|
3505
|
-
on_listing_keydown(event) {
|
|
3506
|
-
if (this.prompt_kind || this.chmod_target || this.show_editor || this.show_delete_modal) {
|
|
3507
|
-
return;
|
|
3508
|
-
}
|
|
3509
|
-
const item = this.selected_item;
|
|
3510
|
-
switch (event.key) {
|
|
3511
|
-
case 'Backspace':
|
|
3512
|
-
event.preventDefault();
|
|
3513
|
-
this.go_to_parent_directory();
|
|
3514
|
-
break;
|
|
3515
|
-
case 'F5':
|
|
3516
|
-
event.preventDefault();
|
|
3517
|
-
this.refresh_directory();
|
|
3518
|
-
break;
|
|
3519
|
-
case 'F2':
|
|
3520
|
-
if (item) {
|
|
3521
|
-
event.preventDefault();
|
|
3522
|
-
this.on_rename_action(item, event);
|
|
3523
|
-
}
|
|
3524
|
-
break;
|
|
3525
|
-
case 'Delete':
|
|
3526
|
-
if (item) {
|
|
3527
|
-
event.preventDefault();
|
|
3528
|
-
this.on_file_delete_action(item, event);
|
|
3529
|
-
}
|
|
3530
|
-
break;
|
|
3531
|
-
case 'Enter':
|
|
3532
|
-
if (item) {
|
|
3533
|
-
event.preventDefault();
|
|
3534
|
-
this.list_directory(item);
|
|
3535
|
-
}
|
|
3536
|
-
break;
|
|
3537
|
-
}
|
|
3538
|
-
}
|
|
3539
|
-
on_modal_keydown(event, close) {
|
|
3540
|
-
if (event.key === 'Escape') {
|
|
3541
|
-
event.preventDefault();
|
|
3542
|
-
event.stopPropagation();
|
|
3543
|
-
close();
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
|
-
/** Focus a dialog's field as it appears, without re-focusing on every render. */
|
|
3547
|
-
focus_once(el, current, keep) {
|
|
3548
|
-
if (!el || el === current) {
|
|
3549
|
-
return;
|
|
3550
|
-
}
|
|
3551
|
-
keep(el);
|
|
3552
|
-
requestAnimationFrame(() => el.focus());
|
|
3553
|
-
}
|
|
3554
|
-
open_upload_picker() {
|
|
3555
|
-
this.uploadInputEl?.click();
|
|
3556
|
-
}
|
|
3557
|
-
on_upload_selected(event) {
|
|
3558
|
-
const input = event.target;
|
|
3559
|
-
const selectedFile = input.files?.[0];
|
|
3560
|
-
if (!selectedFile) {
|
|
3561
|
-
return;
|
|
3562
|
-
}
|
|
3563
|
-
void this.upload_file(selectedFile);
|
|
3564
|
-
input.value = '';
|
|
3565
|
-
}
|
|
3566
|
-
cancel_upload() {
|
|
3567
|
-
this.cancel_active_upload();
|
|
3568
|
-
this.show_upload_modal = false;
|
|
3569
|
-
this.upload_file_name = '';
|
|
3570
|
-
this.upload_speed = '--';
|
|
3571
|
-
this.status = 'Connected';
|
|
3572
|
-
this.refresh_directory();
|
|
3573
|
-
}
|
|
3574
|
-
cancel_download() {
|
|
3575
|
-
this.cancel_active_download();
|
|
3576
|
-
this.show_download_modal = false;
|
|
3577
|
-
this.download_file_name = '';
|
|
3578
|
-
this.download_speed = '--';
|
|
3579
|
-
this.status = 'Connected';
|
|
3580
|
-
this.refresh_directory();
|
|
3581
|
-
}
|
|
3582
|
-
is_selected(item) {
|
|
3583
|
-
if (!this.selected_item) {
|
|
3584
|
-
return false;
|
|
3585
|
-
}
|
|
3586
|
-
return this.selected_item.path === item.path &&
|
|
3587
|
-
this.selected_item.name === item.name;
|
|
3588
|
-
}
|
|
3589
|
-
list_directory(entry) {
|
|
3590
|
-
if (!this.session_id) {
|
|
3591
|
-
console.warn('No active session. Cannot list directory.');
|
|
3592
|
-
return;
|
|
3593
|
-
}
|
|
3594
|
-
if (entry.kind === 'File') {
|
|
3595
|
-
console.warn('Cannot list directory of a file. Ignoring click.');
|
|
3596
|
-
this.selected_item = entry;
|
|
3597
|
-
return;
|
|
3598
|
-
}
|
|
3599
|
-
const path = this.item_path(entry);
|
|
3600
|
-
if (path === this.current_dir) {
|
|
3601
|
-
console.warn('Already in this directory. Ignoring click.');
|
|
3602
|
-
return;
|
|
3603
|
-
}
|
|
3604
|
-
this.show_loader = true;
|
|
3605
|
-
this.selected_item = null;
|
|
3606
|
-
this.channel.send_sftp_list_data(this.nodeId, this.session_id, path);
|
|
3607
|
-
}
|
|
3608
|
-
format_size(size) {
|
|
3609
|
-
if (size === undefined || Number.isNaN(size)) {
|
|
3610
|
-
return '-';
|
|
3611
|
-
}
|
|
3612
|
-
if (size < 1024) {
|
|
3613
|
-
return `${size} B`;
|
|
3614
|
-
}
|
|
3615
|
-
const units = ['KB', 'MB', 'GB', 'TB', 'PB'];
|
|
3616
|
-
let value = size;
|
|
3617
|
-
let unitIndex = -1;
|
|
3618
|
-
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
3619
|
-
value /= 1024;
|
|
3620
|
-
unitIndex += 1;
|
|
3621
|
-
}
|
|
3622
|
-
const rounded = value >= 10 ? value.toFixed(1) : value.toFixed(2);
|
|
3623
|
-
return `${rounded} ${units[unitIndex]}`;
|
|
3624
|
-
}
|
|
3625
|
-
mode_type_to_char(mode, kind) {
|
|
3626
|
-
const S_IFMT = 0o170000;
|
|
3627
|
-
const type = mode & S_IFMT;
|
|
3628
|
-
switch (type) {
|
|
3629
|
-
case 0o140000: return 's';
|
|
3630
|
-
case 0o120000: return 'l';
|
|
3631
|
-
case 0o100000: return '-';
|
|
3632
|
-
case 0o060000: return 'b';
|
|
3633
|
-
case 0o040000: return 'd';
|
|
3634
|
-
case 0o020000: return 'c';
|
|
3635
|
-
case 0o010000: return 'p';
|
|
3636
|
-
default:
|
|
3637
|
-
return kind === 'Folder' ? 'd' : '-';
|
|
3638
|
-
}
|
|
3639
|
-
}
|
|
3640
|
-
format_permissions(permissions, kind) {
|
|
3641
|
-
if (permissions === undefined || permissions === null) {
|
|
3642
|
-
return '-';
|
|
3643
|
-
}
|
|
3644
|
-
if (typeof permissions === 'string') {
|
|
3645
|
-
const value = permissions.trim();
|
|
3646
|
-
if (/^[bcdlps-][rwxStTs-]{9}$/.test(value)) {
|
|
3647
|
-
return value;
|
|
3648
|
-
}
|
|
3649
|
-
if (/^[0-7]{3,4}$/.test(value)) {
|
|
3650
|
-
const mode = parseInt(value, 8);
|
|
3651
|
-
return this.format_permissions(mode, kind);
|
|
3652
|
-
}
|
|
3653
|
-
if (/^\d+$/.test(value)) {
|
|
3654
|
-
const mode = parseInt(value, 10);
|
|
3655
|
-
return this.format_permissions(mode, kind);
|
|
3656
|
-
}
|
|
3657
|
-
return value || '-';
|
|
3658
|
-
}
|
|
3659
|
-
const mode = permissions;
|
|
3660
|
-
const typeChar = this.mode_type_to_char(mode, kind);
|
|
3661
|
-
const chars = [
|
|
3662
|
-
mode & 0o400 ? 'r' : '-',
|
|
3663
|
-
mode & 0o200 ? 'w' : '-',
|
|
3664
|
-
mode & 0o100 ? 'x' : '-',
|
|
3665
|
-
mode & 0o040 ? 'r' : '-',
|
|
3666
|
-
mode & 0o020 ? 'w' : '-',
|
|
3667
|
-
mode & 0o010 ? 'x' : '-',
|
|
3668
|
-
mode & 0o004 ? 'r' : '-',
|
|
3669
|
-
mode & 0o002 ? 'w' : '-',
|
|
3670
|
-
mode & 0o001 ? 'x' : '-',
|
|
3671
|
-
];
|
|
3672
|
-
if (mode & 0o4000) {
|
|
3673
|
-
chars[2] = chars[2] === 'x' ? 's' : 'S';
|
|
3674
|
-
}
|
|
3675
|
-
if (mode & 0o2000) {
|
|
3676
|
-
chars[5] = chars[5] === 'x' ? 's' : 'S';
|
|
3677
|
-
}
|
|
3678
|
-
if (mode & 0o1000) {
|
|
3679
|
-
chars[8] = chars[8] === 'x' ? 't' : 'T';
|
|
3680
|
-
}
|
|
3681
|
-
return `${typeChar}${chars.join('')}`;
|
|
3682
|
-
}
|
|
3683
|
-
render() {
|
|
3684
|
-
return (index.h(index.Host, { key: 'c8a576625404b5653c066c2844160c40cff71603', class: {
|
|
3685
|
-
'default': !this.max,
|
|
3686
|
-
'max': this.max,
|
|
3687
|
-
} }, index.h("section", { key: '87cc1357c8cba09dc857ac0035d701ee46f72ad3', class: "listing" }, !this.hideHeader &&
|
|
3688
|
-
index.h("header", { key: 'f034a4a4d6498c8f813174566ce7ff258f6d98fb' }, index.h("section", { key: 'ce24941dbd0beffe42d5fa6bad89542d25e57ff8', class: "title" }, index.h("img", { key: '808e0b3f448e15ceb5a7daccce98f9314eb5b758', src: phirepassSftpClientLogoSvg, alt: "SFTP Client" }), index.h("div", { key: '4b4e8244a97167010abc5ba2a518f9c7fd465b39', class: "text" }, index.h("div", { key: 'dc32511596fb480ef7fb280941b9de8099b5ff05', class: "name" }, this.name), index.h("div", { key: 'fc477ea5670b74c40f4af20022dac4f02bc8b96c', class: "description" }, this.description))), index.h("section", { key: '35beb6cd84dea257e428cca3338db239eed37cdb', class: "actions" }, index.h("div", { key: '7adecc9ecb0a24721fcf6e82f73b58d38946801e', class: "action", onClick: () => this.toggle_max() }, index.h("img", { key: 'e63674064553d3809a1d563bbe6fc83ad0aceb80', src: phirepassSftpClientMaxSvg, alt: "Maximize" })))), index.h("main", { key: '4bef9055a683d18e391c2620ba2351282a1165ca' }, this.show_navigation && index.h("nav", { key: 'e08ac22ec258e081195785661907d170b86bd83d', class: "navigation" }, index.h("div", { key: '026e32148d4062a7e6be2b58192676dc0102e2dd', class: "breadcrumbs" }, this.breadcrumbs.map((crumb, index$1, breadcrumbs) => (index.h("span", { key: index$1, class: "breadcrumb-container" }, index.h("span", { key: index$1, onClick: () => this.list_breadcrumb(crumb.path), class: "breadcrumb" }, crumb.label), index$1 < breadcrumbs.length - 1 && index.h("img", { class: "arrow", src: phirepassSftpClientChevronSvg }))))), index.h("section", { key: '04f0111d530f2cb9a64bb0557b72820bd13832bf', class: "actions", "aria-label": "SFTP actions" }, index.h("input", { key: 'fb28f1861a4dd9c83aaa4a20a5d25dde3e6337c7', class: "filter", type: "search", autocorrect: "off", autocapitalize: "none", autoComplete: "off", placeholder: "Filter", "aria-label": "Filter this directory", value: this.filter, onInput: (event) => this.filter = event.target.value }), index.h("button", { key: '5e173f8426eee17b08b05547e9ba033746a5a84a', type: "button", class: "action", onClick: () => this.go_to_parent_directory(), title: "Go to parent directory", "aria-label": "Go to parent directory" }, index.h("img", { key: '64ed13f7093abc57f9b73638b902b160d11c1fd3', src: phirepassSftpClientGoUpSvg, alt: "Go up" })), index.h("button", { key: 'e6a7d97bc089f3b023d06213852aec8e5cd83d18', type: "button", class: "action", onClick: () => this.refresh_directory(), title: "Refresh", "aria-label": "Refresh" }, index.h("img", { key: '66590858743453d7fc0fbb578e98da2a8bc762d5', src: phirepassSftpClientRefreshSvg, alt: "Refresh" })), index.h("button", { key: '8eca55beb0377394da8fae85546b25ee74c0f6f9', type: "button", class: "action", onClick: () => this.open_mkdir(), title: "New folder", "aria-label": "New folder" }, index.h("svg", { key: '12d1fc50a9e325a1214462f2a06d734ab38ff1c1', xmlns: "http://www.w3.org/2000/svg", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }, index.h("path", { key: '7148c12cc461d1778ccfb3e3129786655f780dc2', d: "M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" }), index.h("line", { key: 'a5701765411cff983baa1c4248a383c3a3a9dca6', x1: "12", x2: "12", y1: "10", y2: "16" }), index.h("line", { key: '9c22835c4279619e8c8cd130007d07ed19795366', x1: "9", x2: "15", y1: "13", y2: "13" }))), this.fetch_enabled() && index.h(FetchButton, { key: '259d3c2e7bdadac5d1ed77724628459e6c440e09', count: this.fetch_count, onClick: () => void this.downloaderEl?.openFetch(this.current_dir) }), index.h("button", { key: 'f744681697e23f2f2892a01b625490fc66999592', type: "button", class: "action", onClick: () => this.open_upload_picker(), title: "Upload", "aria-label": "Upload" }, index.h("img", { key: 'bcb2e3f7c283f4213b0a27cb97afd3e61f8d954e', src: phirepassSftpClientUploadSvg, alt: "Upload" })), index.h("button", { key: '5348bc25576e559e7b2f05ec6378fe72fc8483f5', type: "button", class: "action disconnect", onClick: () => this.disconnect_session(), title: "Disconnect", "aria-label": "Disconnect" }, "DISCONNECT"))), index.h("input", { key: '7daf75741416f3aeb759ddc6c94106167291d641', type: "file", ref: (el) => this.uploadInputEl = el, onChange: (event) => this.on_upload_selected(event), style: { display: 'none' } }), this.show_content && index.h("div", { key: 'e384c122d7454b16d13066a7cc6f7f3aa1414feb', class: "content", tabindex: 0, onKeyDown: (event) => this.on_listing_keydown(event) }, index.h("table", { key: 'bd1b14b317290eb59cb867a2bfbf23fb63b2fa94' }, index.h("thead", { key: 'c414438b0e8f2a776643bdaaf6441b01ed7c3be3' }, index.h("tr", { key: 'fd7d0947644aa0e0eb93d56dfacb8fe545c805f3' }, index.h("th", { key: '8e62f0daaaad938db61b85586aeb138844877ebe', class: "sortable", onClick: () => this.toggle_sort('name'), title: "Sort by name" }, "Name", this.sort_indicator('name')), index.h("th", { key: 'f2d3e287c8f0f97e23c173c10393d0eec4e4a752', class: "sortable", onClick: () => this.toggle_sort('size'), title: "Sort by size" }, "Size", this.sort_indicator('size')), index.h("th", { key: 'd62906a8dd76c22cfcf2c7a82d37ffe8ac3582ba' }, "Permissions"), index.h("th", { key: 'd5ce78f188629f956704a70a8d2280a1db945666' }, "Owner"), index.h("th", { key: '42d52536f0c5daa29af06c892c5ca3f79b888216', class: "sortable", onClick: () => this.toggle_sort('modified'), title: "Sort by modified date" }, "Modified", this.sort_indicator('modified')), index.h("th", { key: '4b80527286d771950be9219387fb938e92f07b63', class: "action-col", "aria-label": "Actions" }))), index.h("tbody", { key: '1959c3f04257c8c1a2e93b4717a6eef9a7999437' }, this.visible_listing().map((item, index$1) => (index.h("tr", { key: index$1, class: {
|
|
3689
|
-
'selected': this.is_selected(item),
|
|
3690
|
-
'part': item.kind === 'File' && isPartFile(item.name),
|
|
3691
|
-
'fresh': item.kind === 'File' && this.fresh_names.includes(item.name),
|
|
3692
|
-
}, onClick: () => this.list_directory(item), onContextMenu: (event) => void this.on_row_context_menu(item, event) }, index.h("td", null, item.kind === 'Folder' ? index.h("img", { class: "kind", src: phirepassSftpClientFolderSvg, alt: "Folder" }) : index.h("img", { class: "kind", src: phirepassSftpClientFileSvg, alt: "File" }), index.h("span", { class: `name ${item.kind.toLowerCase()}` }, item.name)), index.h("td", null, item.kind === 'Folder' ? '-' : this.format_size(item.attributes.size)), index.h("td", null, this.format_permissions(item.attributes.permissions, item.kind)), index.h("td", null, item.attributes.user ?? '-'), index.h("td", null, new Date(item.attributes.modified * 1000).toLocaleString()), index.h("td", { class: "action-col" }, index.h("div", { class: "file-actions" }, item.kind === 'File' && isPlayableFile(item.name) && this.listing_can_play() &&
|
|
3693
|
-
index.h("button", { type: "button", class: "file-action", onClick: (event) => void this.play_listing_file(item, event), title: "Play", "aria-label": `Play ${item.name}` }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true" }, index.h("path", { d: "M7 5v14l12-7z" }))), item.kind === 'File' &&
|
|
3694
|
-
index.h("button", { type: "button", class: "file-action", onClick: (event) => this.on_edit_action(item, event), title: "Edit", "aria-label": `Edit ${item.name}` }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }, index.h("path", { d: "M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" }), index.h("path", { d: "M18.5 2.5a2.12 2.12 0 0 1 3 3L12 15l-4 1 1-4Z" }))), item.kind === 'File' &&
|
|
3695
|
-
index.h("button", { type: "button", class: "file-action", onClick: (event) => this.on_file_row_action(item, event), title: "Download", "aria-label": `Download ${item.name}` }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }, index.h("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }), index.h("polyline", { points: "7 10 12 15 17 10" }), index.h("line", { x1: "12", x2: "12", y1: "15", y2: "3" }))), index.h("button", { type: "button", class: "file-action", onClick: (event) => this.on_rename_action(item, event), title: "Rename", "aria-label": `Rename ${item.name}` }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }, index.h("path", { d: "M12 20h9" }), index.h("path", { d: "M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z" }))), index.h("button", { type: "button", class: "file-action", onClick: (event) => this.on_chmod_action(item, event), title: "Permissions", "aria-label": `Change permissions on ${item.name}` }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }, index.h("rect", { width: "18", height: "11", x: "3", y: "11", rx: "2", ry: "2" }), index.h("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" }))), index.h("button", { type: "button", class: "file-action delete", onClick: (event) => this.on_file_delete_action(item, event), title: "Delete", "aria-label": `Delete ${item.name}` }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true" }, index.h("polyline", { points: "3 6 5 6 21 6" }), index.h("path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" }), index.h("path", { d: "M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6" }), index.h("line", { x1: "10", x2: "10", y1: "11", y2: "17" }), index.h("line", { x1: "14", x2: "14", y1: "11", y2: "17" })))))))), this.visible_listing().length === 0 &&
|
|
3696
|
-
index.h("tr", { key: '94619eb9cf5506a57c6d085ac6b91d41b7770553', class: "empty" }, index.h("td", { key: '87161e6091cf501364eda0d0b1072a937f8c9946', colSpan: 6 }, this.filter ? `Nothing here matches "${this.filter}".` : 'This directory is empty.'))))), this.show_loader && index.h("div", { key: 'db0f871976de1f36a72fa947441e0fb1f6051438', class: "loader" }, "Loading..."), this.show_error && index.h("div", { key: '8870f437cfe246be74479d98f0a0d5a2bc72f781', class: "error" }, this.error_message)), this.fetch_enabled() &&
|
|
3697
|
-
index.h("phirepass-downloader", { key: '917af582cad03523807ef641710f85bd74bb317e', ref: (el) => this.downloaderEl = el, compact: true, channel: this.channel, connected: this.channel_ready, nodeId: this.nodeId, browsingService: this.serviceId, browsingPath: this.current_dir, streamBase: this.stream_base(), onPhirepassActiveCount: (event) => this.fetch_count = event.detail.n, onPhirepassFetchCompleted: (event) => this.on_fetch_completed(event.detail), onPhirepassShowInFolder: (event) => this.on_show_in_folder(event.detail) }), index.h("footer", { key: 'ff3c726b1762ca1789b1f3cd795613d9e64ec445' }, index.h("section", { key: '47e1cbc5a79ee62355136341add2b67456d1a462', class: "status" }, this.status, this.selected_item && index.h("span", { key: 'c828889045b7d0cca91ce0703a577f9a35a708e0', class: "selected-item" }, this.selected_item.name)), index.h("section", { key: '9e16fe486979999adadd80483542709570a5992d', class: "version" }, this.version ? `Version: ${this.version}` : ''))), this.show_login_screen &&
|
|
3698
|
-
index.h("section", { key: '4da9c7934d550538c3bd488c7ad455af30ff4e00', class: {
|
|
3699
|
-
'creds': true,
|
|
3700
|
-
'blurred': this.show_login_screen,
|
|
3701
|
-
} }, index.h("form", { key: '576cc82e5cd90978039e1e644af04194485b86d6', class: "auth", onSubmit: (event) => {
|
|
3702
|
-
const formData = new FormData(event.target);
|
|
3703
|
-
let username = undefined;
|
|
3704
|
-
if (this.show_login_screen_username) {
|
|
3705
|
-
username = formData.get('username');
|
|
3706
|
-
}
|
|
3707
|
-
let password = undefined;
|
|
3708
|
-
if (this.show_login_screen_password) {
|
|
3709
|
-
password = formData.get('password');
|
|
3710
|
-
}
|
|
3711
|
-
this.channel.open_sftp_tunnel(this.nodeId, this.serviceId, username, password);
|
|
3712
|
-
this.show_login_screen_username = false;
|
|
3713
|
-
this.show_login_screen_password = false;
|
|
3714
|
-
this.show_login_screen = false;
|
|
3715
|
-
this.show_loader = true;
|
|
3716
|
-
event.stopPropagation();
|
|
3717
|
-
event.preventDefault();
|
|
3718
|
-
} }, index.h("div", { key: '27098f0a63b4ceddd4e0bf0d84b3b3f321a3f512', class: "title" }, "SFTP Connection"), this.show_login_screen_username &&
|
|
3719
|
-
index.h("div", { key: '2714b5b014572d4f58523ddb79bde232bf9b65f1' }, index.h("label", { key: '8f0c73f148cc08fc8db445cd99fbab060807fe12', htmlFor: "username" }, "Username"), index.h("input", { key: 'c64fd60eb284e8a77d0943380cb3fcbacbc333fa', autocorrect: "off", autocapitalize: "none", autoComplete: "off", id: "username", name: "username", type: "text", placeholder: "" })), this.show_login_screen_password &&
|
|
3720
|
-
index.h("div", { key: '2d84bbacefcb3b4ba84a9b8ce74bd662fa62c8b3' }, index.h("label", { key: '0ce1b8309229d45ab0f54d5e2de1e40b3fab57f0', htmlFor: "password" }, "Password"), index.h("input", { key: '5752cbe6e72c332be94c0b9a813a66526ab06f3c', autocorrect: "off", autocapitalize: "none", autoComplete: "off", id: "password", name: "password", type: "password", placeholder: "" })), index.h("div", { key: 'e272596a07a758d008a90a2c2290e589feeb8b3f' }, index.h("button", { key: '5ddb365a8b700a8d5051539bed3c9aafef20a099', type: "submit" }, "Connect")))), this.show_upload_modal &&
|
|
3721
|
-
index.h("section", { key: 'b4314fc5bb3ace26757d690ff4113954144362f6', class: {
|
|
3722
|
-
'upload-modal': true,
|
|
3723
|
-
'visible': this.show_upload_modal,
|
|
3724
|
-
} }, index.h("div", { key: '8d152c11c9c27528b667199e6cd66e7129506be6', class: "upload-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Upload progress" }, index.h("div", { key: '703aa9f78b0248f026ae168d95db2aaaea65a6ce', class: "title" }, "Uploading File"), index.h("div", { key: '8e9bceaea052b871b2b6700684384515260c864c', class: "file-name", title: this.upload_file_name }, this.upload_file_name), index.h("div", { key: '0c3f7be58a562e339dea87904297d0407bddb289', class: "progress-track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": this.upload_progress }, index.h("div", { key: 'e003866966bdae3af7e9321b288dd23424491a16', class: "progress-fill", style: { width: `${this.upload_progress}%` } })), index.h("div", { key: 'ac5e45111e0d694b09c4af709378e827288ad418', class: "progress-meta" }, index.h("div", { key: '63e5c77d6af531e49fe9817167d945fc6e80e1be', class: "progress-speed" }, this.upload_speed), index.h("div", { key: '369628aa1ba577c4a4a9fa13930985716830b993', class: "progress-value" }, this.format_percent(this.upload_progress))), index.h("button", { key: 'da4984bb0fc81d65a8f2876aa1aaba5dc8ea9da8', type: "button", class: {
|
|
3725
|
-
'cancel': true,
|
|
3726
|
-
'finished': this.upload_finished,
|
|
3727
|
-
}, onClick: () => this.cancel_upload() }, this.upload_finished ? 'Close' : 'Cancel'))), this.show_download_modal &&
|
|
3728
|
-
index.h("section", { key: '88a14959b710af2dcced2fc37b7c404272571084', class: {
|
|
3729
|
-
'download-modal': true,
|
|
3730
|
-
'visible': this.show_download_modal,
|
|
3731
|
-
} }, index.h("div", { key: '86bbc1dd32612e7b63c4af35b366fe0a74597ed9', class: "download-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Download progress" }, index.h("div", { key: '8c3edb4fc04ffaecb3fbd5b6d1aeab4211d7876c', class: "title" }, "Downloading File"), index.h("div", { key: '4815f43687f525c0b6f598e98f9df237a4253dd9', class: "file-name", title: this.download_file_name }, this.download_file_name), index.h("div", { key: '095ac5ffbcb3f4a1bfe5742232752baffb93308e', class: "progress-track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": this.download_progress }, index.h("div", { key: '6a1f3d4ddbbda2c8a4069b59c7882ddcddee5b4d', class: "progress-fill", style: { width: `${this.download_progress}%` } })), index.h("div", { key: 'db52703f7105f26aa4234eb6b623524362ced064', class: "progress-meta" }, index.h("div", { key: 'a12b2578badf08fc272f3533db2fd93fa946a4b2', class: "progress-speed" }, this.download_speed), index.h("div", { key: '3b2b1d92c4534d6f7adf01d64a1593af504f98d0', class: "progress-value" }, this.format_percent(this.download_progress))), index.h("button", { key: 'f9a668ef58d9566ebaf66ad9219d619005294a6f', type: "button", class: {
|
|
3732
|
-
'cancel': true,
|
|
3733
|
-
'finished': this.download_finished,
|
|
3734
|
-
}, onClick: () => this.cancel_download() }, this.download_finished ? 'Close' : 'Cancel'))), this.show_delete_modal &&
|
|
3735
|
-
index.h("section", { key: 'cbcf699a17d748a8a7fa3daf1d96f42e47847bd6', class: {
|
|
3736
|
-
'delete-modal': true,
|
|
3737
|
-
'visible': this.show_delete_modal,
|
|
3738
|
-
} }, index.h("div", { key: '3ac99ddba7dc86a7712a4cbb1516254a62f88ef4', class: "delete-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Delete confirmation", tabindex: -1, onKeyDown: (event) => this.on_modal_keydown(event, () => this.cancel_delete()) }, index.h("div", { key: '5075e7e7fda69e6941980d3bb257b30bd61d1b03', class: "title" }, this.delete_is_dir ? 'Delete Folder' : 'Delete File'), index.h("div", { key: 'a9bc63a90afc0f56caccdda8c782abf761b06fa9', class: "message" }, this.delete_loading
|
|
3739
|
-
? (this.delete_recursive ? 'Deleting the folder and everything in it...' : 'Deleting...')
|
|
3740
|
-
: `Are you sure you want to delete this ${this.delete_is_dir ? 'folder' : 'file'}?`), index.h("div", { key: '50a72830064fc1352787d6ac761a13e8c6d2d5ce', class: "file-name", title: this.delete_file_name }, this.delete_file_name), this.delete_is_dir &&
|
|
3741
|
-
index.h("label", { key: '528ba9b17f186d54e98fa5abe26d649721880eab', class: "checkline" }, index.h("input", { key: '33dc78531ac4833e95460b93de7d211979a7973b', type: "checkbox", checked: this.delete_recursive, disabled: this.delete_loading, onChange: (event) => this.delete_recursive = event.target.checked }), index.h("span", { key: '68517a96007ba248bbcac1fffaae2b048c4aafaf' }, "Delete everything inside it too")), !this.delete_is_dir || this.delete_recursive ? null :
|
|
3742
|
-
index.h("div", { class: "hint" }, "Without this, the remote refuses a folder that is not empty."), this.delete_error && index.h("div", { key: 'fb0df28a4daa756166deec9dd18c0acae8874202', class: "dialog-error" }, this.delete_error), this.delete_loading &&
|
|
3743
|
-
index.h("div", { key: '114fcfea0367efd1f2df2d06beeba2013058ff73', class: "delete-loader", "aria-hidden": "true" }, index.h("span", { key: '2b07a71d733ba7606fa45f0d24548b2b63dcc798', class: "spinner" })), index.h("div", { key: '44cfc262272484fdbd41257c39457d42de6e1f29', class: "modal-actions" }, index.h("button", { key: '5035eb462279fb4e89036a34b5b5b64eee052706', type: "button", class: "btn secondary", onClick: () => this.cancel_delete(), disabled: this.delete_loading }, "Cancel"), index.h("button", { key: 'f16d9f97ce99691c0cfbbad16679bb1dc3affbc9', type: "button", class: "btn destructive", onClick: () => this.confirm_delete(), disabled: this.delete_loading }, this.delete_loading ? 'Deleting...' : 'Delete')))), this.prompt_kind &&
|
|
3744
|
-
index.h("section", { key: '8ee05b491fbc60b2fa9115fa7a88b60960e3326a', class: "prompt-modal visible" }, index.h("div", { key: '46622ceafa285047e2df9082251d7a02e38cb49f', class: "prompt-dialog", role: "dialog", "aria-modal": "true", "aria-label": this.prompt_kind === 'mkdir' ? 'New folder' : 'Rename', tabindex: -1, onKeyDown: (event) => this.on_modal_keydown(event, () => this.close_prompt()) }, index.h("div", { key: '1dce2a864f58590017238fc76810297190dc223f', class: "title" }, this.prompt_kind === 'mkdir' ? 'New Folder' : 'Rename'), index.h("div", { key: '556e931df541d9ca07a58882cf658572c23276fe', class: "message" }, this.prompt_kind === 'mkdir'
|
|
3745
|
-
? `Create a folder in ${this.current_dir}`
|
|
3746
|
-
: 'Give it a new name. Existing names are not overwritten.'), index.h("form", { key: 'b6a5807b0208576e15468912c48bcdc314cf2d41', onSubmit: (event) => { event.preventDefault(); event.stopPropagation(); void this.submit_prompt(); } }, index.h("input", { key: 'd7ad180a2b431046905f37ee8ba21e6933f8eb09', class: "dialog-input", type: "text", autocorrect: "off", autocapitalize: "none", autoComplete: "off", spellcheck: false, "aria-label": "Name", disabled: this.prompt_busy, value: this.prompt_value, onInput: (event) => this.prompt_value = event.target.value, ref: (el) => this.focus_once(el, this.promptInputEl, (kept) => this.promptInputEl = kept) }), this.prompt_error && index.h("div", { key: 'c0afc0bc34860b1c8bcfea5087d8afca425edf6a', class: "dialog-error" }, this.prompt_error), index.h("div", { key: '91899e1d57a82434cc859e7d90636bd9f1df2545', class: "modal-actions" }, index.h("button", { key: '24f1d359789dbd40e8d98ddf220acf2e5cdbb1e1', type: "button", class: "btn secondary", onClick: () => this.close_prompt(), disabled: this.prompt_busy }, "Cancel"), index.h("button", { key: '3a5ae8f5edbbe70c226d9ec01d204b0f276607cd', type: "submit", class: "btn primary", disabled: this.prompt_busy }, this.prompt_busy ? 'Working...' : (this.prompt_kind === 'mkdir' ? 'Create' : 'Rename')))))), this.chmod_target &&
|
|
3747
|
-
index.h("section", { key: '3f5daa368a81ae49fd074c33979fad6d9dc1e79f', class: "prompt-modal visible" }, index.h("div", { key: 'a2cfc7cbecbead9ccd977e74213c48ba47d5e0f7', class: "prompt-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Change permissions", tabindex: -1, onKeyDown: (event) => this.on_modal_keydown(event, () => this.close_chmod()) }, index.h("div", { key: '6db7c2771db3bf9dc4c16c506c95fbadc01b24d5', class: "title" }, "Permissions"), index.h("div", { key: 'c6fba2cffb84fd01ac51171ddedc140978652756', class: "file-name", title: this.chmod_target.name }, this.chmod_target.name), index.h("table", { key: 'fc871c448ad4ad75754256f0b4d9ce9e5188ea90', class: "perm-grid" }, index.h("thead", { key: 'b2de44bba7219257af5e16687f1f9e44b64429b8' }, index.h("tr", { key: 'b4e964c7281f8088385d1707df0c638b99c0e1e7' }, index.h("th", { key: 'a0bebfa92a96c6276a8c57bbd56555c1c8cacbd2', "aria-label": "Class" }), index.h("th", { key: 'c7618c92048861c4ee94d0fb8078c6dd719d9603' }, "Read"), index.h("th", { key: '23d0d6cbf7de82f337d4230e0286174a5fc6bd97' }, "Write"), index.h("th", { key: 'fbbe7fafe3aa03ed29db6038157167362c736f9c' }, "Execute"))), index.h("tbody", { key: '5468214c98eb5e6278cade8d46bcae62394d0205' }, [
|
|
3748
|
-
{ label: 'Owner', read: 0o400, write: 0o200, exec: 0o100 },
|
|
3749
|
-
{ label: 'Group', read: 0o040, write: 0o020, exec: 0o010 },
|
|
3750
|
-
{ label: 'Other', read: 0o004, write: 0o002, exec: 0o001 },
|
|
3751
|
-
].map((row) => (index.h("tr", { key: row.label }, index.h("th", { scope: "row" }, row.label), [row.read, row.write, row.exec].map((bit) => (index.h("td", { key: bit }, index.h("input", { type: "checkbox", "aria-label": `${row.label} ${bit}`, disabled: this.chmod_busy, checked: (this.chmod_mode & bit) !== 0, onChange: () => this.toggle_chmod_bit(bit) }))))))))), index.h("div", { key: '61a09c4521472a61f3f7e71fe651cb42f125ed81', class: "perm-special" }, [
|
|
3752
|
-
{ label: 'setuid', bit: 0o4000 },
|
|
3753
|
-
{ label: 'setgid', bit: 0o2000 },
|
|
3754
|
-
{ label: 'sticky', bit: 0o1000 },
|
|
3755
|
-
].map((special) => (index.h("label", { key: special.label, class: "checkline" }, index.h("input", { type: "checkbox", disabled: this.chmod_busy, checked: (this.chmod_mode & special.bit) !== 0, onChange: () => this.toggle_chmod_bit(special.bit) }), index.h("span", null, special.label))))), index.h("div", { key: '49370f167cbe30ee221f6373d4261571b25be38b', class: "perm-octal" }, index.h("label", { key: 'f0b17a2ed4c59cbbaf02cd34cc847c773118faef', htmlFor: "chmod-octal" }, "Octal"), index.h("input", { key: '020ec6003d98553c663cceb92502f6391c60691b', id: "chmod-octal", class: "dialog-input", type: "text", autocorrect: "off", autocapitalize: "none", autoComplete: "off", spellcheck: false, maxlength: 4, disabled: this.chmod_busy, value: this.chmod_mode.toString(8).padStart(4, '0'), onInput: (event) => this.on_chmod_octal_input(event.target.value) }), index.h("span", { key: '4cc7a1cbe4ddfb565f44b5ef3fd116feb879b6c0', class: "perm-preview" }, this.format_permissions(this.chmod_mode, this.chmod_target.kind))), this.chmod_error && index.h("div", { key: '99cc2d982aef130ea75fa61765d17921186cc2fb', class: "dialog-error" }, this.chmod_error), index.h("div", { key: 'd5796750cfa9eb9304340bb9fd091eea7781f3cc', class: "modal-actions" }, index.h("button", { key: 'dffe3756b1b4e593ff71663e931df57d53c4a842', type: "button", class: "btn secondary", onClick: () => this.close_chmod(), disabled: this.chmod_busy }, "Cancel"), index.h("button", { key: 'cb30401112b8f500b49e6974dc67ae9065319539', type: "button", class: "btn primary", onClick: () => void this.submit_chmod(), disabled: this.chmod_busy }, this.chmod_busy ? 'Applying...' : 'Apply')))), this.show_editor &&
|
|
3756
|
-
index.h("section", { key: 'c9be5edfe1feea95ca51495503dc0c1c3b213d70', class: "editor-modal visible" }, index.h("div", { key: 'bf7c2aec8559b42017dc7142bc8a12f0fb4f1c39', class: "editor-dialog", role: "dialog", "aria-modal": "true", "aria-label": `Editing ${this.editor_name}`, tabindex: -1, onKeyDown: (event) => {
|
|
3757
|
-
if ((event.ctrlKey || event.metaKey) && event.key === 's') {
|
|
3758
|
-
event.preventDefault();
|
|
3759
|
-
void this.save_editor();
|
|
3760
|
-
return;
|
|
3761
|
-
}
|
|
3762
|
-
this.on_modal_keydown(event, () => this.close_editor());
|
|
3763
|
-
} }, index.h("div", { key: 'fb6c305fc54a7c5f419a133c9477a69b489b77f0', class: "editor-head" }, index.h("div", { key: '9b22c14a92be28cc42ea900b4907d4411f5e3c7d', class: "title" }, this.editor_name, this.editor_is_dirty() ? ' *' : ''), index.h("button", { key: '2c800c08e12448ddf3c0f92f34257960ea0ea713', type: "button", class: "editor-close", onClick: () => this.close_editor(), "aria-label": "Close editor", disabled: this.editor_busy === 'saving' }, "x")), this.editor_busy === 'loading'
|
|
3764
|
-
? index.h("div", { class: "editor-loading" }, "Loading...")
|
|
3765
|
-
: index.h("textarea", { class: "editor-text", spellcheck: false, autocorrect: "off", autocapitalize: "none", autoComplete: "off", "aria-label": "File contents", disabled: this.editor_busy === 'saving' || !this.editor_loaded, value: this.editor_text, onInput: (event) => this.editor_text = event.target.value, ref: (el) => this.focus_once(el, this.editorTextEl, (kept) => this.editorTextEl = kept) }), this.editor_error && index.h("div", { key: '7918d367cbe8c9a3c179a20f8083b9c4e067ad79', class: "dialog-error" }, this.editor_error), this.editor_confirm_discard &&
|
|
3766
|
-
index.h("div", { key: '6b2ba93692a575bd2c6253dcd7c9abb65807a900', class: "dialog-error" }, "Unsaved changes. Close anyway?"), index.h("div", { key: '879a150fdb6501ad95847a09f984f5acd9301830', class: "modal-actions" }, this.editor_confirm_discard
|
|
3767
|
-
? index.h("button", { type: "button", class: "btn destructive", onClick: () => this.close_editor(true) }, "Discard")
|
|
3768
|
-
: index.h("button", { type: "button", class: "btn secondary", onClick: () => this.close_editor(), disabled: this.editor_busy === 'saving' }, "Close"), index.h("button", { key: 'e034f852259bcf75f6ba28159706862cfefbe5fa', type: "button", class: "btn primary", onClick: () => void this.save_editor(), disabled: !!this.editor_busy || !this.editor_is_dirty() }, this.editor_busy === 'saving' ? 'Saving...' : 'Save')))), this.part_delete &&
|
|
3769
|
-
index.h(PartDeleteDialog, { key: 'e7789b9ddf6e9d7f9e479aa390e7391e61c208f7', name: this.part_delete.name, busy: this.part_delete.busy, onCancel: () => this.part_delete = null, onConfirm: () => {
|
|
3770
|
-
const target = this.part_delete;
|
|
3771
|
-
this.part_delete = { ...target, busy: true };
|
|
3772
|
-
void this.downloaderEl?.deleteDownload(target.download_id).finally(() => {
|
|
3773
|
-
this.part_delete = null;
|
|
3774
|
-
this.refresh_directory();
|
|
3775
|
-
});
|
|
3776
|
-
} }), this.torrent_menu &&
|
|
3777
|
-
index.h(TorrentContextMenu, { key: '094cd2ab17cf975825db6afefcf205855221a03b', menu: this.torrent_menu, onClose: () => this.torrent_menu = null, onFetch: () => {
|
|
3778
|
-
const path = this.torrent_menu.path;
|
|
3779
|
-
this.torrent_menu = null;
|
|
3780
|
-
void this.downloaderEl?.startTorrentPath(path);
|
|
3781
|
-
}, onDownload: () => {
|
|
3782
|
-
const item = this.selected_item;
|
|
3783
|
-
this.torrent_menu = null;
|
|
3784
|
-
if (item)
|
|
3785
|
-
void this.start_download(item);
|
|
3786
|
-
}, onRename: () => {
|
|
3787
|
-
const item = this.selected_item;
|
|
3788
|
-
this.torrent_menu = null;
|
|
3789
|
-
if (item)
|
|
3790
|
-
this.on_rename_action(item, new window.Event('click'));
|
|
3791
|
-
}, onDelete: () => {
|
|
3792
|
-
const item = this.selected_item;
|
|
3793
|
-
this.torrent_menu = null;
|
|
3794
|
-
if (item)
|
|
3795
|
-
this.on_file_delete_action(item, new window.Event('click'));
|
|
3796
|
-
} }), this.listing_player &&
|
|
3797
|
-
index.h("section", { key: 'f5b06ff083b4af19a7c4cc336d8be172c0e646e1', class: "player-modal visible" }, index.h("phirepass-media-player", { key: 'b2770268f3fb6af053a6a52da1e346d8ae3cdda9', src: this.listing_player.src, name: this.listing_player.name, status: "On the node", positionKey: this.listing_player.key, onPhirepassPlayerClose: () => this.listing_player = null }))));
|
|
3798
|
-
}
|
|
3799
|
-
static get watchers() { return {
|
|
3800
|
-
"nodeId": [{
|
|
3801
|
-
"onNodeIdChange": 0
|
|
3802
|
-
}],
|
|
3803
|
-
"serverId": [{
|
|
3804
|
-
"onServerIdChange": 0
|
|
3805
|
-
}]
|
|
3806
|
-
}; }
|
|
3807
|
-
};
|
|
3808
|
-
PhirepassSftpClient.style = phirepassSftpClientCss();
|
|
3809
|
-
|
|
3810
|
-
exports.phirepass_downloader = PhirepassDownloader;
|
|
3811
|
-
exports.phirepass_media_player = PhirepassMediaPlayer;
|
|
3812
|
-
exports.phirepass_sftp_client = PhirepassSftpClient;
|