phirepass-widgets 0.0.117 → 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 +1 -12
- package/dist/cjs/{index-DehquNXP.js → index-C3v5xmUo.js} +2 -74
- 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 +2 -2
- package/dist/cjs/{protocol-BjOgJZ9-.js → protocol-DCBMfc2u.js} +21 -277
- package/dist/collection/collection-manifest.json +0 -2
- 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-BinptKL7.js → index-BVOulYtW.js} +2 -74
- 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 +3 -3
- package/dist/esm/{protocol-BekUePpu.js → protocol-CsYQJXY2.js} +20 -276
- package/dist/phirepass-widgets/{p-9e6f9220.entry.js → p-7ea2fdbc.entry.js} +5 -5
- 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 +4 -18
- package/dist/cjs/phirepass-downloader_3.cjs.entry.js +0 -3823
- 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 -1466
- 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-B4kFfbHE.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 -3819
- package/dist/phirepass-widgets/p-6a192c8d.entry.js +0 -1
- package/dist/phirepass-widgets/p-BekUePpu.js +0 -1
- package/dist/phirepass-widgets/p-BinptKL7.js +0 -3
- package/dist/phirepass-widgets/p-fe1ce8da.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 -238
- 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
|
@@ -0,0 +1,1468 @@
|
|
|
1
|
+
import { r as registerInstance, c as createEvent, h, H as Host } from './index-BVOulYtW.js';
|
|
2
|
+
import { _ as __wbg_init, E as ErrorType, C as Channel, a as ConnectionState, P as ProtocolMessageType } from './protocol-CsYQJXY2.js';
|
|
3
|
+
|
|
4
|
+
const phirepassSftpClientLogoSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoNDYsIDE4NCwgMTM4KSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiCiAgICBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10ZXJtaW5hbCB3LTMuNSBoLTMuNSB0ZXh0LXByaW1hcnkiPgogICAgPHBvbHlsaW5lIHBvaW50cz0iNCAxNyAxMCAxMSA0IDUiPjwvcG9seWxpbmU+CiAgICA8bGluZSB4MT0iMTIiIHgyPSIyMCIgeTE9IjE5IiB5Mj0iMTkiPjwvbGluZT4KPC9zdmc+Cg==';
|
|
5
|
+
|
|
6
|
+
const phirepassSftpClientMaxSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTE1LCAxMjMsIDE0MCkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtbWF4aW1pemUyIHctMyBoLTMiPgogICAgPHBvbHlsaW5lIHBvaW50cz0iMTUgMyAyMSAzIDIxIDkiPjwvcG9seWxpbmU+CiAgICA8cG9seWxpbmUgcG9pbnRzPSI5IDIxIDMgMjEgMyAxNSI+PC9wb2x5bGluZT4KICAgIDxsaW5lIHgxPSIyMSIgeDI9IjE0IiB5MT0iMyIgeTI9IjEwIj48L2xpbmU+CiAgICA8bGluZSB4MT0iMyIgeDI9IjEwIiB5MT0iMjEiIHkyPSIxNCI+PC9saW5lPgo8L3N2Zz4K';
|
|
7
|
+
|
|
8
|
+
const phirepassSftpClientChevronSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogICAgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIKICAgIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWNoZXZyb24tcmlnaHQgdy0zIGgtMyB0ZXh0LW11dGVkLWZvcmVncm91bmQvNTAgc2hyaW5rLTAiPgogICAgPHBhdGggZD0ibTkgMTggNi02LTYtNiI+PC9wYXRoPgo8L3N2Zz4K';
|
|
9
|
+
|
|
10
|
+
const phirepassSftpClientFolderSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoNDYsIDE4NCwgMTM4KSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiCiAgICBjbGFzcz0ibHVjaWRlIGx1Y2lkZS1mb2xkZXIgdy0zLjUgaC0zLjUgdGV4dC1wcmltYXJ5IHNocmluay0wIj4KICAgIDxwYXRoCiAgICAgICAgZD0iTTIwIDIwYTIgMiAwIDAgMCAyLTJWOGEyIDIgMCAwIDAtMi0yaC03LjlhMiAyIDAgMCAxLTEuNjktLjlMOS42IDMuOUEyIDIgMCAwIDAgNy45MyAzSDRhMiAyIDAgMCAwLTIgMnYxM2EyIDIgMCAwIDAgMiAyWiI+PC9wYXRoPgo8L3N2Zz4K';
|
|
11
|
+
|
|
12
|
+
const phirepassSftpClientFileSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTE1LCAxMjMsIDE0MCkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtZmlsZSB3LTMuNSBoLTMuNSB0ZXh0LW11dGVkLWZvcmVncm91bmQgc2hyaW5rLTAiPgogICAgPHBhdGggZD0iTTE1IDJINmEyIDIgMCAwIDAtMiAydjE2YTIgMiAwIDAgMCAyIDJoMTJhMiAyIDAgMCAwIDItMlY3WiI+PC9wYXRoPgogICAgPHBhdGggZD0iTTE0IDJ2NGEyIDIgMCAwIDAgMiAyaDQiPjwvcGF0aD4KPC9zdmc+Cg==';
|
|
13
|
+
|
|
14
|
+
const phirepassSftpClientGoUpSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtYXJyb3ctdXAgdy0zLjUgaC0zLjUiPgogICAgPHBhdGggZD0ibTUgMTIgNy03IDcgNyI+PC9wYXRoPgogICAgPHBhdGggZD0iTTEyIDE5VjUiPjwvcGF0aD4KPC9zdmc+Cg==';
|
|
15
|
+
|
|
16
|
+
const phirepassSftpClientRefreshSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtcmVmcmVzaC1jdyB3LTMuNSBoLTMuNSI+CiAgICA8cGF0aCBkPSJNMyAxMmE5IDkgMCAwIDEgOS05IDkuNzUgOS43NSAwIDAgMSA2Ljc0IDIuNzRMMjEgOCI+PC9wYXRoPgogICAgPHBhdGggZD0iTTIxIDN2NWgtNSI+PC9wYXRoPgogICAgPHBhdGggZD0iTTIxIDEyYTkgOSAwIDAgMS05IDkgOS43NSA5Ljc1IDAgMCAxLTYuNzQtMi43NEwzIDE2Ij48L3BhdGg+CiAgICA8cGF0aCBkPSJNOCAxNkgzdjUiPjwvcGF0aD4KPC9zdmc+Cg==';
|
|
17
|
+
|
|
18
|
+
const phirepassSftpClientUploadSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoMTg5LCAyMTksIDIwOSkiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIgogICAgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtdXBsb2FkIHctMy41IGgtMy41Ij4KICAgIDxwYXRoIGQ9Ik0yMSAxNXY0YTIgMiAwIDAgMS0yIDJINWEyIDIgMCAwIDEtMi0ydi00Ij48L3BhdGg+CiAgICA8cG9seWxpbmUgcG9pbnRzPSIxNyA4IDEyIDMgNyA4Ij48L3BvbHlsaW5lPgogICAgPGxpbmUgeDE9IjEyIiB4Mj0iMTIiIHkxPSIzIiB5Mj0iMTUiPjwvbGluZT4KPC9zdmc+Cg==';
|
|
19
|
+
|
|
20
|
+
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}}`;
|
|
21
|
+
|
|
22
|
+
const PhirepassSftpClient = class {
|
|
23
|
+
constructor(hostRef) {
|
|
24
|
+
if (new.target === PhirepassSftpClient)
|
|
25
|
+
registerInstance(this, hostRef);
|
|
26
|
+
this.maximizeEvent = createEvent(this, "maximize");
|
|
27
|
+
this.connectionStateChanged = createEvent(this, "connectionStateChanged");
|
|
28
|
+
}
|
|
29
|
+
channel;
|
|
30
|
+
domReady = false;
|
|
31
|
+
runtimeReady = false;
|
|
32
|
+
connected = false;
|
|
33
|
+
uploadInputEl;
|
|
34
|
+
msgId = 1;
|
|
35
|
+
activeUploadToken = 0;
|
|
36
|
+
pendingUploadStarts = new Map();
|
|
37
|
+
pendingUploadAcks = new Map();
|
|
38
|
+
pendingDownloadStarts = new Map();
|
|
39
|
+
activeDownloads = new Map();
|
|
40
|
+
activeDownloadMsgId;
|
|
41
|
+
pendingOps = new Map();
|
|
42
|
+
promptInputEl;
|
|
43
|
+
editorPath = '';
|
|
44
|
+
editorTextEl;
|
|
45
|
+
// private inputMode: InputMode = InputMode.Default;
|
|
46
|
+
session_id;
|
|
47
|
+
// private usernameBuffer = "";
|
|
48
|
+
// private passwordBuffer = "";
|
|
49
|
+
name = 'SFTP';
|
|
50
|
+
description = 'Client';
|
|
51
|
+
hideHeader = false;
|
|
52
|
+
serverHost = "phirepass.com";
|
|
53
|
+
serverPort = 443;
|
|
54
|
+
allowInsecure = false;
|
|
55
|
+
heartbeatInterval = 30_000;
|
|
56
|
+
nodeId;
|
|
57
|
+
serviceId;
|
|
58
|
+
token;
|
|
59
|
+
onNodeIdChange(newValue, _oldValue) {
|
|
60
|
+
// Handle the change in node_id here
|
|
61
|
+
// console.log(`node_id changed from ${oldValue} to ${newValue}`);
|
|
62
|
+
// Always clear local session state and reset terminal view
|
|
63
|
+
this.reset_session_state();
|
|
64
|
+
// this.terminal.reset();
|
|
65
|
+
// Close existing comms if connected
|
|
66
|
+
if (this.channel && this.channel.is_connected()) {
|
|
67
|
+
this.close_comms();
|
|
68
|
+
}
|
|
69
|
+
// Open new comms for the updated node
|
|
70
|
+
if (newValue) {
|
|
71
|
+
this.open_comms();
|
|
72
|
+
this.channel.connect();
|
|
73
|
+
this.status = 'Connecting...';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
serverId;
|
|
77
|
+
/**
|
|
78
|
+
* Supplies the channel instead of a WebSocket to the server — for demos,
|
|
79
|
+
* screenshots and tests. A property only (a function cannot be an
|
|
80
|
+
* attribute); read once, when the widget connects. See `ChannelFactory`.
|
|
81
|
+
*/
|
|
82
|
+
channelFactory;
|
|
83
|
+
onServerIdChange(_newValue, _oldValue) {
|
|
84
|
+
this.onNodeIdChange(this.nodeId, this.nodeId);
|
|
85
|
+
}
|
|
86
|
+
maximizeEvent;
|
|
87
|
+
async maximize() {
|
|
88
|
+
this.max = !this.max;
|
|
89
|
+
}
|
|
90
|
+
async minimize() {
|
|
91
|
+
this.max = false;
|
|
92
|
+
}
|
|
93
|
+
connectionStateChanged;
|
|
94
|
+
max = false;
|
|
95
|
+
show_login_screen = false;
|
|
96
|
+
show_login_screen_username = false;
|
|
97
|
+
show_error = false;
|
|
98
|
+
error_message = '';
|
|
99
|
+
show_login_screen_password = false;
|
|
100
|
+
show_navigation = false;
|
|
101
|
+
breadcrumbs = [];
|
|
102
|
+
current_dir = '.';
|
|
103
|
+
listing = [];
|
|
104
|
+
show_content = false;
|
|
105
|
+
show_loader = false;
|
|
106
|
+
version = '';
|
|
107
|
+
status = 'Disconnected';
|
|
108
|
+
selected_item = null;
|
|
109
|
+
show_upload_modal = false;
|
|
110
|
+
upload_progress = 0;
|
|
111
|
+
upload_file_name = '';
|
|
112
|
+
upload_speed = '--';
|
|
113
|
+
upload_finished = false;
|
|
114
|
+
show_download_modal = false;
|
|
115
|
+
download_progress = 0;
|
|
116
|
+
download_file_name = '';
|
|
117
|
+
download_speed = '--';
|
|
118
|
+
download_finished = false;
|
|
119
|
+
show_delete_modal = false;
|
|
120
|
+
delete_file_name = '';
|
|
121
|
+
delete_loading = false;
|
|
122
|
+
delete_is_dir = false;
|
|
123
|
+
delete_recursive = false;
|
|
124
|
+
delete_error = '';
|
|
125
|
+
/** `mkdir` and `rename` share one dialog: both take a single name. */
|
|
126
|
+
prompt_kind = null;
|
|
127
|
+
prompt_value = '';
|
|
128
|
+
prompt_error = '';
|
|
129
|
+
prompt_busy = false;
|
|
130
|
+
chmod_target = null;
|
|
131
|
+
/** Permission bits under edit, masked to 0o7777. */
|
|
132
|
+
chmod_mode = 0;
|
|
133
|
+
chmod_error = '';
|
|
134
|
+
chmod_busy = false;
|
|
135
|
+
show_editor = false;
|
|
136
|
+
editor_name = '';
|
|
137
|
+
editor_text = '';
|
|
138
|
+
/** What is on the remote, so the dialog knows whether it has edits. */
|
|
139
|
+
editor_saved_text = '';
|
|
140
|
+
editor_busy = '';
|
|
141
|
+
editor_error = '';
|
|
142
|
+
editor_confirm_discard = false;
|
|
143
|
+
/** False until the file's contents are in hand, so a failed open is read-only. */
|
|
144
|
+
editor_loaded = false;
|
|
145
|
+
filter = '';
|
|
146
|
+
sort_key = 'name';
|
|
147
|
+
sort_asc = true;
|
|
148
|
+
toggle_max() {
|
|
149
|
+
this.maximizeEvent?.emit(!this.max);
|
|
150
|
+
}
|
|
151
|
+
async connectedCallback() {
|
|
152
|
+
if (!this.channelFactory) {
|
|
153
|
+
await __wbg_init();
|
|
154
|
+
}
|
|
155
|
+
// this.setup_terminal();
|
|
156
|
+
this.open_comms();
|
|
157
|
+
this.runtimeReady = true;
|
|
158
|
+
if (!this.nodeId) {
|
|
159
|
+
console.warn('Prop node_id is not set. Cannot connect to terminal.');
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.try_connect();
|
|
163
|
+
}
|
|
164
|
+
componentDidLoad() {
|
|
165
|
+
this.domReady = true;
|
|
166
|
+
this.try_connect();
|
|
167
|
+
}
|
|
168
|
+
async disconnectedCallback() {
|
|
169
|
+
// if (this.resizeDebounceHandle) {
|
|
170
|
+
// clearTimeout(this.resizeDebounceHandle);
|
|
171
|
+
// this.resizeDebounceHandle = undefined;
|
|
172
|
+
// }
|
|
173
|
+
//
|
|
174
|
+
// if (this.resizeObserver) {
|
|
175
|
+
// this.resizeObserver.disconnect();
|
|
176
|
+
// }
|
|
177
|
+
this.connected = false;
|
|
178
|
+
this.domReady = false;
|
|
179
|
+
this.runtimeReady = false;
|
|
180
|
+
this.cancel_active_upload();
|
|
181
|
+
this.cancel_active_download();
|
|
182
|
+
this.clear_pending_operations();
|
|
183
|
+
this.close_comms();
|
|
184
|
+
// this.destroy_terminal();
|
|
185
|
+
}
|
|
186
|
+
next_msg_id() {
|
|
187
|
+
const id = this.msgId;
|
|
188
|
+
this.msgId += 1;
|
|
189
|
+
return id;
|
|
190
|
+
}
|
|
191
|
+
clear_pending_operations() {
|
|
192
|
+
this.pendingUploadStarts.forEach((pending) => {
|
|
193
|
+
window.clearTimeout(pending.timeout);
|
|
194
|
+
pending.reject(new Error('Upload start aborted'));
|
|
195
|
+
});
|
|
196
|
+
this.pendingUploadStarts.clear();
|
|
197
|
+
this.pendingUploadAcks.forEach((pending) => {
|
|
198
|
+
window.clearTimeout(pending.timeout);
|
|
199
|
+
pending.reject(new Error('Upload chunk aborted'));
|
|
200
|
+
});
|
|
201
|
+
this.pendingUploadAcks.clear();
|
|
202
|
+
this.pendingDownloadStarts.forEach((pending) => {
|
|
203
|
+
window.clearTimeout(pending.timeout);
|
|
204
|
+
pending.reject(new Error('Download start aborted'));
|
|
205
|
+
});
|
|
206
|
+
this.pendingDownloadStarts.clear();
|
|
207
|
+
this.pendingOps.forEach((pending) => {
|
|
208
|
+
window.clearTimeout(pending.timeout);
|
|
209
|
+
pending.reject(new Error(`Could not ${pending.verb}: the session ended.`));
|
|
210
|
+
});
|
|
211
|
+
this.pendingOps.clear();
|
|
212
|
+
this.activeDownloads.clear();
|
|
213
|
+
}
|
|
214
|
+
cancel_active_upload() {
|
|
215
|
+
this.activeUploadToken += 1;
|
|
216
|
+
this.upload_progress = 0;
|
|
217
|
+
this.upload_finished = false;
|
|
218
|
+
this.upload_speed = '--';
|
|
219
|
+
}
|
|
220
|
+
cancel_active_download() {
|
|
221
|
+
if (this.activeDownloadMsgId !== undefined) {
|
|
222
|
+
this.activeDownloads.delete(this.activeDownloadMsgId);
|
|
223
|
+
}
|
|
224
|
+
this.activeDownloadMsgId = undefined;
|
|
225
|
+
this.download_progress = 0;
|
|
226
|
+
this.download_finished = false;
|
|
227
|
+
this.download_speed = '--';
|
|
228
|
+
}
|
|
229
|
+
format_duration(seconds) {
|
|
230
|
+
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
231
|
+
return '--';
|
|
232
|
+
}
|
|
233
|
+
if (seconds < 60) {
|
|
234
|
+
return `${seconds.toFixed(0)}s`;
|
|
235
|
+
}
|
|
236
|
+
const minutes = Math.floor(seconds / 60);
|
|
237
|
+
const remainderSeconds = Math.floor(seconds % 60);
|
|
238
|
+
if (minutes < 60) {
|
|
239
|
+
return `${minutes}m ${remainderSeconds}s`;
|
|
240
|
+
}
|
|
241
|
+
const hours = Math.floor(minutes / 60);
|
|
242
|
+
const remainderMinutes = minutes % 60;
|
|
243
|
+
return `${hours}h ${remainderMinutes}m`;
|
|
244
|
+
}
|
|
245
|
+
format_percent(value) {
|
|
246
|
+
const safe = Number.isFinite(value) ? value : 0;
|
|
247
|
+
return `${safe.toFixed(2)}%`;
|
|
248
|
+
}
|
|
249
|
+
format_transfer_rate(bytesPerSecond) {
|
|
250
|
+
if (!Number.isFinite(bytesPerSecond) || bytesPerSecond <= 0) {
|
|
251
|
+
return '--';
|
|
252
|
+
}
|
|
253
|
+
return `${this.format_size(bytesPerSecond)}/s`;
|
|
254
|
+
}
|
|
255
|
+
update_upload_progress(uploadedBytes, totalBytes, startTime) {
|
|
256
|
+
const progress = totalBytes > 0 ? (uploadedBytes / totalBytes) * 100 : 0;
|
|
257
|
+
this.upload_progress = Math.max(0, Math.min(100, progress));
|
|
258
|
+
if (uploadedBytes >= totalBytes) {
|
|
259
|
+
this.upload_finished = true;
|
|
260
|
+
this.upload_speed = '--';
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const elapsedSeconds = (performance.now() - startTime) / 1000;
|
|
264
|
+
const speed = elapsedSeconds > 0 ? uploadedBytes / elapsedSeconds : 0;
|
|
265
|
+
this.upload_speed = this.format_transfer_rate(speed);
|
|
266
|
+
const remaining = totalBytes - uploadedBytes;
|
|
267
|
+
const eta = speed > 0 ? remaining / speed : NaN;
|
|
268
|
+
this.status = `Uploading ${this.format_size(uploadedBytes)} / ${this.format_size(totalBytes)} (ETA ${this.format_duration(eta)})`;
|
|
269
|
+
}
|
|
270
|
+
update_download_progress(receivedBytes, totalBytes, startTime) {
|
|
271
|
+
const progress = totalBytes > 0 ? (receivedBytes / totalBytes) * 100 : 0;
|
|
272
|
+
this.download_progress = Math.max(0, Math.min(100, progress));
|
|
273
|
+
if (receivedBytes >= totalBytes) {
|
|
274
|
+
this.download_finished = true;
|
|
275
|
+
this.download_speed = '--';
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const elapsedSeconds = (Date.now() - startTime) / 1000;
|
|
279
|
+
const speed = elapsedSeconds > 0 ? receivedBytes / elapsedSeconds : 0;
|
|
280
|
+
this.download_speed = this.format_transfer_rate(speed);
|
|
281
|
+
const remaining = totalBytes - receivedBytes;
|
|
282
|
+
const eta = speed > 0 ? remaining / speed : NaN;
|
|
283
|
+
this.status = `Downloading ${this.format_size(receivedBytes)} / ${this.format_size(totalBytes)} (ETA ${this.format_duration(eta)})`;
|
|
284
|
+
}
|
|
285
|
+
connect() {
|
|
286
|
+
this.connected = true;
|
|
287
|
+
this.channel.connect();
|
|
288
|
+
this.status = 'Connecting...';
|
|
289
|
+
// const container = this.containerEl;
|
|
290
|
+
// console.log('Attempting to connect terminal to container:', container);
|
|
291
|
+
// if (container) {
|
|
292
|
+
// this.terminal.open(container);
|
|
293
|
+
// console.log('Terminal opened in container');
|
|
294
|
+
// this.connected = true;
|
|
295
|
+
// this.fit_terminal_safely();
|
|
296
|
+
// this.terminal.focus();
|
|
297
|
+
// this.terminal.onData(this.handle_terminal_data.bind(this));
|
|
298
|
+
// this.channel.connect();
|
|
299
|
+
// this.setup_resize_observer();
|
|
300
|
+
// console.log('Terminal connected and ready');
|
|
301
|
+
// }
|
|
302
|
+
}
|
|
303
|
+
try_connect() {
|
|
304
|
+
if (this.connected || !this.domReady || !this.runtimeReady) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (!this.channel) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
this.connect();
|
|
311
|
+
}
|
|
312
|
+
create_web_socket_endpoint() {
|
|
313
|
+
const protocol = this.allowInsecure ? 'ws' : 'wss';
|
|
314
|
+
if (!this.allowInsecure && this.serverPort === 443) {
|
|
315
|
+
return `${protocol}://${this.serverHost}`;
|
|
316
|
+
}
|
|
317
|
+
if (this.allowInsecure && this.serverPort === 80) {
|
|
318
|
+
return `${protocol}://${this.serverHost}`;
|
|
319
|
+
}
|
|
320
|
+
return `${protocol}://${this.serverHost}:${this.serverPort}`;
|
|
321
|
+
}
|
|
322
|
+
handle_error(error) {
|
|
323
|
+
if (error.msg_id !== undefined) {
|
|
324
|
+
const pendingUploadStart = this.pendingUploadStarts.get(error.msg_id);
|
|
325
|
+
if (pendingUploadStart) {
|
|
326
|
+
window.clearTimeout(pendingUploadStart.timeout);
|
|
327
|
+
pendingUploadStart.reject(new Error(error.message || 'Upload start failed'));
|
|
328
|
+
this.pendingUploadStarts.delete(error.msg_id);
|
|
329
|
+
}
|
|
330
|
+
const pendingDownloadStart = this.pendingDownloadStarts.get(error.msg_id);
|
|
331
|
+
if (pendingDownloadStart) {
|
|
332
|
+
window.clearTimeout(pendingDownloadStart.timeout);
|
|
333
|
+
pendingDownloadStart.reject(new Error(error.message || 'Download start failed'));
|
|
334
|
+
this.pendingDownloadStarts.delete(error.msg_id);
|
|
335
|
+
}
|
|
336
|
+
if (this.activeDownloads.has(error.msg_id)) {
|
|
337
|
+
this.activeDownloads.delete(error.msg_id);
|
|
338
|
+
if (this.activeDownloadMsgId === error.msg_id) {
|
|
339
|
+
this.activeDownloadMsgId = undefined;
|
|
340
|
+
}
|
|
341
|
+
this.download_finished = false;
|
|
342
|
+
}
|
|
343
|
+
const pendingOp = this.pendingOps.get(error.msg_id);
|
|
344
|
+
if (pendingOp) {
|
|
345
|
+
window.clearTimeout(pendingOp.timeout);
|
|
346
|
+
this.pendingOps.delete(error.msg_id);
|
|
347
|
+
pendingOp.reject(new Error(error.message || `Could not ${pendingOp.verb}.`));
|
|
348
|
+
// The caller puts this message in the dialog the user is
|
|
349
|
+
// looking at. Raising the page-level banner as well would say
|
|
350
|
+
// the same thing twice, in the place they are not looking.
|
|
351
|
+
this.show_loader = false;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
switch (error.kind) {
|
|
356
|
+
case ErrorType.Generic:
|
|
357
|
+
case ErrorType.Authentication:
|
|
358
|
+
this.error_message = error.message || 'An unknown error occurred.';
|
|
359
|
+
this.show_error = true;
|
|
360
|
+
break;
|
|
361
|
+
case ErrorType.RequiresUsername:
|
|
362
|
+
this.show_login_screen_username = true;
|
|
363
|
+
this.show_login_screen_password = false;
|
|
364
|
+
this.show_login_screen = true;
|
|
365
|
+
break;
|
|
366
|
+
case ErrorType.RequiresPassword:
|
|
367
|
+
this.show_login_screen_username = false;
|
|
368
|
+
this.show_login_screen_password = true;
|
|
369
|
+
this.show_login_screen = true;
|
|
370
|
+
break;
|
|
371
|
+
case ErrorType.RequiresUsernamePassword:
|
|
372
|
+
this.show_login_screen_username = true;
|
|
373
|
+
this.show_login_screen_password = true;
|
|
374
|
+
this.show_login_screen = true;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
setTimeout(() => {
|
|
378
|
+
this.show_loader = false;
|
|
379
|
+
}, 1_000);
|
|
380
|
+
}
|
|
381
|
+
handle_auth_success(auth) {
|
|
382
|
+
this.clear_creds_buffer();
|
|
383
|
+
this.version = auth.version;
|
|
384
|
+
this.channel.start_heartbeat(this.heartbeatInterval <= 15_000 ? 30_000 : this.heartbeatInterval);
|
|
385
|
+
this.channel.open_sftp_tunnel(this.nodeId, this.serviceId);
|
|
386
|
+
this.status = 'Connected';
|
|
387
|
+
}
|
|
388
|
+
handle_tunnel_opened(web) {
|
|
389
|
+
this.session_id = web.sid;
|
|
390
|
+
// this.terminal.reset();
|
|
391
|
+
// this.fit_terminal_safely();
|
|
392
|
+
// this.send_ssh_terminal_resize();
|
|
393
|
+
this.channel.send_sftp_list_data(this.nodeId, this.session_id, this.current_dir);
|
|
394
|
+
}
|
|
395
|
+
handle_sftp_list_items(web) {
|
|
396
|
+
setTimeout(() => {
|
|
397
|
+
this.show_loader = false;
|
|
398
|
+
}, 500);
|
|
399
|
+
// A filter is about the directory you typed it in; carrying it into
|
|
400
|
+
// the next one hides most of what you just navigated to.
|
|
401
|
+
if (web.path !== this.current_dir) {
|
|
402
|
+
this.filter = '';
|
|
403
|
+
}
|
|
404
|
+
this.listing = web.dir.items;
|
|
405
|
+
this.current_dir = web.path;
|
|
406
|
+
this.breadcrumbs = web.path.split('/').map((path, index, arr) => {
|
|
407
|
+
if (path === '' && index === 0) {
|
|
408
|
+
return { label: '/', path: '/' };
|
|
409
|
+
}
|
|
410
|
+
return { label: path, path: arr.slice(0, index + 1).join('/') };
|
|
411
|
+
});
|
|
412
|
+
this.show_content = true;
|
|
413
|
+
this.show_navigation = true;
|
|
414
|
+
console.log('Received SFTP list items:', web);
|
|
415
|
+
}
|
|
416
|
+
handle_upload_start_response(web) {
|
|
417
|
+
if (web.msg_id === undefined) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const pending = this.pendingUploadStarts.get(web.msg_id);
|
|
421
|
+
if (!pending) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
window.clearTimeout(pending.timeout);
|
|
425
|
+
pending.resolve(web.response.upload_id);
|
|
426
|
+
this.pendingUploadStarts.delete(web.msg_id);
|
|
427
|
+
}
|
|
428
|
+
handle_upload_chunk_ack(web) {
|
|
429
|
+
const key = `${web.upload_id}_${web.chunk_index}`;
|
|
430
|
+
const pending = this.pendingUploadAcks.get(key);
|
|
431
|
+
if (!pending) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
window.clearTimeout(pending.timeout);
|
|
435
|
+
pending.resolve();
|
|
436
|
+
this.pendingUploadAcks.delete(key);
|
|
437
|
+
}
|
|
438
|
+
handle_download_start_response(web) {
|
|
439
|
+
if (web.msg_id === undefined) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const pending = this.pendingDownloadStarts.get(web.msg_id);
|
|
443
|
+
if (!pending) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
window.clearTimeout(pending.timeout);
|
|
447
|
+
pending.resolve({
|
|
448
|
+
download_id: web.response.download_id,
|
|
449
|
+
total_size: web.response.total_size,
|
|
450
|
+
total_chunks: web.response.total_chunks,
|
|
451
|
+
});
|
|
452
|
+
this.pendingDownloadStarts.delete(web.msg_id);
|
|
453
|
+
}
|
|
454
|
+
finalize_download(msgId) {
|
|
455
|
+
const download = this.activeDownloads.get(msgId);
|
|
456
|
+
if (!download) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const sortedChunks = Array.from(download.chunks.entries())
|
|
460
|
+
.sort((a, b) => a[0] - b[0])
|
|
461
|
+
.map(([, data]) => data);
|
|
462
|
+
// Normalize to fresh ArrayBuffer-backed views for BlobPart compatibility.
|
|
463
|
+
const blobParts = sortedChunks.map((chunk) => new Uint8Array(chunk));
|
|
464
|
+
const blob = new Blob(blobParts, { type: 'application/octet-stream' });
|
|
465
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
466
|
+
const anchor = document.createElement('a');
|
|
467
|
+
anchor.href = objectUrl;
|
|
468
|
+
anchor.download = download.filename;
|
|
469
|
+
document.body.appendChild(anchor);
|
|
470
|
+
anchor.click();
|
|
471
|
+
document.body.removeChild(anchor);
|
|
472
|
+
URL.revokeObjectURL(objectUrl);
|
|
473
|
+
this.activeDownloads.delete(msgId);
|
|
474
|
+
if (this.activeDownloadMsgId === msgId) {
|
|
475
|
+
this.activeDownloadMsgId = undefined;
|
|
476
|
+
}
|
|
477
|
+
this.download_finished = true;
|
|
478
|
+
this.status = 'Connected';
|
|
479
|
+
}
|
|
480
|
+
handle_download_chunk(web) {
|
|
481
|
+
if (web.msg_id === undefined) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const download = this.activeDownloads.get(web.msg_id);
|
|
485
|
+
if (!download || !this.session_id) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const chunkData = new Uint8Array(web.chunk.data);
|
|
489
|
+
download.chunks.set(web.chunk.chunk_index, chunkData);
|
|
490
|
+
const receivedBytes = Array.from(download.chunks.values()).reduce((sum, data) => sum + data.length, 0);
|
|
491
|
+
this.update_download_progress(receivedBytes, download.total_size, download.startTime);
|
|
492
|
+
// Pipeline ACK: advance the agent's sliding window so it can push the next
|
|
493
|
+
// batch of chunks without waiting for an explicit per-chunk request.
|
|
494
|
+
this.channel.send_sftp_download_ack(this.nodeId, this.session_id, download.download_id, web.chunk.chunk_index);
|
|
495
|
+
if (download.chunks.size >= download.total_chunks) {
|
|
496
|
+
this.finalize_download(web.msg_id);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
async start_download(item) {
|
|
500
|
+
if (!this.session_id) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
this.selected_item = item;
|
|
504
|
+
this.download_file_name = item.name;
|
|
505
|
+
this.download_progress = 0;
|
|
506
|
+
this.download_finished = false;
|
|
507
|
+
this.download_speed = '--';
|
|
508
|
+
this.show_download_modal = true;
|
|
509
|
+
this.show_error = false;
|
|
510
|
+
const msgId = this.next_msg_id();
|
|
511
|
+
this.activeDownloadMsgId = msgId;
|
|
512
|
+
this.activeDownloads.set(msgId, {
|
|
513
|
+
filename: item.name,
|
|
514
|
+
chunks: new Map(),
|
|
515
|
+
total_chunks: 0,
|
|
516
|
+
total_size: 0,
|
|
517
|
+
download_id: 0,
|
|
518
|
+
startTime: Date.now(),
|
|
519
|
+
});
|
|
520
|
+
const downloadStart = new Promise((resolve, reject) => {
|
|
521
|
+
const timeout = window.setTimeout(() => {
|
|
522
|
+
this.pendingDownloadStarts.delete(msgId);
|
|
523
|
+
reject(new Error('Download start timeout'));
|
|
524
|
+
}, 10_000);
|
|
525
|
+
this.pendingDownloadStarts.set(msgId, {
|
|
526
|
+
timeout,
|
|
527
|
+
resolve,
|
|
528
|
+
reject,
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
try {
|
|
532
|
+
this.channel.send_sftp_download_start(this.nodeId, this.session_id, item.path, item.name, msgId);
|
|
533
|
+
const { download_id, total_chunks, total_size } = await downloadStart;
|
|
534
|
+
const download = this.activeDownloads.get(msgId);
|
|
535
|
+
if (!download) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
download.download_id = download_id;
|
|
539
|
+
download.total_chunks = total_chunks;
|
|
540
|
+
download.total_size = total_size;
|
|
541
|
+
// Pipelined: agent pushes chunks immediately after SFTPDownloadStartResponse;
|
|
542
|
+
// no explicit per-chunk request is needed to start the flow.
|
|
543
|
+
}
|
|
544
|
+
catch (err) {
|
|
545
|
+
this.activeDownloads.delete(msgId);
|
|
546
|
+
if (this.activeDownloadMsgId === msgId) {
|
|
547
|
+
this.activeDownloadMsgId = undefined;
|
|
548
|
+
}
|
|
549
|
+
this.show_error = true;
|
|
550
|
+
this.error_message = err instanceof Error ? err.message : 'Failed to start download';
|
|
551
|
+
this.cancel_download();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
async upload_file(fileToUpload) {
|
|
555
|
+
if (!this.session_id) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const uploadToken = this.activeUploadToken + 1;
|
|
559
|
+
this.activeUploadToken = uploadToken;
|
|
560
|
+
this.upload_file_name = fileToUpload.name;
|
|
561
|
+
this.upload_progress = 0;
|
|
562
|
+
this.upload_finished = false;
|
|
563
|
+
this.upload_speed = '--';
|
|
564
|
+
this.show_upload_modal = true;
|
|
565
|
+
this.show_error = false;
|
|
566
|
+
this.status = 'Uploading...';
|
|
567
|
+
const chunkSize = 64 * 1024;
|
|
568
|
+
const totalChunks = Math.max(1, Math.ceil(fileToUpload.size / chunkSize));
|
|
569
|
+
const msgId = this.next_msg_id();
|
|
570
|
+
const uploadStart = new Promise((resolve, reject) => {
|
|
571
|
+
const timeout = window.setTimeout(() => {
|
|
572
|
+
this.pendingUploadStarts.delete(msgId);
|
|
573
|
+
reject(new Error('Upload start timeout'));
|
|
574
|
+
}, 10_000);
|
|
575
|
+
this.pendingUploadStarts.set(msgId, {
|
|
576
|
+
timeout,
|
|
577
|
+
resolve,
|
|
578
|
+
reject,
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
try {
|
|
582
|
+
this.channel.send_sftp_upload_start(this.nodeId, this.session_id, fileToUpload.name, this.current_dir, totalChunks, BigInt(fileToUpload.size), msgId);
|
|
583
|
+
const uploadId = await uploadStart;
|
|
584
|
+
let uploadedBytes = 0;
|
|
585
|
+
const startedAt = performance.now();
|
|
586
|
+
for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex += 1) {
|
|
587
|
+
if (uploadToken !== this.activeUploadToken) {
|
|
588
|
+
throw new Error('Upload cancelled');
|
|
589
|
+
}
|
|
590
|
+
const start = chunkIndex * chunkSize;
|
|
591
|
+
const end = Math.min(start + chunkSize, fileToUpload.size);
|
|
592
|
+
const chunkBuffer = new Uint8Array(await fileToUpload.slice(start, end).arrayBuffer());
|
|
593
|
+
await new Promise((resolve, reject) => {
|
|
594
|
+
const key = `${uploadId}_${chunkIndex}`;
|
|
595
|
+
const timeout = window.setTimeout(() => {
|
|
596
|
+
this.pendingUploadAcks.delete(key);
|
|
597
|
+
reject(new Error(`Upload chunk ${chunkIndex + 1} timed out`));
|
|
598
|
+
}, 30_000);
|
|
599
|
+
this.pendingUploadAcks.set(key, {
|
|
600
|
+
timeout,
|
|
601
|
+
resolve,
|
|
602
|
+
reject,
|
|
603
|
+
});
|
|
604
|
+
this.channel.send_sftp_upload_chunk(this.nodeId, this.session_id, uploadId, chunkIndex, chunkBuffer.length, chunkBuffer, null);
|
|
605
|
+
});
|
|
606
|
+
uploadedBytes += chunkBuffer.length;
|
|
607
|
+
this.update_upload_progress(uploadedBytes, fileToUpload.size, startedAt);
|
|
608
|
+
}
|
|
609
|
+
this.upload_progress = 100;
|
|
610
|
+
this.upload_finished = true;
|
|
611
|
+
this.status = 'Connected';
|
|
612
|
+
this.refresh_directory();
|
|
613
|
+
}
|
|
614
|
+
catch (err) {
|
|
615
|
+
if (err.message !== 'Upload cancelled') {
|
|
616
|
+
this.show_error = true;
|
|
617
|
+
this.error_message = err instanceof Error ? err.message : 'Upload failed';
|
|
618
|
+
}
|
|
619
|
+
this.upload_finished = false;
|
|
620
|
+
this.status = 'Connected';
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
handle_op_result(web) {
|
|
624
|
+
if (web.msg_id === undefined) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const pending = this.pendingOps.get(web.msg_id);
|
|
628
|
+
if (!pending) {
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
window.clearTimeout(pending.timeout);
|
|
632
|
+
this.pendingOps.delete(web.msg_id);
|
|
633
|
+
pending.resolve(web.result);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Send one filesystem operation and wait for its single answer.
|
|
637
|
+
*
|
|
638
|
+
* There are three outcomes: an `SFTPOpResult` resolves it, an `Error` frame
|
|
639
|
+
* carrying the same `msg_id` rejects it, and the timeout covers the case
|
|
640
|
+
* worth naming — an agent built before these frames existed logs the
|
|
641
|
+
* unknown frame and drops it, so silence usually means "too old" rather
|
|
642
|
+
* than "slow", and the message says so.
|
|
643
|
+
*/
|
|
644
|
+
run_op(verb, send, timeoutMs = 30_000) {
|
|
645
|
+
if (!this.session_id) {
|
|
646
|
+
return Promise.reject(new Error('No active SFTP session.'));
|
|
647
|
+
}
|
|
648
|
+
const msgId = this.next_msg_id();
|
|
649
|
+
return new Promise((resolve, reject) => {
|
|
650
|
+
const timeout = window.setTimeout(() => {
|
|
651
|
+
this.pendingOps.delete(msgId);
|
|
652
|
+
reject(new Error(`Timed out trying to ${verb}. This node's agent may be too old to support it.`));
|
|
653
|
+
}, timeoutMs);
|
|
654
|
+
this.pendingOps.set(msgId, { verb, timeout, resolve, reject });
|
|
655
|
+
try {
|
|
656
|
+
send(msgId);
|
|
657
|
+
}
|
|
658
|
+
catch (err) {
|
|
659
|
+
window.clearTimeout(timeout);
|
|
660
|
+
this.pendingOps.delete(msgId);
|
|
661
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
error_text(err) {
|
|
666
|
+
return err instanceof Error ? err.message : String(err);
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* A listing entry carries its *parent* directory in `path`, so a full path
|
|
670
|
+
* is always the join of the two.
|
|
671
|
+
*/
|
|
672
|
+
item_path(item) {
|
|
673
|
+
return this.join_path(item.path, item.name);
|
|
674
|
+
}
|
|
675
|
+
join_path(dir, name) {
|
|
676
|
+
if (!dir || dir === '/') {
|
|
677
|
+
return `/${name}`;
|
|
678
|
+
}
|
|
679
|
+
return dir.endsWith('/') ? `${dir}${name}` : `${dir}/${name}`;
|
|
680
|
+
}
|
|
681
|
+
/** Names the remote would reject, or that would silently mean something else. */
|
|
682
|
+
invalid_name(name) {
|
|
683
|
+
if (!name) {
|
|
684
|
+
return 'Enter a name.';
|
|
685
|
+
}
|
|
686
|
+
if (name === '.' || name === '..') {
|
|
687
|
+
return 'That name is reserved.';
|
|
688
|
+
}
|
|
689
|
+
if (name.includes('/')) {
|
|
690
|
+
return 'A name cannot contain "/".';
|
|
691
|
+
}
|
|
692
|
+
if (name.includes('\u0000')) {
|
|
693
|
+
return 'A name cannot contain a null byte.';
|
|
694
|
+
}
|
|
695
|
+
return '';
|
|
696
|
+
}
|
|
697
|
+
handle_tunnel_data(web) {
|
|
698
|
+
console.log('received tunnel data:', web);
|
|
699
|
+
}
|
|
700
|
+
handle_tunnel_closed(_web_) {
|
|
701
|
+
// this.session_id = undefined;
|
|
702
|
+
// this.inputMode = InputMode.Default;
|
|
703
|
+
this.clear_creds_buffer();
|
|
704
|
+
// this.terminal.reset();
|
|
705
|
+
// this.terminal.writeln("Connection closed.");
|
|
706
|
+
this.close_comms();
|
|
707
|
+
}
|
|
708
|
+
open_comms() {
|
|
709
|
+
const endpoint = `${this.create_web_socket_endpoint()}/api/web/ws`;
|
|
710
|
+
if (this.channelFactory) {
|
|
711
|
+
this.channel = this.channelFactory(endpoint, this.nodeId, this.serverId || undefined);
|
|
712
|
+
}
|
|
713
|
+
else if (this.serverId) {
|
|
714
|
+
this.channel = new Channel(endpoint, this.nodeId, this.serverId);
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
this.channel = new Channel(endpoint, this.nodeId);
|
|
718
|
+
}
|
|
719
|
+
this.channel.on_connection_open(() => {
|
|
720
|
+
this.connectionStateChanged.emit([ConnectionState.Connected]);
|
|
721
|
+
this.channel.authenticate(this.token, this.nodeId);
|
|
722
|
+
this.status = 'Authenticating...';
|
|
723
|
+
});
|
|
724
|
+
this.channel.on_connection_close(() => {
|
|
725
|
+
this.connectionStateChanged.emit([ConnectionState.Disconnected]);
|
|
726
|
+
this.status = 'Disconnected';
|
|
727
|
+
});
|
|
728
|
+
this.channel.on_connection_error((err) => {
|
|
729
|
+
this.connectionStateChanged.emit([ConnectionState.Error, err]);
|
|
730
|
+
this.status = 'Error ' + err.message;
|
|
731
|
+
});
|
|
732
|
+
this.channel.on_connection_message((_raw_) => {
|
|
733
|
+
//
|
|
734
|
+
});
|
|
735
|
+
this.channel.on_protocol_message((msg) => {
|
|
736
|
+
const { web } = msg.data;
|
|
737
|
+
switch (web.type) {
|
|
738
|
+
case ProtocolMessageType.Error:
|
|
739
|
+
this.handle_error(web);
|
|
740
|
+
break;
|
|
741
|
+
case ProtocolMessageType.AuthSuccess:
|
|
742
|
+
this.handle_auth_success(web);
|
|
743
|
+
break;
|
|
744
|
+
case ProtocolMessageType.TunnelOpened:
|
|
745
|
+
this.handle_tunnel_opened(web);
|
|
746
|
+
break;
|
|
747
|
+
case ProtocolMessageType.TunnelClosed:
|
|
748
|
+
this.handle_tunnel_closed(web);
|
|
749
|
+
break;
|
|
750
|
+
case ProtocolMessageType.TunnelData:
|
|
751
|
+
this.handle_tunnel_data(web);
|
|
752
|
+
break;
|
|
753
|
+
case ProtocolMessageType.SFTPListItems:
|
|
754
|
+
this.handle_sftp_list_items(web);
|
|
755
|
+
break;
|
|
756
|
+
case ProtocolMessageType.SFTPUploadStartResponse:
|
|
757
|
+
this.handle_upload_start_response(web);
|
|
758
|
+
break;
|
|
759
|
+
case ProtocolMessageType.SFTPUploadChunkAck:
|
|
760
|
+
this.handle_upload_chunk_ack(web);
|
|
761
|
+
break;
|
|
762
|
+
case ProtocolMessageType.SFTPDownloadStartResponse:
|
|
763
|
+
this.handle_download_start_response(web);
|
|
764
|
+
break;
|
|
765
|
+
case ProtocolMessageType.SFTPDownloadChunk:
|
|
766
|
+
this.handle_download_chunk(web);
|
|
767
|
+
break;
|
|
768
|
+
case ProtocolMessageType.SFTPOpResult:
|
|
769
|
+
this.handle_op_result(web);
|
|
770
|
+
break;
|
|
771
|
+
default:
|
|
772
|
+
console.warn('Unhandled protocol message type:', web);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
close_comms() {
|
|
777
|
+
this.cancel_active_upload();
|
|
778
|
+
this.cancel_active_download();
|
|
779
|
+
this.clear_pending_operations();
|
|
780
|
+
if (!this.channel) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
this.channel.stop_heartbeat();
|
|
784
|
+
this.channel.disconnect();
|
|
785
|
+
}
|
|
786
|
+
clear_creds_buffer() {
|
|
787
|
+
// this.usernameBuffer = "";
|
|
788
|
+
// this.passwordBuffer = "";
|
|
789
|
+
}
|
|
790
|
+
reset_session_state() {
|
|
791
|
+
// this.session_id = undefined;
|
|
792
|
+
// this.inputMode = InputMode.Default;
|
|
793
|
+
this.clear_creds_buffer();
|
|
794
|
+
}
|
|
795
|
+
list_breadcrumb(path) {
|
|
796
|
+
this.show_loader = true;
|
|
797
|
+
this.selected_item = null;
|
|
798
|
+
this.channel.send_sftp_list_data(this.nodeId, this.session_id, path);
|
|
799
|
+
}
|
|
800
|
+
go_to_parent_directory() {
|
|
801
|
+
if (!this.session_id) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (this.current_dir === '/') {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
const parent = this.breadcrumbs[this.breadcrumbs.length - 2]?.path || '/';
|
|
808
|
+
this.list_breadcrumb(parent);
|
|
809
|
+
}
|
|
810
|
+
refresh_directory() {
|
|
811
|
+
if (!this.session_id) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
this.list_breadcrumb(this.current_dir);
|
|
815
|
+
}
|
|
816
|
+
disconnect_session() {
|
|
817
|
+
this.close_comms();
|
|
818
|
+
this.session_id = undefined;
|
|
819
|
+
this.show_loader = false;
|
|
820
|
+
this.show_content = false;
|
|
821
|
+
this.breadcrumbs = [];
|
|
822
|
+
this.current_dir = '.';
|
|
823
|
+
this.listing = [];
|
|
824
|
+
this.show_navigation = false;
|
|
825
|
+
this.show_login_screen_username = false;
|
|
826
|
+
this.show_login_screen_password = false;
|
|
827
|
+
this.show_login_screen = false;
|
|
828
|
+
this.show_upload_modal = false;
|
|
829
|
+
this.show_download_modal = false;
|
|
830
|
+
this.show_delete_modal = false;
|
|
831
|
+
this.upload_progress = 0;
|
|
832
|
+
this.download_progress = 0;
|
|
833
|
+
this.upload_finished = false;
|
|
834
|
+
this.download_finished = false;
|
|
835
|
+
this.delete_loading = false;
|
|
836
|
+
this.delete_file_name = '';
|
|
837
|
+
this.delete_error = '';
|
|
838
|
+
this.delete_is_dir = false;
|
|
839
|
+
this.delete_recursive = false;
|
|
840
|
+
this.prompt_kind = null;
|
|
841
|
+
this.prompt_value = '';
|
|
842
|
+
this.prompt_error = '';
|
|
843
|
+
this.prompt_busy = false;
|
|
844
|
+
this.chmod_target = null;
|
|
845
|
+
this.chmod_error = '';
|
|
846
|
+
this.chmod_busy = false;
|
|
847
|
+
this.show_editor = false;
|
|
848
|
+
this.editor_busy = '';
|
|
849
|
+
this.editor_error = '';
|
|
850
|
+
this.editor_confirm_discard = false;
|
|
851
|
+
this.editor_loaded = false;
|
|
852
|
+
this.filter = '';
|
|
853
|
+
this.version = '';
|
|
854
|
+
this.status = 'Disconnected';
|
|
855
|
+
}
|
|
856
|
+
on_file_row_action(item, event) {
|
|
857
|
+
event.preventDefault();
|
|
858
|
+
event.stopPropagation();
|
|
859
|
+
if (item.kind !== 'File') {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
void this.start_download(item);
|
|
863
|
+
}
|
|
864
|
+
on_file_delete_action(item, event) {
|
|
865
|
+
event.preventDefault();
|
|
866
|
+
event.stopPropagation();
|
|
867
|
+
this.selected_item = item;
|
|
868
|
+
this.delete_file_name = item.name;
|
|
869
|
+
this.delete_is_dir = item.kind === 'Folder';
|
|
870
|
+
this.delete_recursive = false;
|
|
871
|
+
this.delete_error = '';
|
|
872
|
+
this.delete_loading = false;
|
|
873
|
+
this.show_delete_modal = true;
|
|
874
|
+
}
|
|
875
|
+
cancel_delete() {
|
|
876
|
+
if (this.delete_loading) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
this.show_delete_modal = false;
|
|
880
|
+
this.delete_file_name = '';
|
|
881
|
+
this.delete_error = '';
|
|
882
|
+
this.delete_is_dir = false;
|
|
883
|
+
this.delete_recursive = false;
|
|
884
|
+
}
|
|
885
|
+
async confirm_delete() {
|
|
886
|
+
if (this.delete_loading) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
const target = this.selected_item;
|
|
890
|
+
if (!this.session_id || !target) {
|
|
891
|
+
this.show_delete_modal = false;
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
const path = this.item_path(target);
|
|
895
|
+
const recursive = this.delete_is_dir && this.delete_recursive;
|
|
896
|
+
this.delete_loading = true;
|
|
897
|
+
this.delete_error = '';
|
|
898
|
+
this.show_error = false;
|
|
899
|
+
this.status = `Deleting ${target.name}...`;
|
|
900
|
+
try {
|
|
901
|
+
// A recursive delete walks the tree one entry at a time over SSH,
|
|
902
|
+
// so it earns a far longer leash than the other operations.
|
|
903
|
+
await this.run_op('delete', (msgId) => this.channel.send_sftp_remove(this.nodeId, this.session_id, path, recursive, msgId), recursive ? 300_000 : 30_000);
|
|
904
|
+
this.delete_loading = false;
|
|
905
|
+
this.show_delete_modal = false;
|
|
906
|
+
this.delete_file_name = '';
|
|
907
|
+
this.delete_is_dir = false;
|
|
908
|
+
this.delete_recursive = false;
|
|
909
|
+
this.status = 'Connected';
|
|
910
|
+
this.refresh_directory();
|
|
911
|
+
}
|
|
912
|
+
catch (err) {
|
|
913
|
+
this.delete_loading = false;
|
|
914
|
+
this.delete_error = this.error_text(err);
|
|
915
|
+
this.status = 'Connected';
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
open_mkdir() {
|
|
919
|
+
if (!this.session_id) {
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
this.prompt_kind = 'mkdir';
|
|
923
|
+
this.prompt_value = '';
|
|
924
|
+
this.prompt_error = '';
|
|
925
|
+
this.prompt_busy = false;
|
|
926
|
+
}
|
|
927
|
+
on_rename_action(item, event) {
|
|
928
|
+
event.preventDefault();
|
|
929
|
+
event.stopPropagation();
|
|
930
|
+
if (!this.session_id) {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
this.selected_item = item;
|
|
934
|
+
this.prompt_kind = 'rename';
|
|
935
|
+
this.prompt_value = item.name;
|
|
936
|
+
this.prompt_error = '';
|
|
937
|
+
this.prompt_busy = false;
|
|
938
|
+
}
|
|
939
|
+
close_prompt() {
|
|
940
|
+
if (this.prompt_busy) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
this.prompt_kind = null;
|
|
944
|
+
this.prompt_value = '';
|
|
945
|
+
this.prompt_error = '';
|
|
946
|
+
this.promptInputEl = undefined;
|
|
947
|
+
}
|
|
948
|
+
async submit_prompt() {
|
|
949
|
+
if (this.prompt_busy || !this.session_id) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const kind = this.prompt_kind;
|
|
953
|
+
const name = this.prompt_value.trim();
|
|
954
|
+
const invalid = this.invalid_name(name);
|
|
955
|
+
if (invalid) {
|
|
956
|
+
this.prompt_error = invalid;
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
const target = this.selected_item;
|
|
960
|
+
if (kind === 'rename' && target && name === target.name) {
|
|
961
|
+
this.close_prompt();
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
this.prompt_busy = true;
|
|
965
|
+
this.prompt_error = '';
|
|
966
|
+
this.show_error = false;
|
|
967
|
+
try {
|
|
968
|
+
if (kind === 'mkdir') {
|
|
969
|
+
const path = this.join_path(this.current_dir, name);
|
|
970
|
+
this.status = `Creating ${name}...`;
|
|
971
|
+
await this.run_op('create the folder', (msgId) => this.channel.send_sftp_mkdir(this.nodeId, this.session_id, path, msgId));
|
|
972
|
+
}
|
|
973
|
+
else if (kind === 'rename' && target) {
|
|
974
|
+
// `to` is a full path, so the same call would move the entry if
|
|
975
|
+
// the dialog ever offered a destination directory.
|
|
976
|
+
const from = this.item_path(target);
|
|
977
|
+
const to = this.join_path(target.path, name);
|
|
978
|
+
this.status = `Renaming ${target.name}...`;
|
|
979
|
+
await this.run_op('rename', (msgId) => this.channel.send_sftp_rename(this.nodeId, this.session_id, from, to, msgId));
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
this.prompt_busy = false;
|
|
983
|
+
this.close_prompt();
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
this.prompt_busy = false;
|
|
987
|
+
this.prompt_kind = null;
|
|
988
|
+
this.prompt_value = '';
|
|
989
|
+
this.promptInputEl = undefined;
|
|
990
|
+
this.status = 'Connected';
|
|
991
|
+
this.refresh_directory();
|
|
992
|
+
}
|
|
993
|
+
catch (err) {
|
|
994
|
+
this.prompt_busy = false;
|
|
995
|
+
this.prompt_error = this.error_text(err);
|
|
996
|
+
this.status = 'Connected';
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
on_chmod_action(item, event) {
|
|
1000
|
+
event.preventDefault();
|
|
1001
|
+
event.stopPropagation();
|
|
1002
|
+
if (!this.session_id) {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
this.selected_item = item;
|
|
1006
|
+
this.chmod_target = item;
|
|
1007
|
+
this.chmod_mode = (item.attributes.permissions ?? 0) & 0o7777;
|
|
1008
|
+
this.chmod_error = '';
|
|
1009
|
+
this.chmod_busy = false;
|
|
1010
|
+
}
|
|
1011
|
+
close_chmod() {
|
|
1012
|
+
if (this.chmod_busy) {
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
this.chmod_target = null;
|
|
1016
|
+
this.chmod_error = '';
|
|
1017
|
+
}
|
|
1018
|
+
toggle_chmod_bit(bit) {
|
|
1019
|
+
if (this.chmod_busy) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
this.chmod_mode = (this.chmod_mode ^ bit) & 0o7777;
|
|
1023
|
+
}
|
|
1024
|
+
on_chmod_octal_input(value) {
|
|
1025
|
+
const digits = value.trim();
|
|
1026
|
+
if (!/^[0-7]{1,4}$/.test(digits)) {
|
|
1027
|
+
this.chmod_error = 'Enter up to four octal digits, 0-7.';
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
this.chmod_error = '';
|
|
1031
|
+
this.chmod_mode = parseInt(digits, 8) & 0o7777;
|
|
1032
|
+
}
|
|
1033
|
+
async submit_chmod() {
|
|
1034
|
+
const target = this.chmod_target;
|
|
1035
|
+
if (this.chmod_busy || !this.session_id || !target) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
const path = this.item_path(target);
|
|
1039
|
+
const mode = this.chmod_mode & 0o7777;
|
|
1040
|
+
this.chmod_busy = true;
|
|
1041
|
+
this.chmod_error = '';
|
|
1042
|
+
this.show_error = false;
|
|
1043
|
+
this.status = `Setting permissions on ${target.name}...`;
|
|
1044
|
+
try {
|
|
1045
|
+
await this.run_op('change permissions', (msgId) => this.channel.send_sftp_chmod(this.nodeId, this.session_id, path, mode, msgId));
|
|
1046
|
+
this.chmod_busy = false;
|
|
1047
|
+
this.chmod_target = null;
|
|
1048
|
+
this.status = 'Connected';
|
|
1049
|
+
this.refresh_directory();
|
|
1050
|
+
}
|
|
1051
|
+
catch (err) {
|
|
1052
|
+
this.chmod_busy = false;
|
|
1053
|
+
this.chmod_error = this.error_text(err);
|
|
1054
|
+
this.status = 'Connected';
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
async on_edit_action(item, event) {
|
|
1058
|
+
event.preventDefault();
|
|
1059
|
+
event.stopPropagation();
|
|
1060
|
+
if (!this.session_id || item.kind !== 'File') {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const path = this.item_path(item);
|
|
1064
|
+
this.selected_item = item;
|
|
1065
|
+
this.show_editor = true;
|
|
1066
|
+
this.editorPath = path;
|
|
1067
|
+
this.editor_name = item.name;
|
|
1068
|
+
this.editor_text = '';
|
|
1069
|
+
this.editor_saved_text = '';
|
|
1070
|
+
this.editor_error = '';
|
|
1071
|
+
this.editor_confirm_discard = false;
|
|
1072
|
+
this.editor_loaded = false;
|
|
1073
|
+
this.editor_busy = 'loading';
|
|
1074
|
+
this.status = `Opening ${item.name}...`;
|
|
1075
|
+
try {
|
|
1076
|
+
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);
|
|
1077
|
+
if (answer.result !== 'FileContents') {
|
|
1078
|
+
throw new Error('The agent answered without any file contents.');
|
|
1079
|
+
}
|
|
1080
|
+
const text = this.decode_text(answer.contents instanceof Uint8Array ? answer.contents : new Uint8Array(answer.contents));
|
|
1081
|
+
this.editor_text = text;
|
|
1082
|
+
this.editor_saved_text = text;
|
|
1083
|
+
this.editor_loaded = true;
|
|
1084
|
+
this.editor_busy = '';
|
|
1085
|
+
this.status = 'Connected';
|
|
1086
|
+
}
|
|
1087
|
+
catch (err) {
|
|
1088
|
+
this.editor_busy = '';
|
|
1089
|
+
this.editor_error = this.error_text(err);
|
|
1090
|
+
this.status = 'Connected';
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Refuse binary rather than mangle it. A lossy decode looks fine on screen
|
|
1095
|
+
* and then writes replacement characters over the real bytes on save, so
|
|
1096
|
+
* anything that is not valid UTF-8 is sent to the download button instead.
|
|
1097
|
+
*/
|
|
1098
|
+
decode_text(bytes) {
|
|
1099
|
+
if (bytes.includes(0)) {
|
|
1100
|
+
throw new Error('This looks like a binary file. Download it instead of editing it here.');
|
|
1101
|
+
}
|
|
1102
|
+
try {
|
|
1103
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
1104
|
+
}
|
|
1105
|
+
catch {
|
|
1106
|
+
throw new Error('This file is not valid UTF-8. Download it instead of editing it here.');
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
editor_is_dirty() {
|
|
1110
|
+
return this.editor_loaded && this.editor_text !== this.editor_saved_text;
|
|
1111
|
+
}
|
|
1112
|
+
close_editor(force = false) {
|
|
1113
|
+
if (this.editor_busy === 'saving') {
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
if (!force && this.editor_is_dirty()) {
|
|
1117
|
+
this.editor_confirm_discard = true;
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
this.show_editor = false;
|
|
1121
|
+
this.editor_confirm_discard = false;
|
|
1122
|
+
this.editor_loaded = false;
|
|
1123
|
+
this.editorPath = '';
|
|
1124
|
+
this.editor_name = '';
|
|
1125
|
+
this.editor_text = '';
|
|
1126
|
+
this.editor_saved_text = '';
|
|
1127
|
+
this.editor_error = '';
|
|
1128
|
+
this.editor_busy = '';
|
|
1129
|
+
this.editorTextEl = undefined;
|
|
1130
|
+
}
|
|
1131
|
+
async save_editor() {
|
|
1132
|
+
if (this.editor_busy || !this.session_id || !this.editorPath) {
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
const path = this.editorPath;
|
|
1136
|
+
const text = this.editor_text;
|
|
1137
|
+
this.editor_busy = 'saving';
|
|
1138
|
+
this.editor_error = '';
|
|
1139
|
+
this.show_error = false;
|
|
1140
|
+
this.status = `Saving ${this.editor_name}...`;
|
|
1141
|
+
try {
|
|
1142
|
+
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);
|
|
1143
|
+
this.editor_saved_text = text;
|
|
1144
|
+
this.editor_busy = '';
|
|
1145
|
+
this.status = 'Connected';
|
|
1146
|
+
this.refresh_directory();
|
|
1147
|
+
}
|
|
1148
|
+
catch (err) {
|
|
1149
|
+
this.editor_busy = '';
|
|
1150
|
+
this.editor_error = this.error_text(err);
|
|
1151
|
+
this.status = 'Connected';
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
toggle_sort(key) {
|
|
1155
|
+
if (this.sort_key === key) {
|
|
1156
|
+
this.sort_asc = !this.sort_asc;
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
this.sort_key = key;
|
|
1160
|
+
this.sort_asc = true;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Folders stay above files whichever way the sort runs: a listing that
|
|
1164
|
+
* scatters directories through the files is harder to scan, not more sorted.
|
|
1165
|
+
*/
|
|
1166
|
+
visible_listing() {
|
|
1167
|
+
const needle = this.filter.trim().toLowerCase();
|
|
1168
|
+
const rows = needle
|
|
1169
|
+
? this.listing.filter((item) => item.name.toLowerCase().includes(needle))
|
|
1170
|
+
: [...this.listing];
|
|
1171
|
+
const direction = this.sort_asc ? 1 : -1;
|
|
1172
|
+
return rows.sort((a, b) => {
|
|
1173
|
+
if (a.kind !== b.kind) {
|
|
1174
|
+
return a.kind === 'Folder' ? -1 : 1;
|
|
1175
|
+
}
|
|
1176
|
+
switch (this.sort_key) {
|
|
1177
|
+
case 'size':
|
|
1178
|
+
return direction * ((a.attributes.size ?? 0) - (b.attributes.size ?? 0));
|
|
1179
|
+
case 'modified':
|
|
1180
|
+
return direction * ((a.attributes.modified ?? 0) - (b.attributes.modified ?? 0));
|
|
1181
|
+
default:
|
|
1182
|
+
return direction * a.name.localeCompare(b.name, undefined, {
|
|
1183
|
+
numeric: true,
|
|
1184
|
+
sensitivity: 'base',
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
sort_indicator(key) {
|
|
1190
|
+
if (this.sort_key !== key) {
|
|
1191
|
+
return '';
|
|
1192
|
+
}
|
|
1193
|
+
return this.sort_asc ? ' \u25b2' : ' \u25bc';
|
|
1194
|
+
}
|
|
1195
|
+
/** Keyboard shortcuts, scoped to the file table so the page keeps its own. */
|
|
1196
|
+
on_listing_keydown(event) {
|
|
1197
|
+
if (this.prompt_kind || this.chmod_target || this.show_editor || this.show_delete_modal) {
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
const item = this.selected_item;
|
|
1201
|
+
switch (event.key) {
|
|
1202
|
+
case 'Backspace':
|
|
1203
|
+
event.preventDefault();
|
|
1204
|
+
this.go_to_parent_directory();
|
|
1205
|
+
break;
|
|
1206
|
+
case 'F5':
|
|
1207
|
+
event.preventDefault();
|
|
1208
|
+
this.refresh_directory();
|
|
1209
|
+
break;
|
|
1210
|
+
case 'F2':
|
|
1211
|
+
if (item) {
|
|
1212
|
+
event.preventDefault();
|
|
1213
|
+
this.on_rename_action(item, event);
|
|
1214
|
+
}
|
|
1215
|
+
break;
|
|
1216
|
+
case 'Delete':
|
|
1217
|
+
if (item) {
|
|
1218
|
+
event.preventDefault();
|
|
1219
|
+
this.on_file_delete_action(item, event);
|
|
1220
|
+
}
|
|
1221
|
+
break;
|
|
1222
|
+
case 'Enter':
|
|
1223
|
+
if (item) {
|
|
1224
|
+
event.preventDefault();
|
|
1225
|
+
this.list_directory(item);
|
|
1226
|
+
}
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
on_modal_keydown(event, close) {
|
|
1231
|
+
if (event.key === 'Escape') {
|
|
1232
|
+
event.preventDefault();
|
|
1233
|
+
event.stopPropagation();
|
|
1234
|
+
close();
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
/** Focus a dialog's field as it appears, without re-focusing on every render. */
|
|
1238
|
+
focus_once(el, current, keep) {
|
|
1239
|
+
if (!el || el === current) {
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
keep(el);
|
|
1243
|
+
requestAnimationFrame(() => el.focus());
|
|
1244
|
+
}
|
|
1245
|
+
open_upload_picker() {
|
|
1246
|
+
this.uploadInputEl?.click();
|
|
1247
|
+
}
|
|
1248
|
+
on_upload_selected(event) {
|
|
1249
|
+
const input = event.target;
|
|
1250
|
+
const selectedFile = input.files?.[0];
|
|
1251
|
+
if (!selectedFile) {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
void this.upload_file(selectedFile);
|
|
1255
|
+
input.value = '';
|
|
1256
|
+
}
|
|
1257
|
+
cancel_upload() {
|
|
1258
|
+
this.cancel_active_upload();
|
|
1259
|
+
this.show_upload_modal = false;
|
|
1260
|
+
this.upload_file_name = '';
|
|
1261
|
+
this.upload_speed = '--';
|
|
1262
|
+
this.status = 'Connected';
|
|
1263
|
+
this.refresh_directory();
|
|
1264
|
+
}
|
|
1265
|
+
cancel_download() {
|
|
1266
|
+
this.cancel_active_download();
|
|
1267
|
+
this.show_download_modal = false;
|
|
1268
|
+
this.download_file_name = '';
|
|
1269
|
+
this.download_speed = '--';
|
|
1270
|
+
this.status = 'Connected';
|
|
1271
|
+
this.refresh_directory();
|
|
1272
|
+
}
|
|
1273
|
+
is_selected(item) {
|
|
1274
|
+
if (!this.selected_item) {
|
|
1275
|
+
return false;
|
|
1276
|
+
}
|
|
1277
|
+
return this.selected_item.path === item.path &&
|
|
1278
|
+
this.selected_item.name === item.name;
|
|
1279
|
+
}
|
|
1280
|
+
list_directory(entry) {
|
|
1281
|
+
if (!this.session_id) {
|
|
1282
|
+
console.warn('No active session. Cannot list directory.');
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
if (entry.kind === 'File') {
|
|
1286
|
+
console.warn('Cannot list directory of a file. Ignoring click.');
|
|
1287
|
+
this.selected_item = entry;
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
const path = this.item_path(entry);
|
|
1291
|
+
if (path === this.current_dir) {
|
|
1292
|
+
console.warn('Already in this directory. Ignoring click.');
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
this.show_loader = true;
|
|
1296
|
+
this.selected_item = null;
|
|
1297
|
+
this.channel.send_sftp_list_data(this.nodeId, this.session_id, path);
|
|
1298
|
+
}
|
|
1299
|
+
format_size(size) {
|
|
1300
|
+
if (size === undefined || Number.isNaN(size)) {
|
|
1301
|
+
return '-';
|
|
1302
|
+
}
|
|
1303
|
+
if (size < 1024) {
|
|
1304
|
+
return `${size} B`;
|
|
1305
|
+
}
|
|
1306
|
+
const units = ['KB', 'MB', 'GB', 'TB', 'PB'];
|
|
1307
|
+
let value = size;
|
|
1308
|
+
let unitIndex = -1;
|
|
1309
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
1310
|
+
value /= 1024;
|
|
1311
|
+
unitIndex += 1;
|
|
1312
|
+
}
|
|
1313
|
+
const rounded = value >= 10 ? value.toFixed(1) : value.toFixed(2);
|
|
1314
|
+
return `${rounded} ${units[unitIndex]}`;
|
|
1315
|
+
}
|
|
1316
|
+
mode_type_to_char(mode, kind) {
|
|
1317
|
+
const S_IFMT = 0o170000;
|
|
1318
|
+
const type = mode & S_IFMT;
|
|
1319
|
+
switch (type) {
|
|
1320
|
+
case 0o140000: return 's';
|
|
1321
|
+
case 0o120000: return 'l';
|
|
1322
|
+
case 0o100000: return '-';
|
|
1323
|
+
case 0o060000: return 'b';
|
|
1324
|
+
case 0o040000: return 'd';
|
|
1325
|
+
case 0o020000: return 'c';
|
|
1326
|
+
case 0o010000: return 'p';
|
|
1327
|
+
default:
|
|
1328
|
+
return kind === 'Folder' ? 'd' : '-';
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
format_permissions(permissions, kind) {
|
|
1332
|
+
if (permissions === undefined || permissions === null) {
|
|
1333
|
+
return '-';
|
|
1334
|
+
}
|
|
1335
|
+
if (typeof permissions === 'string') {
|
|
1336
|
+
const value = permissions.trim();
|
|
1337
|
+
if (/^[bcdlps-][rwxStTs-]{9}$/.test(value)) {
|
|
1338
|
+
return value;
|
|
1339
|
+
}
|
|
1340
|
+
if (/^[0-7]{3,4}$/.test(value)) {
|
|
1341
|
+
const mode = parseInt(value, 8);
|
|
1342
|
+
return this.format_permissions(mode, kind);
|
|
1343
|
+
}
|
|
1344
|
+
if (/^\d+$/.test(value)) {
|
|
1345
|
+
const mode = parseInt(value, 10);
|
|
1346
|
+
return this.format_permissions(mode, kind);
|
|
1347
|
+
}
|
|
1348
|
+
return value || '-';
|
|
1349
|
+
}
|
|
1350
|
+
const mode = permissions;
|
|
1351
|
+
const typeChar = this.mode_type_to_char(mode, kind);
|
|
1352
|
+
const chars = [
|
|
1353
|
+
mode & 0o400 ? 'r' : '-',
|
|
1354
|
+
mode & 0o200 ? 'w' : '-',
|
|
1355
|
+
mode & 0o100 ? 'x' : '-',
|
|
1356
|
+
mode & 0o040 ? 'r' : '-',
|
|
1357
|
+
mode & 0o020 ? 'w' : '-',
|
|
1358
|
+
mode & 0o010 ? 'x' : '-',
|
|
1359
|
+
mode & 0o004 ? 'r' : '-',
|
|
1360
|
+
mode & 0o002 ? 'w' : '-',
|
|
1361
|
+
mode & 0o001 ? 'x' : '-',
|
|
1362
|
+
];
|
|
1363
|
+
if (mode & 0o4000) {
|
|
1364
|
+
chars[2] = chars[2] === 'x' ? 's' : 'S';
|
|
1365
|
+
}
|
|
1366
|
+
if (mode & 0o2000) {
|
|
1367
|
+
chars[5] = chars[5] === 'x' ? 's' : 'S';
|
|
1368
|
+
}
|
|
1369
|
+
if (mode & 0o1000) {
|
|
1370
|
+
chars[8] = chars[8] === 'x' ? 't' : 'T';
|
|
1371
|
+
}
|
|
1372
|
+
return `${typeChar}${chars.join('')}`;
|
|
1373
|
+
}
|
|
1374
|
+
render() {
|
|
1375
|
+
return (h(Host, { key: '9e2edc1a72c3a74b26feea2faa08b9f0a2e37a0c', class: {
|
|
1376
|
+
'default': !this.max,
|
|
1377
|
+
'max': this.max,
|
|
1378
|
+
} }, h("section", { key: '72fae8227792615a5452f9b01ec8230c2c10e2a9', class: "listing" }, !this.hideHeader &&
|
|
1379
|
+
h("header", { key: '14632fcb4575678418132892308cfea1903fadab' }, h("section", { key: '3ea3fb2cab9d4cdf36af3876235579562a7acbef', class: "title" }, h("img", { key: 'fd0badaae9b0d7b426ddece5faf7ea3515e9bbf0', src: phirepassSftpClientLogoSvg, alt: "SFTP Client" }), h("div", { key: '4eece24a618c119861f5435eb3f1ae8a5bae4966', class: "text" }, h("div", { key: '84b45196e1a1609451413cf8ea369b60cd7f5ec6', class: "name" }, this.name), h("div", { key: '45da97e659ecbaa69e74d1789a1b7961b760a753', class: "description" }, this.description))), h("section", { key: '9177dcc02b911e95870c5f55fc48f741895a0b75', class: "actions" }, h("div", { key: '468f341eebf7569c2a1c4aeea09d56644e5b6161', class: "action", onClick: () => this.toggle_max() }, h("img", { key: '203b54e42cddc50bf068a49fa7f88c846ecaa2c9', src: phirepassSftpClientMaxSvg, alt: "Maximize" })))), h("main", { key: 'c0f757aaa07734199228e3dc520c98694bc6548d' }, this.show_navigation && h("nav", { key: '295440219080af5fa33566300fb1036998da399c', class: "navigation" }, h("div", { key: 'c9b63f04de675559d2e2bbb876115c63e00bfbd2', 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: phirepassSftpClientChevronSvg }))))), h("section", { key: '325ccd4be07d61df1e16956b5818683feb70c52f', class: "actions", "aria-label": "SFTP actions" }, h("input", { key: 'f75b4191b0718bd2234497b7168af9dc13a070d6', 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: 'da64c4a88332d3efab6a6e03e8c16a8a1db96b43', type: "button", class: "action", onClick: () => this.go_to_parent_directory(), title: "Go to parent directory", "aria-label": "Go to parent directory" }, h("img", { key: '309e0fdb89aa4d119a5193f1803ebdc117e55105', src: phirepassSftpClientGoUpSvg, alt: "Go up" })), h("button", { key: '5f451e50801f10b88a3436515d792b1015bf48bb', type: "button", class: "action", onClick: () => this.refresh_directory(), title: "Refresh", "aria-label": "Refresh" }, h("img", { key: 'aa673b81504e65e78043c328f94d3a9dd02f696a', src: phirepassSftpClientRefreshSvg, alt: "Refresh" })), h("button", { key: '963f5abf044c207f9e42babe9e029ac052521f36', type: "button", class: "action", onClick: () => this.open_mkdir(), title: "New folder", "aria-label": "New folder" }, h("svg", { key: 'd441f67a8b5d2944f95e934d60d680dc22ec7c6c', 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: '9eec6695289a71b135dee4751217cd4b4810a276', 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: '9a759bd7ac97c4e8ebf75c4d54e8f207999634c2', x1: "12", x2: "12", y1: "10", y2: "16" }), h("line", { key: '4591434cdbb6a7d3a1a0212409fe38e21e02a52e', x1: "9", x2: "15", y1: "13", y2: "13" }))), h("button", { key: '301d406858c2d9a4656a342b49e663e76a7f1970', type: "button", class: "action", onClick: () => this.open_upload_picker(), title: "Upload", "aria-label": "Upload" }, h("img", { key: '36ff8480d3acf65282d6ef648349327eb3432237', src: phirepassSftpClientUploadSvg, alt: "Upload" })), h("button", { key: '3fa19d5e17ef2e2a8fc926c8ba6994a4a30a1825', type: "button", class: "action disconnect", onClick: () => this.disconnect_session(), title: "Disconnect", "aria-label": "Disconnect" }, "DISCONNECT"))), h("input", { key: 'f5cf6cc13d4b760b538d630467972c8add2df490', type: "file", ref: (el) => this.uploadInputEl = el, onChange: (event) => this.on_upload_selected(event), style: { display: 'none' } }), this.show_content && h("div", { key: 'd69a7009192adc292cf3ccf4de6a4f059b46fa0e', class: "content", tabindex: 0, onKeyDown: (event) => this.on_listing_keydown(event) }, h("table", { key: '2f00d85024b3e4642925f488a34d228dd056a2ce' }, h("thead", { key: '611091a29f97e218f5282e11c7c1accdc1be5732' }, h("tr", { key: '5f0d04ff8a5009852af02472f4261b9a95733a3c' }, h("th", { key: '6df9558b86b3d3161920d5f94e8df0cf47ee9c80', class: "sortable", onClick: () => this.toggle_sort('name'), title: "Sort by name" }, "Name", this.sort_indicator('name')), h("th", { key: '83384582ac59c07f65526cfc5fd1359b5a0cd912', class: "sortable", onClick: () => this.toggle_sort('size'), title: "Sort by size" }, "Size", this.sort_indicator('size')), h("th", { key: 'cbc16eafd7fb17c9d79b5612502140bc9a16a3cb' }, "Permissions"), h("th", { key: '25d802dd84a6cc3eda222d5a732e05010c405f31' }, "Owner"), h("th", { key: 'cf5f9df11baae69f664724c6a79df0a95a5189a8', class: "sortable", onClick: () => this.toggle_sort('modified'), title: "Sort by modified date" }, "Modified", this.sort_indicator('modified')), h("th", { key: '9c8b9515c81245656d89ea65ee091a70606c1a93', class: "action-col", "aria-label": "Actions" }))), h("tbody", { key: '40f8ec5d38a0601af3520891c4a9d35b2da2c32f' }, this.visible_listing().map((item, index) => (h("tr", { key: index, class: {
|
|
1380
|
+
'selected': this.is_selected(item),
|
|
1381
|
+
}, onClick: () => this.list_directory(item) }, h("td", null, item.kind === 'Folder' ? h("img", { class: "kind", src: phirepassSftpClientFolderSvg, alt: "Folder" }) : h("img", { class: "kind", src: phirepassSftpClientFileSvg, 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' &&
|
|
1382
|
+
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' &&
|
|
1383
|
+
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 &&
|
|
1384
|
+
h("tr", { key: '46a173ad6542c9ab315da2792ea9830f0086b683', class: "empty" }, h("td", { key: '986924de123f9be62f89f869fca02cd195134080', colSpan: 6 }, this.filter ? `Nothing here matches "${this.filter}".` : 'This directory is empty.'))))), this.show_loader && h("div", { key: '588f4ff57df18c993f8566711a2627bd69b03881', class: "loader" }, "Loading..."), this.show_error && h("div", { key: '816c8ca05f68291d784d4c86509c9478204f3449', class: "error" }, this.error_message)), h("footer", { key: '6add74a0d5beb8de15a600d287d96dd69f87a646' }, h("section", { key: '39b31ae22b9f6298b8991be47d5641c1de618ab7', class: "status" }, this.status, this.selected_item && h("span", { key: '6e3942b5471e240719dfaf66cb01763f162ff3f0', class: "selected-item" }, this.selected_item.name)), h("section", { key: 'cc7ab5a9a632da8fae266f9ae73f967083e3589f', class: "version" }, this.version ? `Version: ${this.version}` : ''))), this.show_login_screen &&
|
|
1385
|
+
h("section", { key: '3e13e8c942f690d2e26c231c2403032af620f735', class: {
|
|
1386
|
+
'creds': true,
|
|
1387
|
+
'blurred': this.show_login_screen,
|
|
1388
|
+
} }, h("form", { key: '7ddb982159a3470bfad44aea75973a2eb37bebcd', class: "auth", onSubmit: (event) => {
|
|
1389
|
+
const formData = new FormData(event.target);
|
|
1390
|
+
let username = undefined;
|
|
1391
|
+
if (this.show_login_screen_username) {
|
|
1392
|
+
username = formData.get('username');
|
|
1393
|
+
}
|
|
1394
|
+
let password = undefined;
|
|
1395
|
+
if (this.show_login_screen_password) {
|
|
1396
|
+
password = formData.get('password');
|
|
1397
|
+
}
|
|
1398
|
+
this.channel.open_sftp_tunnel(this.nodeId, this.serviceId, username, password);
|
|
1399
|
+
this.show_login_screen_username = false;
|
|
1400
|
+
this.show_login_screen_password = false;
|
|
1401
|
+
this.show_login_screen = false;
|
|
1402
|
+
this.show_loader = true;
|
|
1403
|
+
event.stopPropagation();
|
|
1404
|
+
event.preventDefault();
|
|
1405
|
+
} }, h("div", { key: '036877a02034000a79836c0a0979def9163f8a1a', class: "title" }, "SFTP Connection"), this.show_login_screen_username &&
|
|
1406
|
+
h("div", { key: '37830ddb769fe0491831700a90f3fc8bf71cf050' }, h("label", { key: '0f6e3d70e34baae3342a57fceed657e59c8c05a4', htmlFor: "username" }, "Username"), h("input", { key: '3ecb202b3ee015e8719c330edb06889f4f48a433', autocorrect: "off", autocapitalize: "none", autoComplete: "off", id: "username", name: "username", type: "text", placeholder: "" })), this.show_login_screen_password &&
|
|
1407
|
+
h("div", { key: '092a40a9da1205ec6342069844135aea92b85c5a' }, h("label", { key: '19e465136660c9d2c1ecd0bb02bd7f8a559e3e0b', htmlFor: "password" }, "Password"), h("input", { key: 'ab9a74273abc594fa9fd51a780c2586fb275b4b4', autocorrect: "off", autocapitalize: "none", autoComplete: "off", id: "password", name: "password", type: "password", placeholder: "" })), h("div", { key: 'c1596787c7fea135d203f831cb7432a6e803d488' }, h("button", { key: '89314be80add42ba55f96ec01bf22848742ec179', type: "submit" }, "Connect")))), this.show_upload_modal &&
|
|
1408
|
+
h("section", { key: 'c8b08cf050947d1936c97caf46eacca93175db9f', class: {
|
|
1409
|
+
'upload-modal': true,
|
|
1410
|
+
'visible': this.show_upload_modal,
|
|
1411
|
+
} }, h("div", { key: 'ccc745354525565cda06b6b6eb8253c557c59009', class: "upload-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Upload progress" }, h("div", { key: 'd478b113fa655386998d93862fc53bf516eaf90b', class: "title" }, "Uploading File"), h("div", { key: '35c85475b00efcf05097e1feae1313afde0d04af', class: "file-name", title: this.upload_file_name }, this.upload_file_name), h("div", { key: 'd5cb7df154d77dacdca48673b2f01e03729846b0', class: "progress-track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": this.upload_progress }, h("div", { key: '4a7c10979b37d06acdda30c0b8d04a2af3cf0e5a', class: "progress-fill", style: { width: `${this.upload_progress}%` } })), h("div", { key: 'c69da13c3bc15a9a36867cbb1a8d041780ffecca', class: "progress-meta" }, h("div", { key: '000b027205a828e1257263e29b5a595ead0fe54a', class: "progress-speed" }, this.upload_speed), h("div", { key: '8eda5c230e39343ffb10aa1bc64f70999d428c57', class: "progress-value" }, this.format_percent(this.upload_progress))), h("button", { key: 'b047fe324179b9f77f97f7bcf541c32e0903bad9', type: "button", class: {
|
|
1412
|
+
'cancel': true,
|
|
1413
|
+
'finished': this.upload_finished,
|
|
1414
|
+
}, onClick: () => this.cancel_upload() }, this.upload_finished ? 'Close' : 'Cancel'))), this.show_download_modal &&
|
|
1415
|
+
h("section", { key: 'fff5c3228be15048397b86a1457f63d4562c98f8', class: {
|
|
1416
|
+
'download-modal': true,
|
|
1417
|
+
'visible': this.show_download_modal,
|
|
1418
|
+
} }, h("div", { key: '8bbf7465cdb2b514b16c4982b3480b04aa5e1a6c', class: "download-dialog", role: "dialog", "aria-modal": "true", "aria-label": "Download progress" }, h("div", { key: 'dea4371acce3010cefdb14bbc3873d6cca1e308c', class: "title" }, "Downloading File"), h("div", { key: 'cffc4ad6e269108252db2bbb3b3f9678e88aed4b', class: "file-name", title: this.download_file_name }, this.download_file_name), h("div", { key: 'ec0fd7bbd72c2c1dcb55dffb39a8e550af9c54a6', class: "progress-track", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": this.download_progress }, h("div", { key: 'c899bcf67b523e9de0db76bc9163d192120fd61b', class: "progress-fill", style: { width: `${this.download_progress}%` } })), h("div", { key: '14c343bb055ca7300f3b500bb9da06450f9338c8', class: "progress-meta" }, h("div", { key: '6b030a95eb9b11d88a070dd8a8dc9f4a2d10302a', class: "progress-speed" }, this.download_speed), h("div", { key: '0d8eb9884506e9bb7a31ea1ceedc0f3e3e74f9b8', class: "progress-value" }, this.format_percent(this.download_progress))), h("button", { key: '4416377601c6655ba0e9385e6149dd461702439a', type: "button", class: {
|
|
1419
|
+
'cancel': true,
|
|
1420
|
+
'finished': this.download_finished,
|
|
1421
|
+
}, onClick: () => this.cancel_download() }, this.download_finished ? 'Close' : 'Cancel'))), this.show_delete_modal &&
|
|
1422
|
+
h("section", { key: '803d5f9fc2096c44335380132eee7d6ee1c70c1f', class: {
|
|
1423
|
+
'delete-modal': true,
|
|
1424
|
+
'visible': this.show_delete_modal,
|
|
1425
|
+
} }, h("div", { key: '0f23cb5f9ed35b97accc994277c86eff46de74bd', 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: '6b64cac5732de2d5c091fea7ef1cd1b903b86c61', class: "title" }, this.delete_is_dir ? 'Delete Folder' : 'Delete File'), h("div", { key: 'f1b6592449d9697208c704dcaaeec83d4d40d852', class: "message" }, this.delete_loading
|
|
1426
|
+
? (this.delete_recursive ? 'Deleting the folder and everything in it...' : 'Deleting...')
|
|
1427
|
+
: `Are you sure you want to delete this ${this.delete_is_dir ? 'folder' : 'file'}?`), h("div", { key: 'a67f8bd35875e0477fcf3bbf9f075b10f9066f07', class: "file-name", title: this.delete_file_name }, this.delete_file_name), this.delete_is_dir &&
|
|
1428
|
+
h("label", { key: '5e660c03c1df789bcdc4dba7a2adfe4887dd71ca', class: "checkline" }, h("input", { key: 'c28122496182d007ae2f99d9de79451c23dadef5', type: "checkbox", checked: this.delete_recursive, disabled: this.delete_loading, onChange: (event) => this.delete_recursive = event.target.checked }), h("span", { key: '53539d4803c5358d26e181dc53fcc7f36ad62d6a' }, "Delete everything inside it too")), !this.delete_is_dir || this.delete_recursive ? null :
|
|
1429
|
+
h("div", { class: "hint" }, "Without this, the remote refuses a folder that is not empty."), this.delete_error && h("div", { key: '0773a1e6a26fa8dde7dba0d0ed00107d01782e2f', class: "dialog-error" }, this.delete_error), this.delete_loading &&
|
|
1430
|
+
h("div", { key: 'b1580f0825ec4f4b37f894fbd714f143a9515fd6', class: "delete-loader", "aria-hidden": "true" }, h("span", { key: 'db549d437007182afdaddab37d8caec7b1c4a2c7', class: "spinner" })), h("div", { key: '040a4c6730ce5149737211fae9d67a3a290bdc5c', class: "modal-actions" }, h("button", { key: 'b742ccd04a3e119c446a2186081835fd6f67022d', type: "button", class: "btn secondary", onClick: () => this.cancel_delete(), disabled: this.delete_loading }, "Cancel"), h("button", { key: '4ce414e250ace86f93d24e399ca56014e56c7757', type: "button", class: "btn destructive", onClick: () => this.confirm_delete(), disabled: this.delete_loading }, this.delete_loading ? 'Deleting...' : 'Delete')))), this.prompt_kind &&
|
|
1431
|
+
h("section", { key: 'd533b9ecb021dbb69766ba92e87d0b4279b047d4', class: "prompt-modal visible" }, h("div", { key: 'f7fbe0ee2323439da2c991046d90b1b6397ebee8', 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: '36b154bda604336f8bbb7c46d7bb35b6afd6cec2', class: "title" }, this.prompt_kind === 'mkdir' ? 'New Folder' : 'Rename'), h("div", { key: '76b8027be289fcdba2867e1b06f05cab8481564d', class: "message" }, this.prompt_kind === 'mkdir'
|
|
1432
|
+
? `Create a folder in ${this.current_dir}`
|
|
1433
|
+
: 'Give it a new name. Existing names are not overwritten.'), h("form", { key: '8ec6e410dc6572de35ff6b2c81734fa48d74a4a8', onSubmit: (event) => { event.preventDefault(); event.stopPropagation(); void this.submit_prompt(); } }, h("input", { key: '0511fa8205057fe088be93781c23e283bc07739e', 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: '2644600b1e015e02209309e1163e991acabad2e9', class: "dialog-error" }, this.prompt_error), h("div", { key: '520937e554f3ff7839aad18fd0ed3c56f8a21680', class: "modal-actions" }, h("button", { key: 'e5a037f006c3f97e6227e672cff6cf3dc7282abb', type: "button", class: "btn secondary", onClick: () => this.close_prompt(), disabled: this.prompt_busy }, "Cancel"), h("button", { key: 'b7883cc44b152c2c648f133eb5ffd7f5942d0aa4', type: "submit", class: "btn primary", disabled: this.prompt_busy }, this.prompt_busy ? 'Working...' : (this.prompt_kind === 'mkdir' ? 'Create' : 'Rename')))))), this.chmod_target &&
|
|
1434
|
+
h("section", { key: 'e99ef709477024789821b76e1bbaa6497dcbc474', class: "prompt-modal visible" }, h("div", { key: '1cec5818b817d089a9b4cda3b4ee514e7e9201a7', 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: '49c35a7228bbc6e9898c499904feb5fb525b2b5c', class: "title" }, "Permissions"), h("div", { key: '814edc9c438d956bef13b14bc22733502168c340', class: "file-name", title: this.chmod_target.name }, this.chmod_target.name), h("table", { key: 'a4c1b45c1ee830599e7c08a9a44c69df1ac2b201', class: "perm-grid" }, h("thead", { key: '99b953b4cf5f3a6aeff766d39b15222e74235a3c' }, h("tr", { key: '49d3ae286989915aaca71ba43cb19db357064158' }, h("th", { key: '3f3b7fcbeb1b713d29a874a111552f6ff95a811e', "aria-label": "Class" }), h("th", { key: '6d18882102b71cb61be8ae93a946f62da7b555bc' }, "Read"), h("th", { key: '44aed1177108307db4618680b5e7d28e248cdab6' }, "Write"), h("th", { key: 'd6056bed3aab4164768a010c369365c70e67bbbc' }, "Execute"))), h("tbody", { key: 'd54ecfe06cade301263977cf1f0a0ba9e3721b5c' }, [
|
|
1435
|
+
{ label: 'Owner', read: 0o400, write: 0o200, exec: 0o100 },
|
|
1436
|
+
{ label: 'Group', read: 0o040, write: 0o020, exec: 0o010 },
|
|
1437
|
+
{ label: 'Other', read: 0o004, write: 0o002, exec: 0o001 },
|
|
1438
|
+
].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: 'a124e9599de6b406d84ba9ffa3a56b3b993179ef', class: "perm-special" }, [
|
|
1439
|
+
{ label: 'setuid', bit: 0o4000 },
|
|
1440
|
+
{ label: 'setgid', bit: 0o2000 },
|
|
1441
|
+
{ label: 'sticky', bit: 0o1000 },
|
|
1442
|
+
].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: '05ab3c8451084b6acdf7ea0e45f71da0f913b08d', class: "perm-octal" }, h("label", { key: '5cb748e079c869720361e56c4973eaea82a85bc0', htmlFor: "chmod-octal" }, "Octal"), h("input", { key: '652571af51a36c975d8b7432923ef2ab80743480', 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: '4a789c75be9a941d2adf8de68cfda043c19864cc', class: "perm-preview" }, this.format_permissions(this.chmod_mode, this.chmod_target.kind))), this.chmod_error && h("div", { key: 'acb09c9d16146cc0466df1ea6394ff492604c397', class: "dialog-error" }, this.chmod_error), h("div", { key: '46c5c4fc154529060b24e335dcd192ed6dc6f75d', class: "modal-actions" }, h("button", { key: '2ad9fad876497e4d629c1911fbe29616853a2e59', type: "button", class: "btn secondary", onClick: () => this.close_chmod(), disabled: this.chmod_busy }, "Cancel"), h("button", { key: 'c14f7edb08da6d2db078722438e8e06455a076c7', type: "button", class: "btn primary", onClick: () => void this.submit_chmod(), disabled: this.chmod_busy }, this.chmod_busy ? 'Applying...' : 'Apply')))), this.show_editor &&
|
|
1443
|
+
h("section", { key: 'f040aeca04a6b02af3247c024271fbdc2564a0c4', class: "editor-modal visible" }, h("div", { key: '6874ae8a526168be8c2c09ca3f8a1faa52b78027', class: "editor-dialog", role: "dialog", "aria-modal": "true", "aria-label": `Editing ${this.editor_name}`, tabindex: -1, onKeyDown: (event) => {
|
|
1444
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 's') {
|
|
1445
|
+
event.preventDefault();
|
|
1446
|
+
void this.save_editor();
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
this.on_modal_keydown(event, () => this.close_editor());
|
|
1450
|
+
} }, h("div", { key: '421cbd1bfbde035049ed028c4d05083cc7d8f66f', class: "editor-head" }, h("div", { key: '889adcf6e0187963964920b9750531c3fa06cd37', class: "title" }, this.editor_name, this.editor_is_dirty() ? ' *' : ''), h("button", { key: 'b14d28ca6a80c9a08277ff20bc0b38fc30ea3869', type: "button", class: "editor-close", onClick: () => this.close_editor(), "aria-label": "Close editor", disabled: this.editor_busy === 'saving' }, "x")), this.editor_busy === 'loading'
|
|
1451
|
+
? h("div", { class: "editor-loading" }, "Loading...")
|
|
1452
|
+
: 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: 'e7c1db037e749fec8970ac2b2be2cb85cfcd85be', class: "dialog-error" }, this.editor_error), this.editor_confirm_discard &&
|
|
1453
|
+
h("div", { key: '84ca6080e18c4334e87374126b82b816f318cb0d', class: "dialog-error" }, "Unsaved changes. Close anyway?"), h("div", { key: '4515e164a418815eccfd9d54d8f96a076616f326', class: "modal-actions" }, this.editor_confirm_discard
|
|
1454
|
+
? h("button", { type: "button", class: "btn destructive", onClick: () => this.close_editor(true) }, "Discard")
|
|
1455
|
+
: h("button", { type: "button", class: "btn secondary", onClick: () => this.close_editor(), disabled: this.editor_busy === 'saving' }, "Close"), h("button", { key: 'b1e758ae6fd5de192135d617126c8c6939c62bde', type: "button", class: "btn primary", onClick: () => void this.save_editor(), disabled: !!this.editor_busy || !this.editor_is_dirty() }, this.editor_busy === 'saving' ? 'Saving...' : 'Save'))))));
|
|
1456
|
+
}
|
|
1457
|
+
static get watchers() { return {
|
|
1458
|
+
"nodeId": [{
|
|
1459
|
+
"onNodeIdChange": 0
|
|
1460
|
+
}],
|
|
1461
|
+
"serverId": [{
|
|
1462
|
+
"onServerIdChange": 0
|
|
1463
|
+
}]
|
|
1464
|
+
}; }
|
|
1465
|
+
};
|
|
1466
|
+
PhirepassSftpClient.style = phirepassSftpClientCss();
|
|
1467
|
+
|
|
1468
|
+
export { PhirepassSftpClient as phirepass_sftp_client };
|