phirepass-widgets 0.0.100 → 0.0.102
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/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/phirepass-rdp.cjs.entry.js +30 -10
- package/dist/cjs/phirepass-sftp-client.cjs.entry.js +547 -81
- package/dist/cjs/phirepass-terminal.cjs.entry.js +2 -2
- package/dist/cjs/phirepass-widgets.cjs.js +1 -1
- package/dist/cjs/{protocol-B45sQiET.js → protocol-BcMWzyWp.js} +155 -59
- package/dist/collection/common/protocol.js +1 -0
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +17 -8
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.viewport.js +12 -1
- package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.css +342 -2
- package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.js +568 -80
- package/dist/collection/components/phirepass-terminal/phirepass-terminal.js +1 -1
- package/dist/collection/phirepass-channel_bg.wasm +0 -0
- package/dist/components/p-Dzyd97Ok.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 +2 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/phirepass-rdp.entry.js +30 -10
- package/dist/esm/phirepass-sftp-client.entry.js +547 -81
- package/dist/esm/phirepass-terminal.entry.js +2 -2
- package/dist/esm/phirepass-widgets.js +1 -1
- package/dist/esm/{protocol-DFhjP92A.js → protocol-Dzyd97Ok.js} +154 -58
- package/dist/phirepass-widgets/p-11aedd04.entry.js +1 -0
- package/dist/phirepass-widgets/{p-c4a31b26.entry.js → p-16145ab4.entry.js} +2 -2
- package/dist/phirepass-widgets/p-57d80137.entry.js +1 -0
- package/dist/phirepass-widgets/p-Dzyd97Ok.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/protocol.d.ts +22 -2
- package/dist/types/components/phirepass-rdp/phirepass-rdp.viewport.d.ts +11 -1
- package/dist/types/components/phirepass-sftp-client/phirepass-sftp-client.d.ts +85 -4
- package/package.json +2 -2
- package/dist/components/p-DFhjP92A.js +0 -1
- package/dist/phirepass-widgets/p-0e9afedb.entry.js +0 -1
- package/dist/phirepass-widgets/p-DFhjP92A.js +0 -1
- package/dist/phirepass-widgets/p-ee09d805.entry.js +0 -1
|
@@ -16,7 +16,6 @@ export class PhirepassSftpClient {
|
|
|
16
16
|
runtimeReady = false;
|
|
17
17
|
connected = false;
|
|
18
18
|
uploadInputEl;
|
|
19
|
-
deleteLoadingTimeout;
|
|
20
19
|
msgId = 1;
|
|
21
20
|
activeUploadToken = 0;
|
|
22
21
|
pendingUploadStarts = new Map();
|
|
@@ -24,7 +23,10 @@ export class PhirepassSftpClient {
|
|
|
24
23
|
pendingDownloadStarts = new Map();
|
|
25
24
|
activeDownloads = new Map();
|
|
26
25
|
activeDownloadMsgId;
|
|
27
|
-
|
|
26
|
+
pendingOps = new Map();
|
|
27
|
+
promptInputEl;
|
|
28
|
+
editorPath = '';
|
|
29
|
+
editorTextEl;
|
|
28
30
|
// private inputMode: InputMode = InputMode.Default;
|
|
29
31
|
session_id;
|
|
30
32
|
// private usernameBuffer = "";
|
|
@@ -96,6 +98,32 @@ export class PhirepassSftpClient {
|
|
|
96
98
|
show_delete_modal = false;
|
|
97
99
|
delete_file_name = '';
|
|
98
100
|
delete_loading = false;
|
|
101
|
+
delete_is_dir = false;
|
|
102
|
+
delete_recursive = false;
|
|
103
|
+
delete_error = '';
|
|
104
|
+
/** `mkdir` and `rename` share one dialog: both take a single name. */
|
|
105
|
+
prompt_kind = null;
|
|
106
|
+
prompt_value = '';
|
|
107
|
+
prompt_error = '';
|
|
108
|
+
prompt_busy = false;
|
|
109
|
+
chmod_target = null;
|
|
110
|
+
/** Permission bits under edit, masked to 0o7777. */
|
|
111
|
+
chmod_mode = 0;
|
|
112
|
+
chmod_error = '';
|
|
113
|
+
chmod_busy = false;
|
|
114
|
+
show_editor = false;
|
|
115
|
+
editor_name = '';
|
|
116
|
+
editor_text = '';
|
|
117
|
+
/** What is on the remote, so the dialog knows whether it has edits. */
|
|
118
|
+
editor_saved_text = '';
|
|
119
|
+
editor_busy = '';
|
|
120
|
+
editor_error = '';
|
|
121
|
+
editor_confirm_discard = false;
|
|
122
|
+
/** False until the file's contents are in hand, so a failed open is read-only. */
|
|
123
|
+
editor_loaded = false;
|
|
124
|
+
filter = '';
|
|
125
|
+
sort_key = 'name';
|
|
126
|
+
sort_asc = true;
|
|
99
127
|
toggle_max() {
|
|
100
128
|
this.maximizeEvent?.emit(!this.max);
|
|
101
129
|
}
|
|
@@ -129,16 +157,9 @@ export class PhirepassSftpClient {
|
|
|
129
157
|
this.cancel_active_upload();
|
|
130
158
|
this.cancel_active_download();
|
|
131
159
|
this.clear_pending_operations();
|
|
132
|
-
this.clear_delete_loading_timeout();
|
|
133
160
|
this.close_comms();
|
|
134
161
|
// this.destroy_terminal();
|
|
135
162
|
}
|
|
136
|
-
clear_delete_loading_timeout() {
|
|
137
|
-
if (this.deleteLoadingTimeout !== undefined) {
|
|
138
|
-
window.clearTimeout(this.deleteLoadingTimeout);
|
|
139
|
-
this.deleteLoadingTimeout = undefined;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
163
|
next_msg_id() {
|
|
143
164
|
const id = this.msgId;
|
|
144
165
|
this.msgId += 1;
|
|
@@ -160,15 +181,13 @@ export class PhirepassSftpClient {
|
|
|
160
181
|
pending.reject(new Error('Download start aborted'));
|
|
161
182
|
});
|
|
162
183
|
this.pendingDownloadStarts.clear();
|
|
163
|
-
this.
|
|
184
|
+
this.pendingOps.forEach((pending) => {
|
|
185
|
+
window.clearTimeout(pending.timeout);
|
|
186
|
+
pending.reject(new Error(`Could not ${pending.verb}: the session ended.`));
|
|
187
|
+
});
|
|
188
|
+
this.pendingOps.clear();
|
|
164
189
|
this.activeDownloads.clear();
|
|
165
190
|
}
|
|
166
|
-
stop_delete_polling() {
|
|
167
|
-
if (this.pendingDelete?.interval !== undefined) {
|
|
168
|
-
window.clearInterval(this.pendingDelete.interval);
|
|
169
|
-
}
|
|
170
|
-
this.pendingDelete = undefined;
|
|
171
|
-
}
|
|
172
191
|
cancel_active_upload() {
|
|
173
192
|
this.activeUploadToken += 1;
|
|
174
193
|
this.upload_progress = 0;
|
|
@@ -298,11 +317,16 @@ export class PhirepassSftpClient {
|
|
|
298
317
|
}
|
|
299
318
|
this.download_finished = false;
|
|
300
319
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.
|
|
305
|
-
|
|
320
|
+
const pendingOp = this.pendingOps.get(error.msg_id);
|
|
321
|
+
if (pendingOp) {
|
|
322
|
+
window.clearTimeout(pendingOp.timeout);
|
|
323
|
+
this.pendingOps.delete(error.msg_id);
|
|
324
|
+
pendingOp.reject(new Error(error.message || `Could not ${pendingOp.verb}.`));
|
|
325
|
+
// The caller puts this message in the dialog the user is
|
|
326
|
+
// looking at. Raising the page-level banner as well would say
|
|
327
|
+
// the same thing twice, in the place they are not looking.
|
|
328
|
+
this.show_loader = false;
|
|
329
|
+
return;
|
|
306
330
|
}
|
|
307
331
|
}
|
|
308
332
|
switch (error.kind) {
|
|
@@ -349,6 +373,11 @@ export class PhirepassSftpClient {
|
|
|
349
373
|
setTimeout(() => {
|
|
350
374
|
this.show_loader = false;
|
|
351
375
|
}, 500);
|
|
376
|
+
// A filter is about the directory you typed it in; carrying it into
|
|
377
|
+
// the next one hides most of what you just navigated to.
|
|
378
|
+
if (web.path !== this.current_dir) {
|
|
379
|
+
this.filter = '';
|
|
380
|
+
}
|
|
352
381
|
this.listing = web.dir.items;
|
|
353
382
|
this.current_dir = web.path;
|
|
354
383
|
this.breadcrumbs = web.path.split('/').map((path, index, arr) => {
|
|
@@ -359,16 +388,6 @@ export class PhirepassSftpClient {
|
|
|
359
388
|
});
|
|
360
389
|
this.show_content = true;
|
|
361
390
|
this.show_navigation = true;
|
|
362
|
-
if (this.pendingDelete && web.path === this.current_dir) {
|
|
363
|
-
const fileStillExists = web.dir.items.some((item) => item.kind === 'File' && item.name === this.pendingDelete?.filename);
|
|
364
|
-
if (!fileStillExists) {
|
|
365
|
-
this.stop_delete_polling();
|
|
366
|
-
this.delete_loading = false;
|
|
367
|
-
this.show_delete_modal = false;
|
|
368
|
-
this.delete_file_name = '';
|
|
369
|
-
this.status = 'Connected';
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
391
|
console.log('Received SFTP list items:', web);
|
|
373
392
|
}
|
|
374
393
|
handle_upload_start_response(web) {
|
|
@@ -578,6 +597,80 @@ export class PhirepassSftpClient {
|
|
|
578
597
|
this.status = 'Connected';
|
|
579
598
|
}
|
|
580
599
|
}
|
|
600
|
+
handle_op_result(web) {
|
|
601
|
+
if (web.msg_id === undefined) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const pending = this.pendingOps.get(web.msg_id);
|
|
605
|
+
if (!pending) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
window.clearTimeout(pending.timeout);
|
|
609
|
+
this.pendingOps.delete(web.msg_id);
|
|
610
|
+
pending.resolve(web.result);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Send one filesystem operation and wait for its single answer.
|
|
614
|
+
*
|
|
615
|
+
* There are three outcomes: an `SFTPOpResult` resolves it, an `Error` frame
|
|
616
|
+
* carrying the same `msg_id` rejects it, and the timeout covers the case
|
|
617
|
+
* worth naming — an agent built before these frames existed logs the
|
|
618
|
+
* unknown frame and drops it, so silence usually means "too old" rather
|
|
619
|
+
* than "slow", and the message says so.
|
|
620
|
+
*/
|
|
621
|
+
run_op(verb, send, timeoutMs = 30_000) {
|
|
622
|
+
if (!this.session_id) {
|
|
623
|
+
return Promise.reject(new Error('No active SFTP session.'));
|
|
624
|
+
}
|
|
625
|
+
const msgId = this.next_msg_id();
|
|
626
|
+
return new Promise((resolve, reject) => {
|
|
627
|
+
const timeout = window.setTimeout(() => {
|
|
628
|
+
this.pendingOps.delete(msgId);
|
|
629
|
+
reject(new Error(`Timed out trying to ${verb}. This node's agent may be too old to support it.`));
|
|
630
|
+
}, timeoutMs);
|
|
631
|
+
this.pendingOps.set(msgId, { verb, timeout, resolve, reject });
|
|
632
|
+
try {
|
|
633
|
+
send(msgId);
|
|
634
|
+
}
|
|
635
|
+
catch (err) {
|
|
636
|
+
window.clearTimeout(timeout);
|
|
637
|
+
this.pendingOps.delete(msgId);
|
|
638
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
error_text(err) {
|
|
643
|
+
return err instanceof Error ? err.message : String(err);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* A listing entry carries its *parent* directory in `path`, so a full path
|
|
647
|
+
* is always the join of the two.
|
|
648
|
+
*/
|
|
649
|
+
item_path(item) {
|
|
650
|
+
return this.join_path(item.path, item.name);
|
|
651
|
+
}
|
|
652
|
+
join_path(dir, name) {
|
|
653
|
+
if (!dir || dir === '/') {
|
|
654
|
+
return `/${name}`;
|
|
655
|
+
}
|
|
656
|
+
return dir.endsWith('/') ? `${dir}${name}` : `${dir}/${name}`;
|
|
657
|
+
}
|
|
658
|
+
/** Names the remote would reject, or that would silently mean something else. */
|
|
659
|
+
invalid_name(name) {
|
|
660
|
+
if (!name) {
|
|
661
|
+
return 'Enter a name.';
|
|
662
|
+
}
|
|
663
|
+
if (name === '.' || name === '..') {
|
|
664
|
+
return 'That name is reserved.';
|
|
665
|
+
}
|
|
666
|
+
if (name.includes('/')) {
|
|
667
|
+
return 'A name cannot contain "/".';
|
|
668
|
+
}
|
|
669
|
+
if (name.includes('\u0000')) {
|
|
670
|
+
return 'A name cannot contain a null byte.';
|
|
671
|
+
}
|
|
672
|
+
return '';
|
|
673
|
+
}
|
|
581
674
|
handle_tunnel_data(web) {
|
|
582
675
|
console.log('received tunnel data:', web);
|
|
583
676
|
}
|
|
@@ -645,6 +738,9 @@ export class PhirepassSftpClient {
|
|
|
645
738
|
case ProtocolMessageType.SFTPDownloadChunk:
|
|
646
739
|
this.handle_download_chunk(web);
|
|
647
740
|
break;
|
|
741
|
+
case ProtocolMessageType.SFTPOpResult:
|
|
742
|
+
this.handle_op_result(web);
|
|
743
|
+
break;
|
|
648
744
|
default:
|
|
649
745
|
console.warn('Unhandled protocol message type:', web);
|
|
650
746
|
}
|
|
@@ -711,6 +807,22 @@ export class PhirepassSftpClient {
|
|
|
711
807
|
this.download_finished = false;
|
|
712
808
|
this.delete_loading = false;
|
|
713
809
|
this.delete_file_name = '';
|
|
810
|
+
this.delete_error = '';
|
|
811
|
+
this.delete_is_dir = false;
|
|
812
|
+
this.delete_recursive = false;
|
|
813
|
+
this.prompt_kind = null;
|
|
814
|
+
this.prompt_value = '';
|
|
815
|
+
this.prompt_error = '';
|
|
816
|
+
this.prompt_busy = false;
|
|
817
|
+
this.chmod_target = null;
|
|
818
|
+
this.chmod_error = '';
|
|
819
|
+
this.chmod_busy = false;
|
|
820
|
+
this.show_editor = false;
|
|
821
|
+
this.editor_busy = '';
|
|
822
|
+
this.editor_error = '';
|
|
823
|
+
this.editor_confirm_discard = false;
|
|
824
|
+
this.editor_loaded = false;
|
|
825
|
+
this.filter = '';
|
|
714
826
|
this.version = '';
|
|
715
827
|
this.status = 'Disconnected';
|
|
716
828
|
}
|
|
@@ -727,6 +839,9 @@ export class PhirepassSftpClient {
|
|
|
727
839
|
event.stopPropagation();
|
|
728
840
|
this.selected_item = item;
|
|
729
841
|
this.delete_file_name = item.name;
|
|
842
|
+
this.delete_is_dir = item.kind === 'Folder';
|
|
843
|
+
this.delete_recursive = false;
|
|
844
|
+
this.delete_error = '';
|
|
730
845
|
this.delete_loading = false;
|
|
731
846
|
this.show_delete_modal = true;
|
|
732
847
|
}
|
|
@@ -736,49 +851,369 @@ export class PhirepassSftpClient {
|
|
|
736
851
|
}
|
|
737
852
|
this.show_delete_modal = false;
|
|
738
853
|
this.delete_file_name = '';
|
|
739
|
-
this.
|
|
740
|
-
this.
|
|
854
|
+
this.delete_error = '';
|
|
855
|
+
this.delete_is_dir = false;
|
|
856
|
+
this.delete_recursive = false;
|
|
741
857
|
}
|
|
742
|
-
confirm_delete() {
|
|
858
|
+
async confirm_delete() {
|
|
743
859
|
if (this.delete_loading) {
|
|
744
860
|
return;
|
|
745
861
|
}
|
|
746
|
-
|
|
862
|
+
const target = this.selected_item;
|
|
863
|
+
if (!this.session_id || !target) {
|
|
747
864
|
this.show_delete_modal = false;
|
|
748
865
|
return;
|
|
749
866
|
}
|
|
750
|
-
const
|
|
867
|
+
const path = this.item_path(target);
|
|
868
|
+
const recursive = this.delete_is_dir && this.delete_recursive;
|
|
751
869
|
this.delete_loading = true;
|
|
752
|
-
this.
|
|
870
|
+
this.delete_error = '';
|
|
753
871
|
this.show_error = false;
|
|
754
|
-
this.
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
msgId,
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
872
|
+
this.status = `Deleting ${target.name}...`;
|
|
873
|
+
try {
|
|
874
|
+
// A recursive delete walks the tree one entry at a time over SSH,
|
|
875
|
+
// so it earns a far longer leash than the other operations.
|
|
876
|
+
await this.run_op('delete', (msgId) => this.channel.send_sftp_remove(this.nodeId, this.session_id, path, recursive, msgId), recursive ? 300_000 : 30_000);
|
|
877
|
+
this.delete_loading = false;
|
|
878
|
+
this.show_delete_modal = false;
|
|
879
|
+
this.delete_file_name = '';
|
|
880
|
+
this.delete_is_dir = false;
|
|
881
|
+
this.delete_recursive = false;
|
|
882
|
+
this.status = 'Connected';
|
|
883
|
+
this.refresh_directory();
|
|
884
|
+
}
|
|
885
|
+
catch (err) {
|
|
886
|
+
this.delete_loading = false;
|
|
887
|
+
this.delete_error = this.error_text(err);
|
|
888
|
+
this.status = 'Connected';
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
open_mkdir() {
|
|
892
|
+
if (!this.session_id) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
this.prompt_kind = 'mkdir';
|
|
896
|
+
this.prompt_value = '';
|
|
897
|
+
this.prompt_error = '';
|
|
898
|
+
this.prompt_busy = false;
|
|
899
|
+
}
|
|
900
|
+
on_rename_action(item, event) {
|
|
901
|
+
event.preventDefault();
|
|
902
|
+
event.stopPropagation();
|
|
903
|
+
if (!this.session_id) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
this.selected_item = item;
|
|
907
|
+
this.prompt_kind = 'rename';
|
|
908
|
+
this.prompt_value = item.name;
|
|
909
|
+
this.prompt_error = '';
|
|
910
|
+
this.prompt_busy = false;
|
|
911
|
+
}
|
|
912
|
+
close_prompt() {
|
|
913
|
+
if (this.prompt_busy) {
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
this.prompt_kind = null;
|
|
917
|
+
this.prompt_value = '';
|
|
918
|
+
this.prompt_error = '';
|
|
919
|
+
this.promptInputEl = undefined;
|
|
920
|
+
}
|
|
921
|
+
async submit_prompt() {
|
|
922
|
+
if (this.prompt_busy || !this.session_id) {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
const kind = this.prompt_kind;
|
|
926
|
+
const name = this.prompt_value.trim();
|
|
927
|
+
const invalid = this.invalid_name(name);
|
|
928
|
+
if (invalid) {
|
|
929
|
+
this.prompt_error = invalid;
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const target = this.selected_item;
|
|
933
|
+
if (kind === 'rename' && target && name === target.name) {
|
|
934
|
+
this.close_prompt();
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
this.prompt_busy = true;
|
|
938
|
+
this.prompt_error = '';
|
|
939
|
+
this.show_error = false;
|
|
940
|
+
try {
|
|
941
|
+
if (kind === 'mkdir') {
|
|
942
|
+
const path = this.join_path(this.current_dir, name);
|
|
943
|
+
this.status = `Creating ${name}...`;
|
|
944
|
+
await this.run_op('create the folder', (msgId) => this.channel.send_sftp_mkdir(this.nodeId, this.session_id, path, msgId));
|
|
764
945
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
this.
|
|
770
|
-
this.
|
|
771
|
-
this.
|
|
772
|
-
|
|
946
|
+
else if (kind === 'rename' && target) {
|
|
947
|
+
// `to` is a full path, so the same call would move the entry if
|
|
948
|
+
// the dialog ever offered a destination directory.
|
|
949
|
+
const from = this.item_path(target);
|
|
950
|
+
const to = this.join_path(target.path, name);
|
|
951
|
+
this.status = `Renaming ${target.name}...`;
|
|
952
|
+
await this.run_op('rename', (msgId) => this.channel.send_sftp_rename(this.nodeId, this.session_id, from, to, msgId));
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
this.prompt_busy = false;
|
|
956
|
+
this.close_prompt();
|
|
773
957
|
return;
|
|
774
958
|
}
|
|
775
|
-
|
|
776
|
-
|
|
959
|
+
this.prompt_busy = false;
|
|
960
|
+
this.prompt_kind = null;
|
|
961
|
+
this.prompt_value = '';
|
|
962
|
+
this.promptInputEl = undefined;
|
|
963
|
+
this.status = 'Connected';
|
|
964
|
+
this.refresh_directory();
|
|
965
|
+
}
|
|
966
|
+
catch (err) {
|
|
967
|
+
this.prompt_busy = false;
|
|
968
|
+
this.prompt_error = this.error_text(err);
|
|
969
|
+
this.status = 'Connected';
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
on_chmod_action(item, event) {
|
|
973
|
+
event.preventDefault();
|
|
974
|
+
event.stopPropagation();
|
|
975
|
+
if (!this.session_id) {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
this.selected_item = item;
|
|
979
|
+
this.chmod_target = item;
|
|
980
|
+
this.chmod_mode = (item.attributes.permissions ?? 0) & 0o7777;
|
|
981
|
+
this.chmod_error = '';
|
|
982
|
+
this.chmod_busy = false;
|
|
983
|
+
}
|
|
984
|
+
close_chmod() {
|
|
985
|
+
if (this.chmod_busy) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
this.chmod_target = null;
|
|
989
|
+
this.chmod_error = '';
|
|
990
|
+
}
|
|
991
|
+
toggle_chmod_bit(bit) {
|
|
992
|
+
if (this.chmod_busy) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
this.chmod_mode = (this.chmod_mode ^ bit) & 0o7777;
|
|
996
|
+
}
|
|
997
|
+
on_chmod_octal_input(value) {
|
|
998
|
+
const digits = value.trim();
|
|
999
|
+
if (!/^[0-7]{1,4}$/.test(digits)) {
|
|
1000
|
+
this.chmod_error = 'Enter up to four octal digits, 0-7.';
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
this.chmod_error = '';
|
|
1004
|
+
this.chmod_mode = parseInt(digits, 8) & 0o7777;
|
|
1005
|
+
}
|
|
1006
|
+
async submit_chmod() {
|
|
1007
|
+
const target = this.chmod_target;
|
|
1008
|
+
if (this.chmod_busy || !this.session_id || !target) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
const path = this.item_path(target);
|
|
1012
|
+
const mode = this.chmod_mode & 0o7777;
|
|
1013
|
+
this.chmod_busy = true;
|
|
1014
|
+
this.chmod_error = '';
|
|
1015
|
+
this.show_error = false;
|
|
1016
|
+
this.status = `Setting permissions on ${target.name}...`;
|
|
1017
|
+
try {
|
|
1018
|
+
await this.run_op('change permissions', (msgId) => this.channel.send_sftp_chmod(this.nodeId, this.session_id, path, mode, msgId));
|
|
1019
|
+
this.chmod_busy = false;
|
|
1020
|
+
this.chmod_target = null;
|
|
1021
|
+
this.status = 'Connected';
|
|
1022
|
+
this.refresh_directory();
|
|
1023
|
+
}
|
|
1024
|
+
catch (err) {
|
|
1025
|
+
this.chmod_busy = false;
|
|
1026
|
+
this.chmod_error = this.error_text(err);
|
|
1027
|
+
this.status = 'Connected';
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
async on_edit_action(item, event) {
|
|
1031
|
+
event.preventDefault();
|
|
1032
|
+
event.stopPropagation();
|
|
1033
|
+
if (!this.session_id || item.kind !== 'File') {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
const path = this.item_path(item);
|
|
1037
|
+
this.selected_item = item;
|
|
1038
|
+
this.show_editor = true;
|
|
1039
|
+
this.editorPath = path;
|
|
1040
|
+
this.editor_name = item.name;
|
|
1041
|
+
this.editor_text = '';
|
|
1042
|
+
this.editor_saved_text = '';
|
|
1043
|
+
this.editor_error = '';
|
|
1044
|
+
this.editor_confirm_discard = false;
|
|
1045
|
+
this.editor_loaded = false;
|
|
1046
|
+
this.editor_busy = 'loading';
|
|
1047
|
+
this.status = `Opening ${item.name}...`;
|
|
1048
|
+
try {
|
|
1049
|
+
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);
|
|
1050
|
+
if (answer.result !== 'FileContents') {
|
|
1051
|
+
throw new Error('The agent answered without any file contents.');
|
|
777
1052
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
1053
|
+
const text = this.decode_text(answer.contents instanceof Uint8Array ? answer.contents : new Uint8Array(answer.contents));
|
|
1054
|
+
this.editor_text = text;
|
|
1055
|
+
this.editor_saved_text = text;
|
|
1056
|
+
this.editor_loaded = true;
|
|
1057
|
+
this.editor_busy = '';
|
|
1058
|
+
this.status = 'Connected';
|
|
1059
|
+
}
|
|
1060
|
+
catch (err) {
|
|
1061
|
+
this.editor_busy = '';
|
|
1062
|
+
this.editor_error = this.error_text(err);
|
|
1063
|
+
this.status = 'Connected';
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Refuse binary rather than mangle it. A lossy decode looks fine on screen
|
|
1068
|
+
* and then writes replacement characters over the real bytes on save, so
|
|
1069
|
+
* anything that is not valid UTF-8 is sent to the download button instead.
|
|
1070
|
+
*/
|
|
1071
|
+
decode_text(bytes) {
|
|
1072
|
+
if (bytes.includes(0)) {
|
|
1073
|
+
throw new Error('This looks like a binary file. Download it instead of editing it here.');
|
|
1074
|
+
}
|
|
1075
|
+
try {
|
|
1076
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
1077
|
+
}
|
|
1078
|
+
catch {
|
|
1079
|
+
throw new Error('This file is not valid UTF-8. Download it instead of editing it here.');
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
editor_is_dirty() {
|
|
1083
|
+
return this.editor_loaded && this.editor_text !== this.editor_saved_text;
|
|
1084
|
+
}
|
|
1085
|
+
close_editor(force = false) {
|
|
1086
|
+
if (this.editor_busy === 'saving') {
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
if (!force && this.editor_is_dirty()) {
|
|
1090
|
+
this.editor_confirm_discard = true;
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
this.show_editor = false;
|
|
1094
|
+
this.editor_confirm_discard = false;
|
|
1095
|
+
this.editor_loaded = false;
|
|
1096
|
+
this.editorPath = '';
|
|
1097
|
+
this.editor_name = '';
|
|
1098
|
+
this.editor_text = '';
|
|
1099
|
+
this.editor_saved_text = '';
|
|
1100
|
+
this.editor_error = '';
|
|
1101
|
+
this.editor_busy = '';
|
|
1102
|
+
this.editorTextEl = undefined;
|
|
1103
|
+
}
|
|
1104
|
+
async save_editor() {
|
|
1105
|
+
if (this.editor_busy || !this.session_id || !this.editorPath) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const path = this.editorPath;
|
|
1109
|
+
const text = this.editor_text;
|
|
1110
|
+
this.editor_busy = 'saving';
|
|
1111
|
+
this.editor_error = '';
|
|
1112
|
+
this.show_error = false;
|
|
1113
|
+
this.status = `Saving ${this.editor_name}...`;
|
|
1114
|
+
try {
|
|
1115
|
+
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);
|
|
1116
|
+
this.editor_saved_text = text;
|
|
1117
|
+
this.editor_busy = '';
|
|
1118
|
+
this.status = 'Connected';
|
|
1119
|
+
this.refresh_directory();
|
|
1120
|
+
}
|
|
1121
|
+
catch (err) {
|
|
1122
|
+
this.editor_busy = '';
|
|
1123
|
+
this.editor_error = this.error_text(err);
|
|
1124
|
+
this.status = 'Connected';
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
toggle_sort(key) {
|
|
1128
|
+
if (this.sort_key === key) {
|
|
1129
|
+
this.sort_asc = !this.sort_asc;
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
this.sort_key = key;
|
|
1133
|
+
this.sort_asc = true;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Folders stay above files whichever way the sort runs: a listing that
|
|
1137
|
+
* scatters directories through the files is harder to scan, not more sorted.
|
|
1138
|
+
*/
|
|
1139
|
+
visible_listing() {
|
|
1140
|
+
const needle = this.filter.trim().toLowerCase();
|
|
1141
|
+
const rows = needle
|
|
1142
|
+
? this.listing.filter((item) => item.name.toLowerCase().includes(needle))
|
|
1143
|
+
: [...this.listing];
|
|
1144
|
+
const direction = this.sort_asc ? 1 : -1;
|
|
1145
|
+
return rows.sort((a, b) => {
|
|
1146
|
+
if (a.kind !== b.kind) {
|
|
1147
|
+
return a.kind === 'Folder' ? -1 : 1;
|
|
1148
|
+
}
|
|
1149
|
+
switch (this.sort_key) {
|
|
1150
|
+
case 'size':
|
|
1151
|
+
return direction * ((a.attributes.size ?? 0) - (b.attributes.size ?? 0));
|
|
1152
|
+
case 'modified':
|
|
1153
|
+
return direction * ((a.attributes.modified ?? 0) - (b.attributes.modified ?? 0));
|
|
1154
|
+
default:
|
|
1155
|
+
return direction * a.name.localeCompare(b.name, undefined, {
|
|
1156
|
+
numeric: true,
|
|
1157
|
+
sensitivity: 'base',
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
sort_indicator(key) {
|
|
1163
|
+
if (this.sort_key !== key) {
|
|
1164
|
+
return '';
|
|
1165
|
+
}
|
|
1166
|
+
return this.sort_asc ? ' \u25b2' : ' \u25bc';
|
|
1167
|
+
}
|
|
1168
|
+
/** Keyboard shortcuts, scoped to the file table so the page keeps its own. */
|
|
1169
|
+
on_listing_keydown(event) {
|
|
1170
|
+
if (this.prompt_kind || this.chmod_target || this.show_editor || this.show_delete_modal) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const item = this.selected_item;
|
|
1174
|
+
switch (event.key) {
|
|
1175
|
+
case 'Backspace':
|
|
1176
|
+
event.preventDefault();
|
|
1177
|
+
this.go_to_parent_directory();
|
|
1178
|
+
break;
|
|
1179
|
+
case 'F5':
|
|
1180
|
+
event.preventDefault();
|
|
1181
|
+
this.refresh_directory();
|
|
1182
|
+
break;
|
|
1183
|
+
case 'F2':
|
|
1184
|
+
if (item) {
|
|
1185
|
+
event.preventDefault();
|
|
1186
|
+
this.on_rename_action(item, event);
|
|
1187
|
+
}
|
|
1188
|
+
break;
|
|
1189
|
+
case 'Delete':
|
|
1190
|
+
if (item) {
|
|
1191
|
+
event.preventDefault();
|
|
1192
|
+
this.on_file_delete_action(item, event);
|
|
1193
|
+
}
|
|
1194
|
+
break;
|
|
1195
|
+
case 'Enter':
|
|
1196
|
+
if (item) {
|
|
1197
|
+
event.preventDefault();
|
|
1198
|
+
this.list_directory(item);
|
|
1199
|
+
}
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
on_modal_keydown(event, close) {
|
|
1204
|
+
if (event.key === 'Escape') {
|
|
1205
|
+
event.preventDefault();
|
|
1206
|
+
event.stopPropagation();
|
|
1207
|
+
close();
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
/** Focus a dialog's field as it appears, without re-focusing on every render. */
|
|
1211
|
+
focus_once(el, current, keep) {
|
|
1212
|
+
if (!el || el === current) {
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
keep(el);
|
|
1216
|
+
requestAnimationFrame(() => el.focus());
|
|
782
1217
|
}
|
|
783
1218
|
open_upload_picker() {
|
|
784
1219
|
this.uploadInputEl?.click();
|
|
@@ -825,7 +1260,7 @@ export class PhirepassSftpClient {
|
|
|
825
1260
|
this.selected_item = entry;
|
|
826
1261
|
return;
|
|
827
1262
|
}
|
|
828
|
-
const path =
|
|
1263
|
+
const path = this.item_path(entry);
|
|
829
1264
|
if (path === this.current_dir) {
|
|
830
1265
|
console.warn('Already in this directory. Ignoring click.');
|
|
831
1266
|
return;
|
|
@@ -910,18 +1345,20 @@ export class PhirepassSftpClient {
|
|
|
910
1345
|
return `${typeChar}${chars.join('')}`;
|
|
911
1346
|
}
|
|
912
1347
|
render() {
|
|
913
|
-
return (h(Host, { key: '
|
|
1348
|
+
return (h(Host, { key: '94f75760ff9d2f6e2852cdabd109f58bbdc21826', class: {
|
|
914
1349
|
'default': !this.max,
|
|
915
1350
|
'max': this.max,
|
|
916
|
-
} }, h("section", { key: '
|
|
917
|
-
h("header", { key: '
|
|
1351
|
+
} }, h("section", { key: '9d2b388a11fb9a4b1ccf8fac1d926c0451fcba3f', class: "listing" }, !this.hideHeader &&
|
|
1352
|
+
h("header", { key: '24e3f95b1ff48553e5e8bb150ee7d7ef60f74d73' }, h("section", { key: '1023558093761f93f32f58083b56f8385e6eecff', class: "title" }, h("img", { key: 'dbac57cd459cb6ebca477e85eb9fdeae51b9b8b2', src: svg, alt: "SFTP Client" }), h("div", { key: 'bab01697a1a84f05fbad8b15b75ba39962408c95', class: "text" }, h("div", { key: 'e3a29b907e3eef0e7240c13ee50d8e77ffd9a29c', class: "name" }, this.name), h("div", { key: 'ccdb117f874649914e4bc6fab0257d888a396ff5', class: "description" }, this.description))), h("section", { key: 'eda0da6fdca162f3414ba0802dad3088b00d9ab1', class: "actions" }, h("div", { key: 'e0882533b6e2512c0f8c074b031e17b53000413d', class: "action", onClick: () => this.toggle_max() }, h("img", { key: '18d6009f7e272537863034141ed22a30d7adcdb1', src: max, alt: "Maximize" })))), h("main", { key: 'fb9496e11a2d61d73052a735793931c6c262956a' }, this.show_navigation && h("nav", { key: 'be8098657ee5bd6335f3e37bb45c19818b3ed354', class: "navigation" }, h("div", { key: 'c689b18ab1c5ff8c2e06b050d9eb55253f064496', class: "breadcrumbs" }, this.breadcrumbs.map((crumb, index, breadcrumbs) => (h("span", { key: index, class: "breadcrumb-container" }, h("span", { key: index, onClick: () => this.list_breadcrumb(crumb.path), class: "breadcrumb" }, crumb.label), index < breadcrumbs.length - 1 && h("img", { class: "arrow", src: chevron }))))), h("section", { key: '8533b0cc60a39d5e43df3646487192d75d28eb95', class: "actions", "aria-label": "SFTP actions" }, h("input", { key: 'a7b98422554ee133af228b18297f03c805f138e5', 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 }), h("button", { key: '4ded4cb62772c4d00153c73df40f2d77946f392d', type: "button", class: "action", onClick: () => this.go_to_parent_directory(), title: "Go to parent directory", "aria-label": "Go to parent directory" }, h("img", { key: '7c56e8a47b0bd650525dce7d1b14440e7fa5dd05', src: go_up, alt: "Go up" })), h("button", { key: '5f3dbe6e7bd6dbcdd9f5d08e179b96de25ddfbe4', type: "button", class: "action", onClick: () => this.refresh_directory(), title: "Refresh", "aria-label": "Refresh" }, h("img", { key: 'fad82f885c47e8fff98fdc987888bdf28533a28d', src: refresh, alt: "Refresh" })), h("button", { key: '5d55e71fa8eb1f2ea1f75859eef44b5a87ece401', type: "button", class: "action", onClick: () => this.open_mkdir(), title: "New folder", "aria-label": "New folder" }, h("svg", { key: '58a5611574a4a862767416437d6488c3ba87a566', 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" }, h("path", { key: 'b2bedcd737a0709e0f8af29cbe955acc15477081', 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" }), h("line", { key: 'ef531e0af9df3b308d91590b15d6dfb57acbeee2', x1: "12", x2: "12", y1: "10", y2: "16" }), h("line", { key: '4b3fb7124f97bacf0e723e728a7ddeec3b534879', x1: "9", x2: "15", y1: "13", y2: "13" }))), h("button", { key: '824e0362e5a256c3848392280ea46a7f798be1c0', type: "button", class: "action", onClick: () => this.open_upload_picker(), title: "Upload", "aria-label": "Upload" }, h("img", { key: '9566d040fa2856e1a39db5d16f7c9ac93af319f7', src: upload, alt: "Upload" })), h("button", { key: '8f3cb1ca3f128af76d7bc33d162ead4d25df7459', type: "button", class: "action disconnect", onClick: () => this.disconnect_session(), title: "Disconnect", "aria-label": "Disconnect" }, "DISCONNECT"))), h("input", { key: '916c345c3163ccea404fe85da708d1e5a522c8ec', type: "file", ref: (el) => this.uploadInputEl = el, onChange: (event) => this.on_upload_selected(event), style: { display: 'none' } }), this.show_content && h("div", { key: 'c894bda7c9f05538e099335bae720c6ac032dc70', class: "content", tabindex: 0, onKeyDown: (event) => this.on_listing_keydown(event) }, h("table", { key: 'e6d162543c57e0805875d52f5de8060473023113' }, h("thead", { key: 'b32d8edc1cc63834dada7cd4a8a9fc0aa4e641ab' }, h("tr", { key: '7ef2d28ba557ab36689066b830534aa644cd100a' }, h("th", { key: '9ec3dc58c85915562618f6dfedb466e4d32d8627', class: "sortable", onClick: () => this.toggle_sort('name'), title: "Sort by name" }, "Name", this.sort_indicator('name')), h("th", { key: '75164784bfde44c0844b5ba1e790fd53476ac0e0', class: "sortable", onClick: () => this.toggle_sort('size'), title: "Sort by size" }, "Size", this.sort_indicator('size')), h("th", { key: 'f4dc607bb845ee940030cd631bfb07aefda9316e' }, "Permissions"), h("th", { key: '2bcbe63f98b2ec812ae0ba82e184cdc0fa1fdfe4' }, "Owner"), h("th", { key: '7f3933b4191b303b99cac3a999392ea700072735', class: "sortable", onClick: () => this.toggle_sort('modified'), title: "Sort by modified date" }, "Modified", this.sort_indicator('modified')), h("th", { key: '6fc772fcb7eb31cc2684e5f50c7e0b25fc3cb11a', class: "action-col", "aria-label": "Actions" }))), h("tbody", { key: '6a506bd214a34a2f4ae0e138b43226502e2cd283' }, this.visible_listing().map((item, index) => (h("tr", { key: index, class: {
|
|
918
1353
|
'selected': this.is_selected(item),
|
|
919
|
-
}, onClick: () => this.list_directory(item) }, h("td", null, item.kind === 'Folder' ? h("img", { class: "kind", src: folder, alt: "Folder" }) : h("img", { class: "kind", src: file, alt: "File" }), h("span", { class: `name ${item.kind.toLowerCase()}` }, item.name)), h("td", null, this.format_size(item.attributes.size)), h("td", null, this.format_permissions(item.attributes.permissions, item.kind)), h("td", null, item.attributes.user ?? '-'), h("td", null, new Date(item.attributes.modified * 1000).toLocaleString()), h("td", { class: "action-col" }, item.kind === 'File' &&
|
|
920
|
-
h("
|
|
921
|
-
h("
|
|
1354
|
+
}, onClick: () => this.list_directory(item) }, h("td", null, item.kind === 'Folder' ? h("img", { class: "kind", src: folder, alt: "Folder" }) : h("img", { class: "kind", src: file, alt: "File" }), h("span", { class: `name ${item.kind.toLowerCase()}` }, item.name)), h("td", null, item.kind === 'Folder' ? '-' : this.format_size(item.attributes.size)), h("td", null, this.format_permissions(item.attributes.permissions, item.kind)), h("td", null, item.attributes.user ?? '-'), h("td", null, new Date(item.attributes.modified * 1000).toLocaleString()), h("td", { class: "action-col" }, h("div", { class: "file-actions" }, item.kind === 'File' &&
|
|
1355
|
+
h("button", { type: "button", class: "file-action", onClick: (event) => this.on_edit_action(item, event), title: "Edit", "aria-label": `Edit ${item.name}` }, 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" }, h("path", { d: "M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" }), h("path", { d: "M18.5 2.5a2.12 2.12 0 0 1 3 3L12 15l-4 1 1-4Z" }))), item.kind === 'File' &&
|
|
1356
|
+
h("button", { type: "button", class: "file-action", onClick: (event) => this.on_file_row_action(item, event), title: "Download", "aria-label": `Download ${item.name}` }, 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" }, h("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }), h("polyline", { points: "7 10 12 15 17 10" }), h("line", { x1: "12", x2: "12", y1: "15", y2: "3" }))), h("button", { type: "button", class: "file-action", onClick: (event) => this.on_rename_action(item, event), title: "Rename", "aria-label": `Rename ${item.name}` }, 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" }, h("path", { d: "M12 20h9" }), h("path", { d: "M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z" }))), h("button", { type: "button", class: "file-action", onClick: (event) => this.on_chmod_action(item, event), title: "Permissions", "aria-label": `Change permissions on ${item.name}` }, 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" }, h("rect", { width: "18", height: "11", x: "3", y: "11", rx: "2", ry: "2" }), h("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" }))), h("button", { type: "button", class: "file-action delete", onClick: (event) => this.on_file_delete_action(item, event), title: "Delete", "aria-label": `Delete ${item.name}` }, 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" }, h("polyline", { points: "3 6 5 6 21 6" }), h("path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" }), h("path", { d: "M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6" }), h("line", { x1: "10", x2: "10", y1: "11", y2: "17" }), h("line", { x1: "14", x2: "14", y1: "11", y2: "17" })))))))), this.visible_listing().length === 0 &&
|
|
1357
|
+
h("tr", { key: 'b056d99b4df7c0217c0eeb925d7ab8b519456a5f', class: "empty" }, h("td", { key: '34a0f9f9e70827e64ea9843bd0263f258fc0c20a', colSpan: 6 }, this.filter ? `Nothing here matches "${this.filter}".` : 'This directory is empty.'))))), this.show_loader && h("div", { key: '980fd45f6af488bf86dbbf1211abe0ccb3422b81', class: "loader" }, "Loading..."), this.show_error && h("div", { key: '0c368db0fd65b63f64e40119ac474d74e7832b61', class: "error" }, this.error_message)), h("footer", { key: '71d8b999bca0fd0a9b3a224fa370f2953abf3b5f' }, h("section", { key: '911030d32f3e1fab2f0df0ab43b093626124395c', class: "status" }, this.status, this.selected_item && h("span", { key: '19d2607ce0761647eeda4b01fbea9f4a3ccc5885', class: "selected-item" }, this.selected_item.name)), h("section", { key: 'e6f3f2a1b3f8adf04eff1b77f2947e210302876f', class: "version" }, this.version ? `Version: ${this.version}` : ''))), this.show_login_screen &&
|
|
1358
|
+
h("section", { key: 'f08ce7f1182fffe42e7eb470e52d046095441234', class: {
|
|
922
1359
|
'creds': true,
|
|
923
1360
|
'blurred': this.show_login_screen,
|
|
924
|
-
} }, h("form", { key: '
|
|
1361
|
+
} }, h("form", { key: '0fbcaaf222d20a0c5a8769d7d9614135db0971bd', class: "auth", onSubmit: (event) => {
|
|
925
1362
|
const formData = new FormData(event.target);
|
|
926
1363
|
let username = undefined;
|
|
927
1364
|
if (this.show_login_screen_username) {
|
|
@@ -938,28 +1375,57 @@ export class PhirepassSftpClient {
|
|
|
938
1375
|
this.show_loader = true;
|
|
939
1376
|
event.stopPropagation();
|
|
940
1377
|
event.preventDefault();
|
|
941
|
-
} }, h("div", { key: '
|
|
942
|
-
h("div", { key: '
|
|
943
|
-
h("div", { key: '
|
|
944
|
-
h("section", { key: '
|
|
1378
|
+
} }, h("div", { key: '25af70a09ffe30493a8416f30b367402017b7ed0', class: "title" }, "SFTP Connection"), this.show_login_screen_username &&
|
|
1379
|
+
h("div", { key: '3f1064e4acfc3f599e22e9314a455db72fcfd6f2' }, h("label", { key: 'a353afd35a192e7b8f7f66d0168974a42921a17d', htmlFor: "username" }, "Username"), h("input", { key: 'bc36e4f51537a4070443f9a5a82910e48842cfec', autocorrect: "off", autocapitalize: "none", autoComplete: "off", id: "username", name: "username", type: "text", placeholder: "" })), this.show_login_screen_password &&
|
|
1380
|
+
h("div", { key: 'e7181272416bfc7928d8e714d9c3227b5d0c1f66' }, h("label", { key: 'd090c64f8179378cdef09bd6b9180f5707a1e43e', htmlFor: "password" }, "Password"), h("input", { key: '6359b22a3a2ba9c68c1d54ea07dae8b1c388d17a', autocorrect: "off", autocapitalize: "none", autoComplete: "off", id: "password", name: "password", type: "password", placeholder: "" })), h("div", { key: '778c3e57e389329fc12ad6bc90921d86aedd4e80' }, h("button", { key: 'ad7881537626c5242f4ff5f0ae267e4526589d0f', type: "submit" }, "Connect")))), this.show_upload_modal &&
|
|
1381
|
+
h("section", { key: '75ee6bf70138d1df39eae7559e1d5358af127858', class: {
|
|
945
1382
|
'upload-modal': true,
|
|
946
1383
|
'visible': this.show_upload_modal,
|
|
947
|
-
} }, h("div", { key: '
|
|
1384
|
+
} }, h("div", { key: '87ea253eb2044c1748c9feaf1daa9c684df429f8', class: "upload-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Upload progress" }, h("div", { key: '83c64dcfc0a59c0cc76b6d0223c8fd17346849fc', class: "title" }, "Uploading File"), h("div", { key: 'a71a0dec4cb9d75e0a4edc5612c41238d9729f1a', class: "file-name", title: this.upload_file_name }, this.upload_file_name), h("div", { key: '057c9ca8bdf18fbedd75dba33d35ef7336a1c097', class: "progress-track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": this.upload_progress }, h("div", { key: '7a503b29c32cc03f0491be389bd9a21b340838aa', class: "progress-fill", style: { width: `${this.upload_progress}%` } })), h("div", { key: 'a9b831b1548eecfcf21ad9d3d56a22cc6e3dae84', class: "progress-meta" }, h("div", { key: 'f5de7e9567ed5633bb81634add297faf24d55123', class: "progress-speed" }, this.upload_speed), h("div", { key: '0241bcc3c54afd1cd6e5bb802b8518bb45458659', class: "progress-value" }, this.format_percent(this.upload_progress))), h("button", { key: '354fb6fa81acf2e48eaa3ef897fb0d48d9435494', type: "button", class: {
|
|
948
1385
|
'cancel': true,
|
|
949
1386
|
'finished': this.upload_finished,
|
|
950
1387
|
}, onClick: () => this.cancel_upload() }, this.upload_finished ? 'Close' : 'Cancel'))), this.show_download_modal &&
|
|
951
|
-
h("section", { key: '
|
|
1388
|
+
h("section", { key: 'c5ae39a268ae33b4a623b576101fb524fb651a61', class: {
|
|
952
1389
|
'download-modal': true,
|
|
953
1390
|
'visible': this.show_download_modal,
|
|
954
|
-
} }, h("div", { key: '
|
|
1391
|
+
} }, h("div", { key: '38817aa1411005058ae56a9ab3acd66e7e031221', class: "download-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Download progress" }, h("div", { key: '96bebe6045d616d34b8aeef8876032fed887affc', class: "title" }, "Downloading File"), h("div", { key: '9669662ca9a60bbee2764ba1b92c7d43a20106af', class: "file-name", title: this.download_file_name }, this.download_file_name), h("div", { key: '66b7759dbec989dbd093a3635d312ffd78059356', class: "progress-track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": this.download_progress }, h("div", { key: '6ef0146a885aadfdf90de134ab8c4ad34b6a0a34', class: "progress-fill", style: { width: `${this.download_progress}%` } })), h("div", { key: '073bb8a2452515e0ea3678ed5da5e85a09df61ba', class: "progress-meta" }, h("div", { key: 'a401199826a0b028e26dc17155e056fa5b18b049', class: "progress-speed" }, this.download_speed), h("div", { key: 'a0c6170323d18d62107ea9c93405218773ef8f74', class: "progress-value" }, this.format_percent(this.download_progress))), h("button", { key: '9b8beb35c26a57b42c2e1b8b96eadb875e893668', type: "button", class: {
|
|
955
1392
|
'cancel': true,
|
|
956
1393
|
'finished': this.download_finished,
|
|
957
1394
|
}, onClick: () => this.cancel_download() }, this.download_finished ? 'Close' : 'Cancel'))), this.show_delete_modal &&
|
|
958
|
-
h("section", { key: '
|
|
1395
|
+
h("section", { key: 'acb147f3b2474a12948153992db4b105ec46c2e3', class: {
|
|
959
1396
|
'delete-modal': true,
|
|
960
1397
|
'visible': this.show_delete_modal,
|
|
961
|
-
} }, h("div", { key: '
|
|
962
|
-
|
|
1398
|
+
} }, h("div", { key: '1adb2b1ed0183ec136bfdaf63b4dfe880f919811', class: "delete-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Delete confirmation", tabindex: -1, onKeyDown: (event) => this.on_modal_keydown(event, () => this.cancel_delete()) }, h("div", { key: '2481008ad54e92f4abd82c8e2c36a52e34db0c7c', class: "title" }, this.delete_is_dir ? 'Delete Folder' : 'Delete File'), h("div", { key: 'a91a942f3b35b7886033146597bb1ff7b9998dc1', class: "message" }, this.delete_loading
|
|
1399
|
+
? (this.delete_recursive ? 'Deleting the folder and everything in it...' : 'Deleting...')
|
|
1400
|
+
: `Are you sure you want to delete this ${this.delete_is_dir ? 'folder' : 'file'}?`), h("div", { key: 'f218cfc2faa0843b7dc8715f96aff55986aeab15', class: "file-name", title: this.delete_file_name }, this.delete_file_name), this.delete_is_dir &&
|
|
1401
|
+
h("label", { key: '9477429e9d929c95f8173160ea3983034a3e3849', class: "checkline" }, h("input", { key: '6573ea9e9b7af1d6233ddf8328b152226b6957bb', type: "checkbox", checked: this.delete_recursive, disabled: this.delete_loading, onChange: (event) => this.delete_recursive = event.target.checked }), h("span", { key: '0e2f1fed38cd99272af527a4aebeb56afaaa1c0d' }, "Delete everything inside it too")), !this.delete_is_dir || this.delete_recursive ? null :
|
|
1402
|
+
h("div", { class: "hint" }, "Without this, the remote refuses a folder that is not empty."), this.delete_error && h("div", { key: '837a597c00932e82be2e713badba936dcefb8b40', class: "dialog-error" }, this.delete_error), this.delete_loading &&
|
|
1403
|
+
h("div", { key: '1e350abb9e5d93fff3a496797d5c53c3c2de1827', class: "delete-loader", "aria-hidden": "true" }, h("span", { key: '89ea233eba5a799e702944afb1c989e707497c77', class: "spinner" })), h("div", { key: '679d16bc9641e98c993bce468cf09a6cd06a345d', class: "modal-actions" }, h("button", { key: '2fbcf1783b8a6aeb6f9c7d3f20a8abf3ae68d816', type: "button", class: "btn secondary", onClick: () => this.cancel_delete(), disabled: this.delete_loading }, "Cancel"), h("button", { key: '00cb2afd0df514a36c7977e800007746e8c8e73d', type: "button", class: "btn destructive", onClick: () => this.confirm_delete(), disabled: this.delete_loading }, this.delete_loading ? 'Deleting...' : 'Delete')))), this.prompt_kind &&
|
|
1404
|
+
h("section", { key: '7ac274aaa8c19e6d77c3a0be9feb68630fccb84f', class: "prompt-modal visible" }, h("div", { key: 'b9f9099ae61a0b518491c32e3f6aef79c28a812f', 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()) }, h("div", { key: 'e837df12158553b576282957ba368caf977f4d2a', class: "title" }, this.prompt_kind === 'mkdir' ? 'New Folder' : 'Rename'), h("div", { key: '25b71e67724d98f50cb3d21722822bddf8bc2c4c', class: "message" }, this.prompt_kind === 'mkdir'
|
|
1405
|
+
? `Create a folder in ${this.current_dir}`
|
|
1406
|
+
: 'Give it a new name. Existing names are not overwritten.'), h("form", { key: '390328d2b0f27a1a315a2bc55ae520e907813068', onSubmit: (event) => { event.preventDefault(); event.stopPropagation(); void this.submit_prompt(); } }, h("input", { key: 'dc958cd778250116043d82f191c0f4fb2fcf1c91', 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 && h("div", { key: '588e3aa9ec1759e24404784164a83001f1da8bb8', class: "dialog-error" }, this.prompt_error), h("div", { key: '15850d8a366a2a5f87e9b10c0351d684c3c30f78', class: "modal-actions" }, h("button", { key: 'dbfb5831fd896fc711efe53cbfe8ed57af19a2e3', type: "button", class: "btn secondary", onClick: () => this.close_prompt(), disabled: this.prompt_busy }, "Cancel"), h("button", { key: '95c872e35e3f65f4a7f0893b45c4d258b082b020', type: "submit", class: "btn primary", disabled: this.prompt_busy }, this.prompt_busy ? 'Working...' : (this.prompt_kind === 'mkdir' ? 'Create' : 'Rename')))))), this.chmod_target &&
|
|
1407
|
+
h("section", { key: '52373d1f66e3db9da1d8bb3018788efbf19fc762', class: "prompt-modal visible" }, h("div", { key: '887b863eb1d41d99acebbe7abe19273b202bbed2', class: "prompt-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Change permissions", tabindex: -1, onKeyDown: (event) => this.on_modal_keydown(event, () => this.close_chmod()) }, h("div", { key: '8c686b15eb982779633720236d3e00559ed37edd', class: "title" }, "Permissions"), h("div", { key: 'af9b7c128bc8bf0072c9c52de052435b3f8a6574', class: "file-name", title: this.chmod_target.name }, this.chmod_target.name), h("table", { key: '996e04c071fb8bbde39a0c811d8beef052f311c5', class: "perm-grid" }, h("thead", { key: '767477a3d4aacfe75fa4fa0bdc762c6d3448cebb' }, h("tr", { key: '5198f4e64fa9903cfd0c5221cb9ab86d690253e3' }, h("th", { key: 'd6fb60c8407b19a61e0d215ca8a9a1daa228e98e', "aria-label": "Class" }), h("th", { key: '9c1d18a98cd7471f6bae9f1009a2425287f60ef7' }, "Read"), h("th", { key: '529584b9be0ac95104818e22b7cd515b9e0f79f8' }, "Write"), h("th", { key: '9402ec30094930c53822722c17dd126949c8705e' }, "Execute"))), h("tbody", { key: '6aae29e72101eab4f5191696d64d65db35361b95' }, [
|
|
1408
|
+
{ label: 'Owner', read: 0o400, write: 0o200, exec: 0o100 },
|
|
1409
|
+
{ label: 'Group', read: 0o040, write: 0o020, exec: 0o010 },
|
|
1410
|
+
{ label: 'Other', read: 0o004, write: 0o002, exec: 0o001 },
|
|
1411
|
+
].map((row) => (h("tr", { key: row.label }, h("th", { scope: "row" }, row.label), [row.read, row.write, row.exec].map((bit) => (h("td", { key: bit }, 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) }))))))))), h("div", { key: 'c429b0d2bff193da9b48a2802719b774899125f4', class: "perm-special" }, [
|
|
1412
|
+
{ label: 'setuid', bit: 0o4000 },
|
|
1413
|
+
{ label: 'setgid', bit: 0o2000 },
|
|
1414
|
+
{ label: 'sticky', bit: 0o1000 },
|
|
1415
|
+
].map((special) => (h("label", { key: special.label, class: "checkline" }, h("input", { type: "checkbox", disabled: this.chmod_busy, checked: (this.chmod_mode & special.bit) !== 0, onChange: () => this.toggle_chmod_bit(special.bit) }), h("span", null, special.label))))), h("div", { key: '8927030347b5a78bbc2d0c68963cfa4b50aafc7b', class: "perm-octal" }, h("label", { key: '23cab841c245e4efabbf2348d0b932e70084f15d', htmlFor: "chmod-octal" }, "Octal"), h("input", { key: '1db5c92a844e4458bd6b3be663d9d1c87d523cb1', 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) }), h("span", { key: '636db9e85c1e551e3f09882acddca4b5e00ddb3a', class: "perm-preview" }, this.format_permissions(this.chmod_mode, this.chmod_target.kind))), this.chmod_error && h("div", { key: '295b4b35efbabede3481ba87df67dd6c49d96cc4', class: "dialog-error" }, this.chmod_error), h("div", { key: 'c226a4e3bed1a0388ceed76813667012d1022a4b', class: "modal-actions" }, h("button", { key: '716e0e6c46cbdb72872200a3ce5041212b41c63a', type: "button", class: "btn secondary", onClick: () => this.close_chmod(), disabled: this.chmod_busy }, "Cancel"), h("button", { key: '3b579eccd182089b65047280a0a8523aa62e3c74', type: "button", class: "btn primary", onClick: () => void this.submit_chmod(), disabled: this.chmod_busy }, this.chmod_busy ? 'Applying...' : 'Apply')))), this.show_editor &&
|
|
1416
|
+
h("section", { key: 'c965bc02d104440f0e171a7ebbc3b63bf11b1ca7', class: "editor-modal visible" }, h("div", { key: '4796d6b8b79a6a1f486109005bac2f9f76c424d2', class: "editor-dialog", role: "dialog", "aria-modal": "true", "aria-label": `Editing ${this.editor_name}`, tabindex: -1, onKeyDown: (event) => {
|
|
1417
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 's') {
|
|
1418
|
+
event.preventDefault();
|
|
1419
|
+
void this.save_editor();
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
this.on_modal_keydown(event, () => this.close_editor());
|
|
1423
|
+
} }, h("div", { key: '9f5a55b46763e68b7a127b1b341a6a54e46628f4', class: "editor-head" }, h("div", { key: '59b7d4105a5a31e66c520ff0f809bdc59e700330', class: "title" }, this.editor_name, this.editor_is_dirty() ? ' *' : ''), h("button", { key: 'ee74ac43364b05393e3ddbffb40f291bd855a4f8', type: "button", class: "editor-close", onClick: () => this.close_editor(), "aria-label": "Close editor", disabled: this.editor_busy === 'saving' }, "x")), this.editor_busy === 'loading'
|
|
1424
|
+
? h("div", { class: "editor-loading" }, "Loading...")
|
|
1425
|
+
: 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 && h("div", { key: '9a6c47f21cdce7cc76ce3cb9c5ca12af7215004e', class: "dialog-error" }, this.editor_error), this.editor_confirm_discard &&
|
|
1426
|
+
h("div", { key: 'd445399441b1411d5f2607c1bed36551e8421b39', class: "dialog-error" }, "Unsaved changes. Close anyway?"), h("div", { key: '9a98131525346b0b818dc55f7f02d0be579a75c9', class: "modal-actions" }, this.editor_confirm_discard
|
|
1427
|
+
? h("button", { type: "button", class: "btn destructive", onClick: () => this.close_editor(true) }, "Discard")
|
|
1428
|
+
: h("button", { type: "button", class: "btn secondary", onClick: () => this.close_editor(), disabled: this.editor_busy === 'saving' }, "Close"), h("button", { key: '23cbe88de46ef76de09c02e54074606aec5aa3e8', type: "button", class: "btn primary", onClick: () => void this.save_editor(), disabled: !!this.editor_busy || !this.editor_is_dirty() }, this.editor_busy === 'saving' ? 'Saving...' : 'Save'))))));
|
|
963
1429
|
}
|
|
964
1430
|
static get is() { return "phirepass-sftp-client"; }
|
|
965
1431
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1222,7 +1688,29 @@ export class PhirepassSftpClient {
|
|
|
1222
1688
|
"download_finished": {},
|
|
1223
1689
|
"show_delete_modal": {},
|
|
1224
1690
|
"delete_file_name": {},
|
|
1225
|
-
"delete_loading": {}
|
|
1691
|
+
"delete_loading": {},
|
|
1692
|
+
"delete_is_dir": {},
|
|
1693
|
+
"delete_recursive": {},
|
|
1694
|
+
"delete_error": {},
|
|
1695
|
+
"prompt_kind": {},
|
|
1696
|
+
"prompt_value": {},
|
|
1697
|
+
"prompt_error": {},
|
|
1698
|
+
"prompt_busy": {},
|
|
1699
|
+
"chmod_target": {},
|
|
1700
|
+
"chmod_mode": {},
|
|
1701
|
+
"chmod_error": {},
|
|
1702
|
+
"chmod_busy": {},
|
|
1703
|
+
"show_editor": {},
|
|
1704
|
+
"editor_name": {},
|
|
1705
|
+
"editor_text": {},
|
|
1706
|
+
"editor_saved_text": {},
|
|
1707
|
+
"editor_busy": {},
|
|
1708
|
+
"editor_error": {},
|
|
1709
|
+
"editor_confirm_discard": {},
|
|
1710
|
+
"editor_loaded": {},
|
|
1711
|
+
"filter": {},
|
|
1712
|
+
"sort_key": {},
|
|
1713
|
+
"sort_asc": {}
|
|
1226
1714
|
};
|
|
1227
1715
|
}
|
|
1228
1716
|
static get events() {
|