dsh-remote-vs 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/client.js +626 -117
- package/lib/index.js +252 -2
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/archive.d.ts +30 -0
- package/lib/types/client/DownloadDock.d.ts +15 -0
- package/lib/types/client/download.d.ts +69 -0
- package/lib/types/client/downloads.d.ts +63 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/protocol.d.ts +14 -0
- package/lib/types/sftp.d.ts +38 -0
- package/lib/{worlds-a8nqW9mi.js → worlds-oj65Hic-.js} +171 -1
- package/package.json +1 -1
- package/src/archive.ts +60 -0
- package/src/client/DownloadDock.tsx +89 -0
- package/src/client/RemoteExplorer.tsx +31 -1
- package/src/client/RemoteRoot.tsx +2 -0
- package/src/client/SearchView.tsx +8 -0
- package/src/client/download.ts +212 -0
- package/src/client/downloads.ts +175 -0
- package/src/client/i18n.ts +23 -0
- package/src/client/vsc/vsc.css +124 -0
- package/src/protocol.ts +492 -474
- package/src/routes.ts +221 -2
- package/src/sftp.ts +213 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download runner and its tiny observable store.
|
|
3
|
+
*
|
|
4
|
+
* The explorer/search menus start one download each; this module owns the
|
|
5
|
+
* stat preflight, the file-vs-directory choice, the cancel handle and the
|
|
6
|
+
* progress/status snapshot the dock renders. Kept outside React on purpose:
|
|
7
|
+
* the dock is portaled to `<body>` and may unmount with its sidebar tab, while
|
|
8
|
+
* a download already streaming must keep running to completion.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { api } from './api.ts'
|
|
12
|
+
import { saveRemoteDir, saveRemoteFile, saveRemoteMany, type DownloadOutcome } from './download.ts'
|
|
13
|
+
|
|
14
|
+
/** One download's lifecycle state. */
|
|
15
|
+
export type DownloadStatus = 'running' | 'done' | 'failed' | 'cancelled'
|
|
16
|
+
|
|
17
|
+
/** One task as the dock renders it. */
|
|
18
|
+
export interface DownloadTask {
|
|
19
|
+
id: string
|
|
20
|
+
/** Basename of the remote path (or `selection-N` for a multi-selection). */
|
|
21
|
+
name: string
|
|
22
|
+
/** Resolved from the stat preflight; `hint.directory` until then. */
|
|
23
|
+
directory: boolean
|
|
24
|
+
/** Entries in a multi-selection archive; absent for a single path. */
|
|
25
|
+
selection?: number
|
|
26
|
+
status: DownloadStatus
|
|
27
|
+
loaded: number
|
|
28
|
+
/** Absent for a streamed archive (chunked, size unknown). */
|
|
29
|
+
total?: number
|
|
30
|
+
/** Failure text, or the note shown for the browser-default fallback. */
|
|
31
|
+
error?: string
|
|
32
|
+
/** `browserDefault` means no save dialog existed and the file went to Downloads. */
|
|
33
|
+
via?: 'picker' | 'browserDefault'
|
|
34
|
+
startedAt: number
|
|
35
|
+
finishedAt?: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Human byte size for the progress line. */
|
|
39
|
+
export function formatByteCount(bytes: number): string {
|
|
40
|
+
if (!Number.isFinite(bytes) || bytes < 0) return '0 B'
|
|
41
|
+
if (bytes < 1024) return `${Math.round(bytes)} B`
|
|
42
|
+
const units = ['KiB', 'MiB', 'GiB', 'TiB']
|
|
43
|
+
let value = bytes / 1024
|
|
44
|
+
let unit = 0
|
|
45
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
46
|
+
value /= 1024
|
|
47
|
+
unit += 1
|
|
48
|
+
}
|
|
49
|
+
return `${value >= 100 ? Math.round(value) : value.toFixed(1)} ${units[unit]}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let tasks: readonly DownloadTask[] = []
|
|
53
|
+
const listeners = new Set<() => void>()
|
|
54
|
+
const controllers = new Map<string, AbortController>()
|
|
55
|
+
let sequence = 0
|
|
56
|
+
|
|
57
|
+
const notify = (): void => {
|
|
58
|
+
for (const listener of [...listeners]) listener()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const patch = (id: string, next: Partial<DownloadTask>): void => {
|
|
62
|
+
tasks = tasks.map(task => (task.id === id ? { ...task, ...next } : task))
|
|
63
|
+
notify()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Store surface: `useSyncExternalStore(subscribe, getSnapshot, getSnapshot)`. */
|
|
67
|
+
export const downloadsStore = {
|
|
68
|
+
subscribe(listener: () => void): () => void {
|
|
69
|
+
listeners.add(listener)
|
|
70
|
+
return () => {
|
|
71
|
+
listeners.delete(listener)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
getSnapshot(): readonly DownloadTask[] {
|
|
75
|
+
return tasks
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Progress sink handed to every starter. */
|
|
80
|
+
interface RunnerOptions {
|
|
81
|
+
signal: AbortSignal
|
|
82
|
+
onProgress: (progress: { loaded: number; total?: number }) => void
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Run one task body: progress patches, terminal status, cancel mapping.
|
|
87
|
+
*
|
|
88
|
+
* The task row is published by the caller before any await, so the dock shows
|
|
89
|
+
* the row immediately and only the numbers move afterwards.
|
|
90
|
+
*/
|
|
91
|
+
const launch = (id: string, controller: AbortController, run: (options: RunnerOptions) => Promise<DownloadOutcome>): void => {
|
|
92
|
+
void (async () => {
|
|
93
|
+
try {
|
|
94
|
+
const outcome = await run({
|
|
95
|
+
signal: controller.signal,
|
|
96
|
+
onProgress: (progress) => {
|
|
97
|
+
if (controller.signal.aborted) return
|
|
98
|
+
patch(id, {
|
|
99
|
+
loaded: progress.loaded,
|
|
100
|
+
...(progress.total === undefined ? {} : { total: progress.total }),
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
patch(id, {
|
|
105
|
+
status: 'done',
|
|
106
|
+
finishedAt: Date.now(),
|
|
107
|
+
via: outcome === 'downloaded' ? 'browserDefault' : 'picker',
|
|
108
|
+
})
|
|
109
|
+
} catch (error) {
|
|
110
|
+
const aborted = controller.signal.aborted || (error instanceof Error && error.name === 'AbortError')
|
|
111
|
+
patch(id, {
|
|
112
|
+
status: aborted ? 'cancelled' : 'failed',
|
|
113
|
+
finishedAt: Date.now(),
|
|
114
|
+
...(aborted ? {} : { error: error instanceof Error ? error.message : String(error) }),
|
|
115
|
+
})
|
|
116
|
+
} finally {
|
|
117
|
+
controllers.delete(id)
|
|
118
|
+
}
|
|
119
|
+
})()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Publish one running task and return its id plus cancel handle. */
|
|
123
|
+
const newTask = (task: Pick<DownloadTask, 'name' | 'directory'> & Partial<Pick<DownloadTask, 'selection'>>): { id: string; controller: AbortController } => {
|
|
124
|
+
const id = `download-${++sequence}`
|
|
125
|
+
const controller = new AbortController()
|
|
126
|
+
controllers.set(id, controller)
|
|
127
|
+
tasks = [...tasks, { ...task, id, status: 'running', loaded: 0, startedAt: Date.now() }]
|
|
128
|
+
notify()
|
|
129
|
+
return { id, controller }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Start one download (file or directory) and return its task id.
|
|
134
|
+
*
|
|
135
|
+
* The stat preflight runs here — not in the menus — so a deleted/unreadable
|
|
136
|
+
* remote path becomes a failed task with the Host's real message, and the
|
|
137
|
+
* file-vs-directory decision comes from the Host rather than a possibly stale
|
|
138
|
+
* tree row.
|
|
139
|
+
*/
|
|
140
|
+
export function startDownload(alias: string, path: string, hint: { name: string; directory: boolean }): string {
|
|
141
|
+
const { id, controller } = newTask({ name: hint.name, directory: hint.directory })
|
|
142
|
+
launch(id, controller, async (options) => {
|
|
143
|
+
const entry = await api.fileOp.stat(alias, path)
|
|
144
|
+
patch(id, { directory: entry.isDir })
|
|
145
|
+
return entry.isDir ? await saveRemoteDir(alias, path, options) : await saveRemoteFile(alias, path, options)
|
|
146
|
+
})
|
|
147
|
+
return id
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Start one multi-selection download.
|
|
152
|
+
*
|
|
153
|
+
* The Host archives every selected entry into a single `.tar.gz`, so the user
|
|
154
|
+
* picks one destination instead of answering N save dialogs; mixed files and
|
|
155
|
+
* directories are fine (tar recurses). Entry validation happens Host-side
|
|
156
|
+
* before the archive starts, so no client preflight round trip is needed.
|
|
157
|
+
*/
|
|
158
|
+
export function startSelectionDownload(alias: string, paths: readonly string[]): string {
|
|
159
|
+
const { id, controller } = newTask({ name: `selection-${paths.length}`, directory: true, selection: paths.length })
|
|
160
|
+
launch(id, controller, options => saveRemoteMany(alias, paths, options))
|
|
161
|
+
return id
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Cancel one running download (the panel's stop button). */
|
|
165
|
+
export function cancelDownload(id: string): void {
|
|
166
|
+
controllers.get(id)?.abort()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Drop one task from the dock (finished tasks only in practice). */
|
|
170
|
+
export function dismissDownload(id: string): void {
|
|
171
|
+
controllers.get(id)?.abort()
|
|
172
|
+
controllers.delete(id)
|
|
173
|
+
tasks = tasks.filter(task => task.id !== id)
|
|
174
|
+
notify()
|
|
175
|
+
}
|
package/src/client/i18n.ts
CHANGED
|
@@ -27,6 +27,9 @@ export const DYNAMIC_KEYS = [
|
|
|
27
27
|
'history.details',
|
|
28
28
|
'history.content',
|
|
29
29
|
'history.diff',
|
|
30
|
+
// Reached through the `STATUS_KEY` lookup in `DownloadDock.tsx` (running is
|
|
31
|
+
// the only status the detail line never prints as a literal `t()` call).
|
|
32
|
+
'downloads.running',
|
|
30
33
|
] as const
|
|
31
34
|
|
|
32
35
|
const zh: Record<string, string> = {
|
|
@@ -191,6 +194,16 @@ const zh: Record<string, string> = {
|
|
|
191
194
|
'files.cutClipboard': '已剪切到剪贴板',
|
|
192
195
|
'files.copyRel': '复制相对路径',
|
|
193
196
|
'files.copyAbs': '复制绝对路径',
|
|
197
|
+
'files.download': '下载到本地',
|
|
198
|
+
'downloads.running': '下载中',
|
|
199
|
+
'downloads.done': '下载完成',
|
|
200
|
+
'downloads.failed': '下载失败',
|
|
201
|
+
'downloads.cancelled': '已取消',
|
|
202
|
+
'downloads.cancel': '取消下载',
|
|
203
|
+
'downloads.close': '关闭',
|
|
204
|
+
'downloads.browserDefault': '已保存到浏览器默认下载目录',
|
|
205
|
+
'downloads.indeterminate': '正在打包…',
|
|
206
|
+
'downloads.tooMany': '选择项过多(最多 100 项),请改为下载所在目录',
|
|
194
207
|
'files.copied': '已复制',
|
|
195
208
|
'files.moved': '已移动',
|
|
196
209
|
'files.pasteFailed': '操作失败',
|
|
@@ -608,6 +621,16 @@ const en: Record<string, string> = {
|
|
|
608
621
|
'files.cutClipboard': 'Cut to clipboard',
|
|
609
622
|
'files.copyRel': 'Copy relative path',
|
|
610
623
|
'files.copyAbs': 'Copy absolute path',
|
|
624
|
+
'files.download': 'Download to Local',
|
|
625
|
+
'downloads.running': 'Downloading',
|
|
626
|
+
'downloads.done': 'Downloaded',
|
|
627
|
+
'downloads.failed': 'Download failed',
|
|
628
|
+
'downloads.cancelled': 'Cancelled',
|
|
629
|
+
'downloads.cancel': 'Cancel download',
|
|
630
|
+
'downloads.close': 'Dismiss',
|
|
631
|
+
'downloads.browserDefault': 'Saved to the browser download folder',
|
|
632
|
+
'downloads.indeterminate': 'Packaging…',
|
|
633
|
+
'downloads.tooMany': 'Too many entries (max 100); download the containing folder instead',
|
|
611
634
|
'files.copied': 'Copied',
|
|
612
635
|
'files.moved': 'Moved',
|
|
613
636
|
'files.pasteFailed': 'operation failed',
|
package/src/client/vsc/vsc.css
CHANGED
|
@@ -3604,3 +3604,127 @@ body[data-ds-dark-theme] .rvs-execpanel {
|
|
|
3604
3604
|
font-size: 11px;
|
|
3605
3605
|
}
|
|
3606
3606
|
|
|
3607
|
+
/* --------------------------------------------------------- download dock */
|
|
3608
|
+
/* PORTALed to <body>, i.e. OUTSIDE `.rvs-root` where the tokens are declared:
|
|
3609
|
+
declare the subset this panel uses (same rule as `.rvs-execpanel`). */
|
|
3610
|
+
.rvs-downloads {
|
|
3611
|
+
--rvs-fg: var(--dsw-alias-label-primary, #e6e6e6);
|
|
3612
|
+
--rvs-fg2: var(--dsw-alias-label-secondary, #b9b9b9);
|
|
3613
|
+
--rvs-fg3: var(--dsw-alias-label-tertiary, #8b8b8b);
|
|
3614
|
+
--rvs-border: var(--dsw-alias-border-l1, rgba(127, 127, 127, .25));
|
|
3615
|
+
--rvs-border2: var(--dsw-alias-border-l2, rgba(127, 127, 127, .38));
|
|
3616
|
+
--rvs-overlay: var(--dsw-alias-bg-overlay, #24262e);
|
|
3617
|
+
--rvs-brand: var(--dsw-alias-brand-primary, #4d6bfe);
|
|
3618
|
+
--rvs-danger: var(--dsw-alias-state-error-primary, #e05555);
|
|
3619
|
+
--rvs-git-m: #e2b714;
|
|
3620
|
+
--rvs-git-a: #4ec9b0;
|
|
3621
|
+
position: fixed;
|
|
3622
|
+
/* Bottom-RIGHT, not over the sidebar's own footer (first screenshot: the
|
|
3623
|
+
dock sat on the usage/account block). `bottom: 64px` keeps it above the
|
|
3624
|
+
transient toast stack (right 16 / bottom 18 / z 100001) and above the
|
|
3625
|
+
network exec panel (right 16 / bottom 16 / z 45), so neither covers it. */
|
|
3626
|
+
right: 16px;
|
|
3627
|
+
bottom: 64px;
|
|
3628
|
+
z-index: 100000;
|
|
3629
|
+
animation: rvsFade .12s ease;
|
|
3630
|
+
width: min(380px, calc(100vw - 32px));
|
|
3631
|
+
max-height: min(45vh, 420px);
|
|
3632
|
+
overflow-y: auto;
|
|
3633
|
+
display: flex;
|
|
3634
|
+
flex-direction: column;
|
|
3635
|
+
gap: 6px;
|
|
3636
|
+
padding: 8px;
|
|
3637
|
+
border: 1px solid var(--rvs-border2);
|
|
3638
|
+
border-radius: 10px;
|
|
3639
|
+
background: var(--rvs-overlay);
|
|
3640
|
+
color: var(--rvs-fg);
|
|
3641
|
+
box-shadow: 0 18px 60px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .28);
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
.rvs-download {
|
|
3645
|
+
display: flex;
|
|
3646
|
+
flex-direction: column;
|
|
3647
|
+
gap: 4px;
|
|
3648
|
+
padding: 6px 8px;
|
|
3649
|
+
border: 1px solid var(--rvs-border);
|
|
3650
|
+
border-radius: 8px;
|
|
3651
|
+
background: rgba(127, 127, 127, .06);
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3654
|
+
.rvs-download-head {
|
|
3655
|
+
display: flex;
|
|
3656
|
+
align-items: center;
|
|
3657
|
+
gap: 6px;
|
|
3658
|
+
min-width: 0;
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
.rvs-download-icon {
|
|
3662
|
+
flex: none;
|
|
3663
|
+
display: flex;
|
|
3664
|
+
align-items: center;
|
|
3665
|
+
color: var(--rvs-fg2);
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
.rvs-download-name {
|
|
3669
|
+
flex: 1;
|
|
3670
|
+
min-width: 0;
|
|
3671
|
+
overflow: hidden;
|
|
3672
|
+
text-overflow: ellipsis;
|
|
3673
|
+
white-space: nowrap;
|
|
3674
|
+
font-size: 12px;
|
|
3675
|
+
font-weight: 600;
|
|
3676
|
+
}
|
|
3677
|
+
|
|
3678
|
+
.rvs-download-status {
|
|
3679
|
+
flex: none;
|
|
3680
|
+
font-size: 11px;
|
|
3681
|
+
color: var(--rvs-fg3);
|
|
3682
|
+
}
|
|
3683
|
+
|
|
3684
|
+
.rvs-download-status.done { color: var(--rvs-git-a); }
|
|
3685
|
+
.rvs-download-status.failed { color: var(--rvs-danger); }
|
|
3686
|
+
.rvs-download-status.cancelled { color: var(--rvs-git-m); }
|
|
3687
|
+
|
|
3688
|
+
.rvs-download-bar {
|
|
3689
|
+
height: 4px;
|
|
3690
|
+
overflow: hidden;
|
|
3691
|
+
border-radius: 2px;
|
|
3692
|
+
background: rgba(127, 127, 127, .22);
|
|
3693
|
+
}
|
|
3694
|
+
|
|
3695
|
+
.rvs-download-fill {
|
|
3696
|
+
height: 100%;
|
|
3697
|
+
width: 0;
|
|
3698
|
+
border-radius: 2px;
|
|
3699
|
+
background: var(--rvs-brand);
|
|
3700
|
+
transition: width .12s linear;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
.rvs-download-fill.indeterminate {
|
|
3704
|
+
width: 35%;
|
|
3705
|
+
animation: rvs-download-slide 1.2s ease-in-out infinite;
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
@keyframes rvs-download-slide {
|
|
3709
|
+
from { transform: translateX(-120%); }
|
|
3710
|
+
to { transform: translateX(320%); }
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3713
|
+
@media (prefers-reduced-motion: reduce) {
|
|
3714
|
+
.rvs-download-fill.indeterminate { animation-duration: 2.4s; }
|
|
3715
|
+
.rvs-download-fill { transition: none; }
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
.rvs-download-meta {
|
|
3719
|
+
overflow: hidden;
|
|
3720
|
+
color: var(--rvs-fg3);
|
|
3721
|
+
font-size: 11px;
|
|
3722
|
+
text-overflow: ellipsis;
|
|
3723
|
+
white-space: nowrap;
|
|
3724
|
+
}
|
|
3725
|
+
|
|
3726
|
+
.rvs-download-meta.failed { color: var(--rvs-danger); white-space: normal; word-break: break-word; }
|
|
3727
|
+
.rvs-download-meta.done { color: var(--rvs-fg2); }
|
|
3728
|
+
.rvs-download-meta.cancelled { color: var(--rvs-git-m); }
|
|
3729
|
+
|
|
3730
|
+
|