phirepass-widgets 0.0.112 → 0.0.114

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