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
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as pushPipeline, c as
|
|
1
|
+
import { a as pushPipeline, c as attachmentHeader, d as dshHome, f as ensurePrivateDir, i as probe, l as require_lib, m as storePath, o as seedHelperCache, p as keysDir, r as helperAvailability, s as RemoteFiles, t as RemoteWorlds, u as aliasRoot } from "./worlds-oj65Hic-.js";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeSync } from "node:fs";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
5
|
+
import { dirname, join, posix } from "node:path";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { StringDecoder } from "node:string_decoder";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
@@ -1137,6 +1137,12 @@ const REMOTE_API = {
|
|
|
1137
1137
|
files: "/api/dsh-remote/files",
|
|
1138
1138
|
/** Streaming binary upload: raw request body, host and path in the query. */
|
|
1139
1139
|
upload: "/api/dsh-remote/upload",
|
|
1140
|
+
/** Streaming binary download: raw response body, host and path in the query. */
|
|
1141
|
+
download: "/api/dsh-remote/download",
|
|
1142
|
+
/** Streaming directory download: a remote `tar -czf -` of the directory. */
|
|
1143
|
+
downloadDir: "/api/dsh-remote/download-dir",
|
|
1144
|
+
/** Streaming multi-selection download: one remote tar of repeated `path` params. */
|
|
1145
|
+
downloadMany: "/api/dsh-remote/download-many",
|
|
1140
1146
|
workspaces: "/api/dsh-remote/workspaces",
|
|
1141
1147
|
deploy: "/api/dsh-remote/deploy",
|
|
1142
1148
|
importSshConfig: "/api/dsh-remote/import-ssh-config",
|
|
@@ -1149,6 +1155,71 @@ const REMOTE_API = {
|
|
|
1149
1155
|
/** What one live session changed on its remote host (the review panel). */
|
|
1150
1156
|
changes: "/api/dsh-remote/changes"
|
|
1151
1157
|
};
|
|
1158
|
+
/** Suggested/attachment file name for one multi-selection archive. */
|
|
1159
|
+
function selectionDownloadName(count) {
|
|
1160
|
+
return `selection-${count}.tar.gz`;
|
|
1161
|
+
}
|
|
1162
|
+
//#endregion
|
|
1163
|
+
//#region src/git-format.ts
|
|
1164
|
+
/** Wrap a value for POSIX sh single-quote context. */
|
|
1165
|
+
function shQuote(value) {
|
|
1166
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
1167
|
+
}
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region src/archive.ts
|
|
1170
|
+
/**
|
|
1171
|
+
* Remote directory archiving for the download route.
|
|
1172
|
+
*
|
|
1173
|
+
* The archive is produced ON the remote host (`tar -czf -`) and streamed
|
|
1174
|
+
* straight into the HTTP response, so the Host never builds it in memory or
|
|
1175
|
+
* writes it to its own disk. Pure string builders (no fs, no exec) so the
|
|
1176
|
+
* download gate can pin the exact command shape.
|
|
1177
|
+
*/
|
|
1178
|
+
/** Download file name for one archived directory. */
|
|
1179
|
+
function directoryArchiveName(dir) {
|
|
1180
|
+
const trimmed = String(dir).replace(/[\\/]+$/, "");
|
|
1181
|
+
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
1182
|
+
const base = at < 0 ? trimmed : trimmed.slice(at + 1);
|
|
1183
|
+
return `${base === "" ? "root" : base}.tar.gz`;
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* One POSIX shell command that writes the directory's gzip tar to stdout.
|
|
1187
|
+
*
|
|
1188
|
+
* The member name is prefixed with `./` so a directory whose name starts with
|
|
1189
|
+
* `-` cannot be read as a tar option; `-C` names the parent instead of relying
|
|
1190
|
+
* on a shell `cd`, and both paths are single-quoted (`shQuote`) so spaces,
|
|
1191
|
+
* quotes and `$()` in a real path cannot escape into the command.
|
|
1192
|
+
*/
|
|
1193
|
+
function directoryArchiveCommand(dir) {
|
|
1194
|
+
const path = String(dir).replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1195
|
+
if (path === "" || path === "/") throw new Error("refusing to archive the remote root");
|
|
1196
|
+
if (!path.startsWith("/")) throw new Error("remote path must be absolute");
|
|
1197
|
+
const parent = posix.dirname(path);
|
|
1198
|
+
const name = posix.basename(path);
|
|
1199
|
+
return `tar -czf - -C ${shQuote(parent)} ${shQuote(`./${name}`)}`;
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* One POSIX shell command archiving several selected paths to stdout.
|
|
1203
|
+
*
|
|
1204
|
+
* GNU tar accepts one `-C` before each member, so every entry is stored as its
|
|
1205
|
+
* own bare `./name` while keeping its real parent on the remote side; that is
|
|
1206
|
+
* what lets a selection span several directories (mixed files and directories
|
|
1207
|
+
* are fine — tar recurses into directories). Two entries with the same basename
|
|
1208
|
+
* from different directories collide inside the archive by design: the
|
|
1209
|
+
* alternative would be a synthetic directory tree the remote never had.
|
|
1210
|
+
*/
|
|
1211
|
+
function selectionArchiveCommand(paths) {
|
|
1212
|
+
if (paths.length === 0) throw new Error("refusing to archive an empty selection");
|
|
1213
|
+
if (paths.length > 100) throw new Error(`too many entries: ${paths.length} (max 100)`);
|
|
1214
|
+
let command = "tar -czf -";
|
|
1215
|
+
for (const raw of paths) {
|
|
1216
|
+
const path = String(raw).replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1217
|
+
if (path === "" || path === "/") throw new Error("refusing to archive the remote root");
|
|
1218
|
+
if (!path.startsWith("/")) throw new Error("remote path must be absolute");
|
|
1219
|
+
command += ` -C ${shQuote(posix.dirname(path))} ${shQuote(`./${posix.basename(path)}`)}`;
|
|
1220
|
+
}
|
|
1221
|
+
return command;
|
|
1222
|
+
}
|
|
1152
1223
|
//#endregion
|
|
1153
1224
|
//#region src/keygen.ts
|
|
1154
1225
|
/**
|
|
@@ -1764,6 +1835,78 @@ function makeRoutes(deps) {
|
|
|
1764
1835
|
const timeouts = () => deps.timeouts?.() ?? DEFAULT_TIMEOUTS;
|
|
1765
1836
|
const files = new RemoteFiles(pool);
|
|
1766
1837
|
const terminalSessions = new TerminalSessionRegistry(pool);
|
|
1838
|
+
/**
|
|
1839
|
+
* Stream one remote `tar -czf -` command into a `.tar.gz` download response.
|
|
1840
|
+
*
|
|
1841
|
+
* Shared by the directory and multi-selection routes (they differ only in the
|
|
1842
|
+
* command and the attachment name). The archive is produced remotely; the
|
|
1843
|
+
* response has no length, backpressure pauses the channel, and a non-zero tar
|
|
1844
|
+
* exit destroys the response with the stderr tail.
|
|
1845
|
+
*/
|
|
1846
|
+
const streamArchive = async (alias, command, res, downloadName) => {
|
|
1847
|
+
let channel;
|
|
1848
|
+
try {
|
|
1849
|
+
channel = await pool.execChannel(alias, command);
|
|
1850
|
+
} catch (error) {
|
|
1851
|
+
writeJson(res, 502, { error: error instanceof Error ? error.message : String(error) });
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
res.writeHead(200, {
|
|
1855
|
+
"content-type": "application/gzip",
|
|
1856
|
+
"content-disposition": attachmentHeader(downloadName),
|
|
1857
|
+
"cache-control": "no-store",
|
|
1858
|
+
"x-content-type-options": "nosniff"
|
|
1859
|
+
});
|
|
1860
|
+
let closed = false;
|
|
1861
|
+
/** `undefined` until the remote process reports one. */
|
|
1862
|
+
let exitCode;
|
|
1863
|
+
let stderr = "";
|
|
1864
|
+
/** Finish once: end on success, destroy on failure, close the remote channel either way. */
|
|
1865
|
+
const stop = (error) => {
|
|
1866
|
+
if (closed) return;
|
|
1867
|
+
closed = true;
|
|
1868
|
+
try {
|
|
1869
|
+
channel.close();
|
|
1870
|
+
} catch {}
|
|
1871
|
+
if (error === void 0) {
|
|
1872
|
+
try {
|
|
1873
|
+
res.end();
|
|
1874
|
+
} catch {}
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
res.destroy(error);
|
|
1878
|
+
};
|
|
1879
|
+
channel.stdout.on("data", (chunk) => {
|
|
1880
|
+
if (closed) return;
|
|
1881
|
+
try {
|
|
1882
|
+
if (!res.write(chunk)) channel.stdout.pause();
|
|
1883
|
+
} catch (error) {
|
|
1884
|
+
stop(error instanceof Error ? error : new Error(String(error)));
|
|
1885
|
+
}
|
|
1886
|
+
});
|
|
1887
|
+
res.on("drain", () => {
|
|
1888
|
+
if (!closed) try {
|
|
1889
|
+
channel.stdout.resume();
|
|
1890
|
+
} catch {}
|
|
1891
|
+
});
|
|
1892
|
+
channel.stderr.on("data", (chunk) => {
|
|
1893
|
+
if (stderr.length < 16384) stderr += chunk.toString("utf8");
|
|
1894
|
+
});
|
|
1895
|
+
channel.on("error", (error) => stop(error));
|
|
1896
|
+
channel.on("exit", (code) => {
|
|
1897
|
+
exitCode = code;
|
|
1898
|
+
});
|
|
1899
|
+
channel.on("close", () => {
|
|
1900
|
+
if (closed) return;
|
|
1901
|
+
if (exitCode !== 0) {
|
|
1902
|
+
const detail = stderr.trim() === "" ? "no stderr" : stderr.trim().slice(0, 400);
|
|
1903
|
+
stop(/* @__PURE__ */ new Error(`tar failed (${exitCode === null ? "signal" : exitCode}): ${detail}`));
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
stop();
|
|
1907
|
+
});
|
|
1908
|
+
res.on("close", () => stop());
|
|
1909
|
+
};
|
|
1767
1910
|
/** Apply parsed import payloads; per-entry errors become skips. */
|
|
1768
1911
|
const applyImport = (parsed) => {
|
|
1769
1912
|
const imported = [];
|
|
@@ -2151,6 +2294,113 @@ function makeRoutes(deps) {
|
|
|
2151
2294
|
}
|
|
2152
2295
|
}
|
|
2153
2296
|
},
|
|
2297
|
+
{
|
|
2298
|
+
kind: "exact",
|
|
2299
|
+
path: REMOTE_API.download,
|
|
2300
|
+
handler: async (req, res) => {
|
|
2301
|
+
if (!isLoopbackRequest(req)) {
|
|
2302
|
+
writeJson(res, 403, { error: "forbidden: loopback-only" });
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
if (req.method !== "GET") {
|
|
2306
|
+
writeJson(res, 405, { error: `method not allowed: ${req.method}` });
|
|
2307
|
+
return;
|
|
2308
|
+
}
|
|
2309
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
2310
|
+
const alias = url.searchParams.get("alias") ?? "";
|
|
2311
|
+
const path = url.searchParams.get("path") ?? "";
|
|
2312
|
+
if (alias === "" || path === "") {
|
|
2313
|
+
writeJson(res, 400, { error: "alias and path query parameters are required" });
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
if (!path.startsWith("/")) {
|
|
2317
|
+
writeJson(res, 400, { error: `path must be absolute: ${path}` });
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
try {
|
|
2321
|
+
await files.download(alias, path, res);
|
|
2322
|
+
} catch (error) {
|
|
2323
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2324
|
+
if (!res.headersSent && !res.destroyed) writeJson(res, 502, { error: message });
|
|
2325
|
+
else res.destroy(error instanceof Error ? error : void 0);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
},
|
|
2329
|
+
{
|
|
2330
|
+
kind: "exact",
|
|
2331
|
+
path: REMOTE_API.downloadDir,
|
|
2332
|
+
handler: async (req, res) => {
|
|
2333
|
+
if (!isLoopbackRequest(req)) {
|
|
2334
|
+
writeJson(res, 403, { error: "forbidden: loopback-only" });
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
if (req.method !== "GET") {
|
|
2338
|
+
writeJson(res, 405, { error: `method not allowed: ${req.method}` });
|
|
2339
|
+
return;
|
|
2340
|
+
}
|
|
2341
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
2342
|
+
const alias = url.searchParams.get("alias") ?? "";
|
|
2343
|
+
const path = url.searchParams.get("path") ?? "";
|
|
2344
|
+
if (alias === "" || path === "") {
|
|
2345
|
+
writeJson(res, 400, { error: "alias and path query parameters are required" });
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
if (!path.startsWith("/")) {
|
|
2349
|
+
writeJson(res, 400, { error: `path must be absolute: ${path}` });
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
let command;
|
|
2353
|
+
try {
|
|
2354
|
+
if (!(await files.stat(alias, path)).isDir) {
|
|
2355
|
+
writeJson(res, 400, { error: `not a directory: ${path}` });
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
command = directoryArchiveCommand(path);
|
|
2359
|
+
} catch (error) {
|
|
2360
|
+
writeJson(res, 502, { error: error instanceof Error ? error.message : String(error) });
|
|
2361
|
+
return;
|
|
2362
|
+
}
|
|
2363
|
+
await streamArchive(alias, command, res, directoryArchiveName(path));
|
|
2364
|
+
}
|
|
2365
|
+
},
|
|
2366
|
+
{
|
|
2367
|
+
kind: "exact",
|
|
2368
|
+
path: REMOTE_API.downloadMany,
|
|
2369
|
+
handler: async (req, res) => {
|
|
2370
|
+
if (!isLoopbackRequest(req)) {
|
|
2371
|
+
writeJson(res, 403, { error: "forbidden: loopback-only" });
|
|
2372
|
+
return;
|
|
2373
|
+
}
|
|
2374
|
+
if (req.method !== "GET") {
|
|
2375
|
+
writeJson(res, 405, { error: `method not allowed: ${req.method}` });
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
2379
|
+
const alias = url.searchParams.get("alias") ?? "";
|
|
2380
|
+
const paths = url.searchParams.getAll("path");
|
|
2381
|
+
if (alias === "" || paths.length === 0) {
|
|
2382
|
+
writeJson(res, 400, { error: "alias and at least one path query parameter are required" });
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
if (paths.length > 100) {
|
|
2386
|
+
writeJson(res, 400, { error: `too many entries: ${paths.length} (max 100)` });
|
|
2387
|
+
return;
|
|
2388
|
+
}
|
|
2389
|
+
for (const path of paths) if (!path.startsWith("/")) {
|
|
2390
|
+
writeJson(res, 400, { error: `path must be absolute: ${path}` });
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
let command;
|
|
2394
|
+
try {
|
|
2395
|
+
for (const path of paths) await files.stat(alias, path);
|
|
2396
|
+
command = selectionArchiveCommand(paths);
|
|
2397
|
+
} catch (error) {
|
|
2398
|
+
writeJson(res, 502, { error: error instanceof Error ? error.message : String(error) });
|
|
2399
|
+
return;
|
|
2400
|
+
}
|
|
2401
|
+
await streamArchive(alias, command, res, selectionDownloadName(paths.length));
|
|
2402
|
+
}
|
|
2403
|
+
},
|
|
2154
2404
|
{
|
|
2155
2405
|
kind: "exact",
|
|
2156
2406
|
path: REMOTE_API.workspaces,
|
package/lib/p2-router-fs.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote directory archiving for the download route.
|
|
3
|
+
*
|
|
4
|
+
* The archive is produced ON the remote host (`tar -czf -`) and streamed
|
|
5
|
+
* straight into the HTTP response, so the Host never builds it in memory or
|
|
6
|
+
* writes it to its own disk. Pure string builders (no fs, no exec) so the
|
|
7
|
+
* download gate can pin the exact command shape.
|
|
8
|
+
*/
|
|
9
|
+
/** Download file name for one archived directory. */
|
|
10
|
+
export declare function directoryArchiveName(dir: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* One POSIX shell command that writes the directory's gzip tar to stdout.
|
|
13
|
+
*
|
|
14
|
+
* The member name is prefixed with `./` so a directory whose name starts with
|
|
15
|
+
* `-` cannot be read as a tar option; `-C` names the parent instead of relying
|
|
16
|
+
* on a shell `cd`, and both paths are single-quoted (`shQuote`) so spaces,
|
|
17
|
+
* quotes and `$()` in a real path cannot escape into the command.
|
|
18
|
+
*/
|
|
19
|
+
export declare function directoryArchiveCommand(dir: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* One POSIX shell command archiving several selected paths to stdout.
|
|
22
|
+
*
|
|
23
|
+
* GNU tar accepts one `-C` before each member, so every entry is stored as its
|
|
24
|
+
* own bare `./name` while keeping its real parent on the remote side; that is
|
|
25
|
+
* what lets a selection span several directories (mixed files and directories
|
|
26
|
+
* are fine — tar recurses into directories). Two entries with the same basename
|
|
27
|
+
* from different directories collide inside the archive by design: the
|
|
28
|
+
* alternative would be a synthetic directory tree the remote never had.
|
|
29
|
+
*/
|
|
30
|
+
export declare function selectionArchiveCommand(paths: readonly string[]): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download progress dock.
|
|
3
|
+
*
|
|
4
|
+
* Rendered through a PORTAL on `document.body`: the dock starts inside the
|
|
5
|
+
* sidebar's keep-alive slot, and a `position: fixed` descendant of a hidden
|
|
6
|
+
* ancestor disappears with it — which would take the progress bar (and the
|
|
7
|
+
* cancel button) of a running download along when the user switches rail views.
|
|
8
|
+
*
|
|
9
|
+
* The runner lives in `downloads.ts`, outside React, so an unmount of this
|
|
10
|
+
* component never interrupts a transfer; the dock only reads its snapshot.
|
|
11
|
+
*/
|
|
12
|
+
import { type ReactNode } from 'react';
|
|
13
|
+
export declare function DownloadDock(props: {
|
|
14
|
+
t: (key: string) => string;
|
|
15
|
+
}): ReactNode;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download one remote file or directory to the local machine.
|
|
3
|
+
*
|
|
4
|
+
* The Host streams the bytes over `REMOTE_API.download` (file) or
|
|
5
|
+
* `REMOTE_API.downloadDir` (one remote `tar -czf -` archive). When the browser
|
|
6
|
+
* offers the File System Access API the user picks the destination in a native
|
|
7
|
+
* "save as" dialog and the response body is written chunk by chunk into that
|
|
8
|
+
* file — streamed, never assembled into a Blob — which is also what feeds the
|
|
9
|
+
* progress meter. Without the API (Firefox, some Electron shells) the download
|
|
10
|
+
* falls back to an anchor click, i.e. the browser's configured download folder,
|
|
11
|
+
* with no progress to report.
|
|
12
|
+
*
|
|
13
|
+
* The runner (`downloads.ts`) preflights with `files` op=stat, so a vanished or
|
|
14
|
+
* unreadable path shows the Host's real error instead of an empty saved file.
|
|
15
|
+
*/
|
|
16
|
+
/** What one download attempt ended as. */
|
|
17
|
+
export type DownloadOutcome = 'saved' | 'downloaded';
|
|
18
|
+
/** One progress sample: `total` is absent for a streamed archive (chunked). */
|
|
19
|
+
export interface DownloadProgress {
|
|
20
|
+
loaded: number;
|
|
21
|
+
total?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Hooks the runner uses for the progress panel and its cancel button. */
|
|
24
|
+
export interface SaveOptions {
|
|
25
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}
|
|
28
|
+
/** File name a remote POSIX path should be saved as. */
|
|
29
|
+
export declare function downloadFileName(path: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Same-origin URL of the streaming download route for one remote file.
|
|
32
|
+
*
|
|
33
|
+
* Deliberately RELATIVE, including on Desktop: the page origin there is
|
|
34
|
+
* `dsh-app://app` and the Electron shell proxies app-origin HTTP to its Host,
|
|
35
|
+
* so the click stays same-origin (the `download` attribute applies) and passes
|
|
36
|
+
* the route's loopback/same-origin fence. Naming the published loopback origin
|
|
37
|
+
* instead would make it a cross-site GET, which that fence rejects.
|
|
38
|
+
*/
|
|
39
|
+
export declare function downloadUrl(alias: string, path: string): string;
|
|
40
|
+
/** Same-origin URL of the streaming directory-archive route. */
|
|
41
|
+
export declare function downloadDirUrl(alias: string, path: string): string;
|
|
42
|
+
/** Same-origin URL of the multi-selection archive route (one `path` per entry). */
|
|
43
|
+
export declare function downloadManyUrl(alias: string, paths: readonly string[]): string;
|
|
44
|
+
/**
|
|
45
|
+
* Hand one download to the browser (fallback when no save picker exists).
|
|
46
|
+
*
|
|
47
|
+
* The element is attached to the document on purpose: a detached anchor is
|
|
48
|
+
* ignored by some Chromium versions, and Desktop's shell hooks the download at
|
|
49
|
+
* the document level.
|
|
50
|
+
*/
|
|
51
|
+
export declare function triggerDownload(href: string, fileName: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Save one streamed URL to a destination the user picks.
|
|
54
|
+
*
|
|
55
|
+
* The picker runs while the click's transient activation is still valid, so it
|
|
56
|
+
* must come before the network work. A picker that refuses the call (expired
|
|
57
|
+
* activation, policy) falls back to the browser download flow instead of
|
|
58
|
+
* failing the download outright.
|
|
59
|
+
*
|
|
60
|
+
* @returns `'saved'` for the picked destination, `'downloaded'` for the
|
|
61
|
+
* browser-default fallback.
|
|
62
|
+
*/
|
|
63
|
+
export declare function saveRemoteUrl(href: string, fileName: string, options?: SaveOptions): Promise<DownloadOutcome>;
|
|
64
|
+
/** Save one remote file (fresh name from its POSIX basename). */
|
|
65
|
+
export declare function saveRemoteFile(alias: string, path: string, options?: SaveOptions): Promise<DownloadOutcome>;
|
|
66
|
+
/** Save one remote directory as a single `.tar.gz`. */
|
|
67
|
+
export declare function saveRemoteDir(alias: string, path: string, options?: SaveOptions): Promise<DownloadOutcome>;
|
|
68
|
+
/** Save several selected entries as one `.tar.gz` archive. */
|
|
69
|
+
export declare function saveRemoteMany(alias: string, paths: readonly string[], options?: SaveOptions): Promise<DownloadOutcome>;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
/** One download's lifecycle state. */
|
|
11
|
+
export type DownloadStatus = 'running' | 'done' | 'failed' | 'cancelled';
|
|
12
|
+
/** One task as the dock renders it. */
|
|
13
|
+
export interface DownloadTask {
|
|
14
|
+
id: string;
|
|
15
|
+
/** Basename of the remote path (or `selection-N` for a multi-selection). */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Resolved from the stat preflight; `hint.directory` until then. */
|
|
18
|
+
directory: boolean;
|
|
19
|
+
/** Entries in a multi-selection archive; absent for a single path. */
|
|
20
|
+
selection?: number;
|
|
21
|
+
status: DownloadStatus;
|
|
22
|
+
loaded: number;
|
|
23
|
+
/** Absent for a streamed archive (chunked, size unknown). */
|
|
24
|
+
total?: number;
|
|
25
|
+
/** Failure text, or the note shown for the browser-default fallback. */
|
|
26
|
+
error?: string;
|
|
27
|
+
/** `browserDefault` means no save dialog existed and the file went to Downloads. */
|
|
28
|
+
via?: 'picker' | 'browserDefault';
|
|
29
|
+
startedAt: number;
|
|
30
|
+
finishedAt?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Human byte size for the progress line. */
|
|
33
|
+
export declare function formatByteCount(bytes: number): string;
|
|
34
|
+
/** Store surface: `useSyncExternalStore(subscribe, getSnapshot, getSnapshot)`. */
|
|
35
|
+
export declare const downloadsStore: {
|
|
36
|
+
subscribe(listener: () => void): () => void;
|
|
37
|
+
getSnapshot(): readonly DownloadTask[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Start one download (file or directory) and return its task id.
|
|
41
|
+
*
|
|
42
|
+
* The stat preflight runs here — not in the menus — so a deleted/unreadable
|
|
43
|
+
* remote path becomes a failed task with the Host's real message, and the
|
|
44
|
+
* file-vs-directory decision comes from the Host rather than a possibly stale
|
|
45
|
+
* tree row.
|
|
46
|
+
*/
|
|
47
|
+
export declare function startDownload(alias: string, path: string, hint: {
|
|
48
|
+
name: string;
|
|
49
|
+
directory: boolean;
|
|
50
|
+
}): string;
|
|
51
|
+
/**
|
|
52
|
+
* Start one multi-selection download.
|
|
53
|
+
*
|
|
54
|
+
* The Host archives every selected entry into a single `.tar.gz`, so the user
|
|
55
|
+
* picks one destination instead of answering N save dialogs; mixed files and
|
|
56
|
+
* directories are fine (tar recurses). Entry validation happens Host-side
|
|
57
|
+
* before the archive starts, so no client preflight round trip is needed.
|
|
58
|
+
*/
|
|
59
|
+
export declare function startSelectionDownload(alias: string, paths: readonly string[]): string;
|
|
60
|
+
/** Cancel one running download (the panel's stop button). */
|
|
61
|
+
export declare function cancelDownload(id: string): void;
|
|
62
|
+
/** Drop one task from the dock (finished tasks only in practice). */
|
|
63
|
+
export declare function dismissDownload(id: string): void;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* them here keeps the check meaningful in both directions: every entry must
|
|
12
12
|
* exist in both dictionaries, and nothing else may be unreferenced.
|
|
13
13
|
*/
|
|
14
|
-
export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff"];
|
|
14
|
+
export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running"];
|
|
15
15
|
export type Lang = 'zh' | 'en';
|
|
16
16
|
export declare function detectLang(): Lang;
|
|
17
17
|
export declare function makeT(lang: Lang): (key: string) => string;
|
package/lib/types/protocol.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export declare const REMOTE_API: {
|
|
|
14
14
|
readonly files: "/api/dsh-remote/files";
|
|
15
15
|
/** Streaming binary upload: raw request body, host and path in the query. */
|
|
16
16
|
readonly upload: "/api/dsh-remote/upload";
|
|
17
|
+
/** Streaming binary download: raw response body, host and path in the query. */
|
|
18
|
+
readonly download: "/api/dsh-remote/download";
|
|
19
|
+
/** Streaming directory download: a remote `tar -czf -` of the directory. */
|
|
20
|
+
readonly downloadDir: "/api/dsh-remote/download-dir";
|
|
21
|
+
/** Streaming multi-selection download: one remote tar of repeated `path` params. */
|
|
22
|
+
readonly downloadMany: "/api/dsh-remote/download-many";
|
|
17
23
|
readonly workspaces: "/api/dsh-remote/workspaces";
|
|
18
24
|
readonly deploy: "/api/dsh-remote/deploy";
|
|
19
25
|
readonly importSshConfig: "/api/dsh-remote/import-ssh-config";
|
|
@@ -26,6 +32,14 @@ export declare const REMOTE_API: {
|
|
|
26
32
|
/** What one live session changed on its remote host (the review panel). */
|
|
27
33
|
readonly changes: "/api/dsh-remote/changes";
|
|
28
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Most entries one multi-selection download may archive. The selection rides in
|
|
37
|
+
* the request URL (one `path` param per entry), so this bounds both the archive
|
|
38
|
+
* and the request line; a larger selection should download its folder instead.
|
|
39
|
+
*/
|
|
40
|
+
export declare const MAX_SELECTION_DOWNLOAD = 100;
|
|
41
|
+
/** Suggested/attachment file name for one multi-selection archive. */
|
|
42
|
+
export declare function selectionDownloadName(count: number): string;
|
|
29
43
|
/** Authentication flavors a host entry may carry (P0: direct only, no jump/agent). */
|
|
30
44
|
export type RemoteAuthKind = 'key' | 'password';
|
|
31
45
|
/** One stored host entry (the $DSH_HOME/dsh-remote.json store shape). */
|
package/lib/types/sftp.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
|
1
2
|
import type { RemotePool } from './pool.ts';
|
|
2
3
|
import type { RemoteFileEntry, RemoteRead } from './protocol.ts';
|
|
3
4
|
/** Single-read cap (matches the fs-ssh 8 MiB window). */
|
|
@@ -13,8 +14,27 @@ export declare const READ_CAP: number;
|
|
|
13
14
|
export declare const LIST_ENTRY_CAP = 20000;
|
|
14
15
|
/** Largest single upload accepted (matches the client-side planner cap). */
|
|
15
16
|
export declare const UPLOAD_MAX_BYTES: number;
|
|
17
|
+
/**
|
|
18
|
+
* How long one download stream may make no progress before it is failed.
|
|
19
|
+
*
|
|
20
|
+
* A download has no wall-clock budget for the same reason an upload does not: a
|
|
21
|
+
* big file on a slow link is healthy for minutes. What must never happen is a
|
|
22
|
+
* silently dead stream pinning the SFTP session (and its channel slot) forever,
|
|
23
|
+
* so progress is the bound — any chunk resets this clock.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DOWNLOAD_IDLE_MS = 60000;
|
|
16
26
|
/** Assert an absolute POSIX remote path and return its normalized form. */
|
|
17
27
|
export declare function remotePath(path: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* `Content-Disposition` for one attachment (RFC 6266 + RFC 5987).
|
|
30
|
+
*
|
|
31
|
+
* Receivers prefer `filename*` when both forms are present (RFC 6266 §4.3),
|
|
32
|
+
* which is why a non-ASCII remote name survives the round trip; the quoted
|
|
33
|
+
* ASCII copy is the fallback for clients that do not understand the extended
|
|
34
|
+
* form. Quotes and backslashes are stripped from that fallback so they cannot
|
|
35
|
+
* break the header.
|
|
36
|
+
*/
|
|
37
|
+
export declare function attachmentHeader(fileName: string): string;
|
|
18
38
|
export declare class RemoteFiles {
|
|
19
39
|
private readonly pool;
|
|
20
40
|
/**
|
|
@@ -57,6 +77,24 @@ export declare class RemoteFiles {
|
|
|
57
77
|
upload(alias: string, file: string, source: NodeJS.ReadableStream, maxBytes?: number, overwrite?: boolean): Promise<{
|
|
58
78
|
size: number;
|
|
59
79
|
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Stream one remote file into an HTTP response (download to the local machine).
|
|
82
|
+
*
|
|
83
|
+
* Streaming, not `read()`: `read()` caps at 8 MiB because it answers a JSON
|
|
84
|
+
* editor read, while a download is whatever the user pointed at — a log, a
|
|
85
|
+
* binary, an artifact. The file is opened through one SFTP handle before the
|
|
86
|
+
* headers are written: symlinks are followed (lstat's size is the link
|
|
87
|
+
* target's string length, not the file's), directories are refused, and the
|
|
88
|
+
* content length comes from the same handle the body is read through. The
|
|
89
|
+
* session has no wall-clock deadline (see `DOWNLOAD_IDLE_MS`); the caller's
|
|
90
|
+
* response close and stream errors are both handled, so a cancelled download
|
|
91
|
+
* never leaves the SFTP session or its channel slot pinned.
|
|
92
|
+
*
|
|
93
|
+
* @param alias - host alias.
|
|
94
|
+
* @param file - absolute remote source path.
|
|
95
|
+
* @param res - HTTP response to write the file into.
|
|
96
|
+
*/
|
|
97
|
+
download(alias: string, file: string, res: ServerResponse): Promise<void>;
|
|
60
98
|
mkdir(alias: string, dir: string): Promise<void>;
|
|
61
99
|
remove(alias: string, target: string, recursive: boolean): Promise<void>;
|
|
62
100
|
rename(alias: string, oldPath: string, newPath: string): Promise<void>;
|