@lemoncat7/dsh-ssh 1.4.2 → 1.4.3
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/ARCHITECTURE.md +2 -0
- package/README.md +15 -1
- package/lib/api.js +20 -2
- package/lib/api.js.map +1 -1
- package/lib/client-api.d.ts +3 -0
- package/lib/client-api.d.ts.map +1 -1
- package/lib/client-api.js +9 -0
- package/lib/client-api.js.map +1 -1
- package/lib/client.js +43 -43
- package/lib/client.js.map +4 -4
- package/lib/explorer-path.d.ts +5 -0
- package/lib/explorer-path.d.ts.map +1 -0
- package/lib/explorer-path.js +15 -0
- package/lib/explorer-path.js.map +1 -0
- package/lib/file-entry-sort.d.ts.map +1 -1
- package/lib/file-entry-sort.js +3 -2
- package/lib/file-entry-sort.js.map +1 -1
- package/lib/file-name-compare.d.ts +2 -0
- package/lib/file-name-compare.d.ts.map +1 -0
- package/lib/file-name-compare.js +5 -0
- package/lib/file-name-compare.js.map +1 -0
- package/lib/file-transfer-tools.d.ts.map +1 -1
- package/lib/file-transfer-tools.js +29 -6
- package/lib/file-transfer-tools.js.map +1 -1
- package/lib/file-transfer-workspace.js +6 -2
- package/lib/file-transfer-workspace.js.map +1 -1
- package/lib/ftp-adapter.js +21 -21
- package/lib/ftp-adapter.js.map +1 -1
- package/lib/local-workspace.d.ts +2 -1
- package/lib/local-workspace.d.ts.map +1 -1
- package/lib/local-workspace.js +6 -0
- package/lib/local-workspace.js.map +1 -1
- package/lib/remote-files.d.ts.map +1 -1
- package/lib/remote-files.js +2 -1
- package/lib/remote-files.js.map +1 -1
- package/lib/session-file-download.d.ts +25 -0
- package/lib/session-file-download.d.ts.map +1 -0
- package/lib/session-file-download.js +159 -0
- package/lib/session-file-download.js.map +1 -0
- package/lib/sftp-client.d.ts.map +1 -1
- package/lib/sftp-client.js +61 -23
- package/lib/sftp-client.js.map +1 -1
- package/package.json +1 -1
package/lib/local-workspace.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
|
-
import { type SftpDirectoryView, type SftpFilePreview } from './sftp.js';
|
|
2
|
+
import { type SftpDirectoryEntry, type SftpDirectoryView, type SftpFilePreview } from './sftp.js';
|
|
3
|
+
export declare function statLocalWorkspacePath(root: string, requestedPath: string): Promise<SftpDirectoryEntry>;
|
|
3
4
|
export declare function listLocalWorkspace(root: string, requestedPath?: string): Promise<SftpDirectoryView>;
|
|
4
5
|
export declare function readLocalWorkspacePreview(root: string, requestedPath: string): Promise<SftpFilePreview>;
|
|
5
6
|
export declare function openLocalWorkspaceFile(root: string, requestedPath: string): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-workspace.d.ts","sourceRoot":"","sources":["../src/local-workspace.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAA4B,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"local-workspace.d.ts","sourceRoot":"","sources":["../src/local-workspace.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAA4B,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAI3H,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAK7G;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAsBzG;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAgB7G;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC,CAM7J;AAED,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB1H"}
|
package/lib/local-workspace.js
CHANGED
|
@@ -3,6 +3,12 @@ import { lstat, open, readdir, realpath, rm, stat } from 'node:fs/promises';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { mimeTypeFor, previewKind } from './sftp.js';
|
|
5
5
|
const MAX_PREVIEW_BYTES = 1_048_576;
|
|
6
|
+
export async function statLocalWorkspacePath(root, requestedPath) {
|
|
7
|
+
const target = await resolveInside(await realpath(root), requestedPath);
|
|
8
|
+
const attributes = await stat(target);
|
|
9
|
+
return { path: target, name: path.basename(target), size: attributes.size, modifiedAt: attributes.mtimeMs,
|
|
10
|
+
kind: attributes.isDirectory() ? 'directory' : attributes.isFile() ? 'file' : 'other' };
|
|
11
|
+
}
|
|
6
12
|
export async function listLocalWorkspace(root, requestedPath) {
|
|
7
13
|
const boundary = await realpath(root);
|
|
8
14
|
const target = await resolveInside(boundary, requestedPath ?? boundary);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-workspace.js","sourceRoot":"","sources":["../src/local-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,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AS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;AACpG,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,QAAgB,EAAE,aAAqB;IAClE,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;IACrG,IAAI,QAAgB,CAAA;IACpB,IAAI,CAAC;QAAC,QAAQ,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAA;IAAC,CAAC;IAC5C,MAAM,CAAC;QAAC,MAAM,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;IAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAClD,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,MAAM,SAAS,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAA;IACpI,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,OAAe;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-files.d.ts","sourceRoot":"","sources":["../src/remote-files.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remote-files.d.ts","sourceRoot":"","sources":["../src/remote-files.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAA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AAK,EAAE,MAAM,GAAG,MAAM,CAA8C;AAExG,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAM/E"}
|
package/lib/remote-files.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { compareFileNames } from './file-name-compare.js';
|
|
2
3
|
export function endpointId(kind, id) { return `${kind}:${id}`; }
|
|
3
4
|
export function splitEndpointId(value) {
|
|
4
5
|
const separator = value.indexOf(':');
|
|
@@ -30,7 +31,7 @@ export function sortRemoteEntries(entries) {
|
|
|
30
31
|
return -1;
|
|
31
32
|
if (left.kind !== 'directory' && right.kind === 'directory')
|
|
32
33
|
return 1;
|
|
33
|
-
return left.name
|
|
34
|
+
return compareFileNames(left.name, right.name);
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
//# sourceMappingURL=remote-files.js.map
|
package/lib/remote-files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-files.js","sourceRoot":"","sources":["../src/remote-files.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"remote-files.js","sourceRoot":"","sources":["../src/remote-files.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAkDzD,MAAM,UAAU,UAAU,CAAC,IAAwB,EAAE,EAAU,IAAY,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAA,CAAC,CAAC;AAEnG,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,SAAS,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IACnC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,C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,CAAC,CAAC;AAExG,MAAM,UAAU,iBAAiB,CAAC,OAA0B;IAC1D,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAClC,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO,CAAC,CAAC,CAAA;QACtE,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO,CAAC,CAAA;QACrE,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RemoteFileSystems } from './remote-file-systems.js';
|
|
2
|
+
interface DownloadRequest {
|
|
3
|
+
endpointId: string;
|
|
4
|
+
remotePath: string;
|
|
5
|
+
sessionDirectory: string;
|
|
6
|
+
localPath?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Bounded foreground downloads. Final names appear only after a complete, exclusive commit. */
|
|
9
|
+
export declare class SessionFileDownloads {
|
|
10
|
+
private readonly files;
|
|
11
|
+
private readonly active;
|
|
12
|
+
private closed;
|
|
13
|
+
constructor(files: RemoteFileSystems);
|
|
14
|
+
download(request: DownloadRequest, callerSignal: AbortSignal, assertAllowed: () => void): Promise<{
|
|
15
|
+
state: "completed";
|
|
16
|
+
endpointId: string;
|
|
17
|
+
remotePath: string;
|
|
18
|
+
localPath: string;
|
|
19
|
+
bytes: number;
|
|
20
|
+
location: "DSH session directory";
|
|
21
|
+
}>;
|
|
22
|
+
close(): void;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=session-file-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-file-download.d.ts","sourceRoot":"","sources":["../src/session-file-download.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAMjE,UAAU,eAAe;IAAG,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE;AAElH,gGAAgG;AAChG,qBAAa,oBAAoB;IAGnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IACpD,OAAO,CAAC,MAAM,CAAQ;gBACO,KAAK,EAAE,iBAAiB;IAE/C,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,IAAI;;;;;;;;IAkF7F,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { link, lstat, mkdtemp, open, realpath, rm } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { Transform } from 'node:stream';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
const MAX_DOWNLOAD_BYTES = 512 * 1024 * 1024;
|
|
7
|
+
const DOWNLOAD_TIMEOUT_MS = 300_000;
|
|
8
|
+
/** Bounded foreground downloads. Final names appear only after a complete, exclusive commit. */
|
|
9
|
+
export class SessionFileDownloads {
|
|
10
|
+
files;
|
|
11
|
+
active = new Set();
|
|
12
|
+
closed = false;
|
|
13
|
+
constructor(files) {
|
|
14
|
+
this.files = files;
|
|
15
|
+
}
|
|
16
|
+
async download(request, callerSignal, assertAllowed) {
|
|
17
|
+
if (this.closed)
|
|
18
|
+
throw new Error('文件下载服务已停止');
|
|
19
|
+
if (this.active.size >= 2)
|
|
20
|
+
throw new Error('已有两个文件正在下载,请稍后重试');
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
const signal = AbortSignal.any([callerSignal, controller.signal]);
|
|
23
|
+
const timer = setTimeout(() => controller.abort(new Error('文件下载超时,请重试')), DOWNLOAD_TIMEOUT_MS);
|
|
24
|
+
timer.unref?.();
|
|
25
|
+
this.active.add(controller);
|
|
26
|
+
let session;
|
|
27
|
+
let temporary;
|
|
28
|
+
try {
|
|
29
|
+
signal.throwIfAborted();
|
|
30
|
+
assertAllowed();
|
|
31
|
+
if (!request.sessionDirectory || !path.isAbsolute(request.sessionDirectory))
|
|
32
|
+
throw new Error('当前会话没有有效的本地工作目录,不能下载');
|
|
33
|
+
if (request.localPath !== undefined)
|
|
34
|
+
validateLocalPath(request.localPath);
|
|
35
|
+
const root = await realpath(request.sessionDirectory);
|
|
36
|
+
if (!(await lstat(root)).isDirectory())
|
|
37
|
+
throw new Error('当前会话工作目录不是目录');
|
|
38
|
+
signal.throwIfAborted();
|
|
39
|
+
assertAllowed();
|
|
40
|
+
session = await this.files.connect(request.endpointId, signal);
|
|
41
|
+
const entry = await session.stat(request.remotePath, signal);
|
|
42
|
+
if (entry.kind !== 'file')
|
|
43
|
+
throw new Error('下载工具仅支持普通文件;请指定文件路径,不要指定目录或特殊文件');
|
|
44
|
+
if (!Number.isSafeInteger(entry.size) || entry.size < 0 || entry.size > MAX_DOWNLOAD_BYTES)
|
|
45
|
+
throw new Error('单文件下载上限为 512 MiB');
|
|
46
|
+
const relativePath = request.localPath ?? entry.name;
|
|
47
|
+
validateLocalPath(relativePath);
|
|
48
|
+
const candidate = path.resolve(root, relativePath);
|
|
49
|
+
assertInside(root, candidate);
|
|
50
|
+
let parent;
|
|
51
|
+
try {
|
|
52
|
+
parent = await realpath(path.dirname(candidate));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code === 'ENOENT')
|
|
56
|
+
throw new Error('目标子目录不存在,请先创建目录或省略 localPath 使用会话目录');
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
assertInside(root, parent, true);
|
|
60
|
+
const target = path.join(parent, path.basename(candidate));
|
|
61
|
+
await assertAbsent(target);
|
|
62
|
+
signal.throwIfAborted();
|
|
63
|
+
assertAllowed();
|
|
64
|
+
temporary = await mkdtemp(path.join(parent, '.dsh-download-'));
|
|
65
|
+
const partial = path.join(temporary, 'content.part');
|
|
66
|
+
let bytes = 0;
|
|
67
|
+
const meter = new Transform({
|
|
68
|
+
highWaterMark: 64 * 1024,
|
|
69
|
+
transform(chunk, _encoding, callback) {
|
|
70
|
+
try {
|
|
71
|
+
signal.throwIfAborted();
|
|
72
|
+
assertAllowed();
|
|
73
|
+
bytes += chunk.length;
|
|
74
|
+
if (bytes > MAX_DOWNLOAD_BYTES)
|
|
75
|
+
throw new Error('下载内容超过 512 MiB,已停止');
|
|
76
|
+
callback(null, chunk);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
callback(error);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
meter.on('error', () => { });
|
|
84
|
+
const output = createWriteStream(partial, { flags: 'wx', mode: 0o600 });
|
|
85
|
+
const sink = pipeline(meter, output, { signal });
|
|
86
|
+
// Either side failing cancels the other side; wait for both before removing staging files.
|
|
87
|
+
const stop = (error) => { controller.abort(error); throw error; };
|
|
88
|
+
const writes = sink.catch(stop);
|
|
89
|
+
const reads = Promise.resolve().then(() => session.download(entry.path, meter, signal)).catch(stop);
|
|
90
|
+
const outcomes = await Promise.allSettled([reads, writes]);
|
|
91
|
+
signal.throwIfAborted();
|
|
92
|
+
for (const outcome of outcomes)
|
|
93
|
+
if (outcome.status === 'rejected')
|
|
94
|
+
throw outcome.reason;
|
|
95
|
+
if (bytes !== entry.size)
|
|
96
|
+
throw new Error('远端文件大小在下载期间发生变化,请重试;未保存不完整文件');
|
|
97
|
+
const handle = await open(partial, 'r');
|
|
98
|
+
try {
|
|
99
|
+
await handle.sync();
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await handle.close();
|
|
103
|
+
}
|
|
104
|
+
if (await realpath(request.sessionDirectory) !== root || await realpath(parent) !== parent)
|
|
105
|
+
throw new Error('会话目录在下载期间发生变化,请重试');
|
|
106
|
+
signal.throwIfAborted();
|
|
107
|
+
assertAllowed();
|
|
108
|
+
// link is atomic and fails for an existing file, directory or symlink; never overwrite.
|
|
109
|
+
try {
|
|
110
|
+
await link(partial, target);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error.code === 'EEXIST')
|
|
114
|
+
throw new Error('本地同名文件已存在,未覆盖;请指定其他 localPath');
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
return { state: 'completed', endpointId: request.endpointId, remotePath: entry.path,
|
|
118
|
+
localPath: target, bytes, location: 'DSH session directory' };
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
try {
|
|
123
|
+
session?.close();
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
if (temporary !== undefined)
|
|
127
|
+
await rm(temporary, { recursive: true, force: true }).catch(() => { });
|
|
128
|
+
this.active.delete(controller);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
close() {
|
|
133
|
+
this.closed = true;
|
|
134
|
+
for (const controller of this.active)
|
|
135
|
+
controller.abort(new Error('文件下载服务已停止'));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function validateLocalPath(value) {
|
|
139
|
+
if (!value || value.length > 4096 || /[\0\r\n\\]/.test(value) || path.isAbsolute(value) || path.win32.isAbsolute(value) || value.split('/').some(part => part === '..' || part === '' || part === '.')) {
|
|
140
|
+
throw new Error('localPath 必须是会话目录内的相对文件路径,不能包含 ..、绝对路径或换行');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function assertInside(root, target, allowRoot = false) {
|
|
144
|
+
const relative = path.relative(root, target);
|
|
145
|
+
if ((!allowRoot && !relative) || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
|
|
146
|
+
throw new Error('下载目标必须位于当前会话目录内');
|
|
147
|
+
}
|
|
148
|
+
async function assertAbsent(target) {
|
|
149
|
+
try {
|
|
150
|
+
await lstat(target);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (error.code === 'ENOENT')
|
|
154
|
+
return;
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
throw new Error('本地同名文件已存在,未覆盖;请指定其他 localPath');
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=session-file-download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-file-download.js","sourceRoot":"","sources":["../src/session-file-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAI/C,MAAM,kBAAkB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA;AAC5C,MAAM,mBAAmB,GAAG,OAAO,CAAA;AAInC,gGAAgG;AAChG,MAAM,OAAO,oBAAoB;IAGF;IAFZ,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAA;IAC5C,MAAM,GAAG,KAAK,CAAA;IACtB,YAA6B,KAAwB;QAAxB,UAAK,GAAL,KAAK,CAAmB;IAAG,CAAC;IAEzD,KAAK,CAAC,QAAQ,CAAC,OAAwB,EAAE,YAAyB,EAAE,aAAyB;QAC3F,IAAI,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;QAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,C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ACD,SAAS,YAAY,CAAC,IAAY,EAAE,MAAc,EAAE,SAAS,GAAG,KAAK;IACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC5C,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;AAC7J,CAAC;AACD,KAAK,UAAU,YAAY,CAAC,MAAc;IACxC,IAAI,CAAC;QAAC,MAAM,KAAK,CAAC,MAAM,CAAC,CAAA;IAAC,CAAC;IAC3B,OAAO,KAAK,EAAE,CAAC;QAAC,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO;QAAC,MAAM,KAAK,CAAA;IAAC,CAAC;IAC7F,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;AAClD,CAAC"}
|
package/lib/sftp-client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sftp-client.d.ts","sourceRoot":"","sources":["../src/sftp-client.tsx"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"sftp-client.d.ts","sourceRoot":"","sources":["../src/sftp-client.tsx"],"names":[],"mappings":"AAOA,OAAO,EAKL,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAC3C,MAAM,iBAAiB,CAAA;AAuCxB,wBAAgB,qBAAqB,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,GAAG,CAAC,OAAO,CAOvF;AAED,wBAAgB,mBAAmB,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,mBAAmB,CAAC;IAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAAC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GAAG,GAAG,CAAC,OAAO,CAmBlP;AAED,wBAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,WAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAgB,EAAE,EAAE;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,IAAI,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,GAAG,CAAC,OAAO,CAavN"}
|
package/lib/sftp-client.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
3
3
|
import ReactMarkdown from 'react-markdown';
|
|
4
4
|
import remarkGfm from 'remark-gfm';
|
|
5
5
|
import { IconChevronLeftOutline14, IconCloseOutline16, IconDataOutline16, IconDownloadOutline16, IconFolderClose16, IconEditOutline16, IconFullscreenOutline16, IconRefreshOutline16, IconSendOutline14, IconTrashOutline16, Modal, } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
6
|
-
import { ApiError, deleteFileEndpointEntries, deleteLocalWorkspaceEntries, loadLocalWorkspaceDirectory, loadLocalWorkspaceFilePreview, loadProfileSftpDirectory, loadProfileSftpFilePreview, loadSftpDirectory, loadSftpFilePreview, localWorkspaceFileUrl, profileAddress, profileSftpFileUrl, sftpFileUrl, updateActivityDirectory, uploadProfileSftpFile, } from './client-api.js';
|
|
6
|
+
import { ApiError, deleteFileEndpointEntries, deleteLocalWorkspaceEntries, loadLocalWorkspaceDirectory, loadLocalWorkspaceFilePreview, loadProfileSftpDirectory, loadProfileSftpFilePreview, loadSftpDirectory, loadSftpFilePreview, localWorkspaceFileUrl, profileAddress, profileSftpFileUrl, sftpFileUrl, updateActivityDirectory, uploadProfileSftpFile, loadLocalWorkspacePathEntry, loadProfileSftpPathEntry, loadSftpPathEntry, } from './client-api.js';
|
|
7
7
|
import { REMOTE_FILES_DRAG_TYPE, isNavigableRemoteEntry, parseRemoteFilesDragPayload, remoteDropOperation } from './file-transfer-intent.js';
|
|
8
8
|
import { executeRemoteFileDrop } from './remote-file-drop.js';
|
|
9
9
|
import { FileEntryDeleteDialog } from './file-entry-delete-dialog.js';
|
|
10
|
+
import { explorerInputPath } from './explorer-path.js';
|
|
10
11
|
const MAX_UPLOAD_BYTES = 512 * 1024 * 1024;
|
|
11
12
|
export function LocalWorkspaceBrowser({ sessionId }) {
|
|
13
|
+
const loadPathEntry = useCallback((path) => loadLocalWorkspacePathEntry(sessionId, path), [sessionId]);
|
|
12
14
|
const loadDirectory = useCallback((path) => loadLocalWorkspaceDirectory(sessionId, path || undefined), [sessionId]);
|
|
13
15
|
const loadPreview = useCallback((path) => loadLocalWorkspaceFilePreview(sessionId, path), [sessionId]);
|
|
14
16
|
const fileUrl = useCallback((path, inline = false) => localWorkspaceFileUrl(sessionId, path, inline), [sessionId]);
|
|
15
17
|
const remove = useCallback((directory, paths) => deleteLocalWorkspaceEntries(sessionId, directory, paths), [sessionId]);
|
|
16
|
-
return _jsx(SftpExplorer, { initialPath: "", loadDirectory: loadDirectory, loadPreview: loadPreview, fileUrl: fileUrl, deletion: { locationName: '本地会话', locationKind: 'local', remove } });
|
|
18
|
+
return _jsx(SftpExplorer, { initialPath: "", loadPathEntry: loadPathEntry, loadDirectory: loadDirectory, loadPreview: loadPreview, fileUrl: fileUrl, deletion: { locationName: '本地会话', locationKind: 'local', remove } }, sessionId);
|
|
17
19
|
}
|
|
18
20
|
export function ActivitySftpBrowser({ sessionId, profile, profiles, onProfile, onSaved }) {
|
|
21
|
+
const loadPathEntry = useCallback((path) => loadSftpPathEntry(sessionId, profile.id, path), [sessionId, profile.id]);
|
|
19
22
|
const loadDirectory = useCallback(async (target, persist) => {
|
|
20
23
|
const cwd = persist ? (await updateActivityDirectory(sessionId, profile.id, target)).cwd : target;
|
|
21
24
|
const directory = await loadSftpDirectory(sessionId, profile.id, cwd);
|
|
@@ -30,9 +33,10 @@ export function ActivitySftpBrowser({ sessionId, profile, profiles, onProfile, o
|
|
|
30
33
|
const endpointId = `sftp:${profile.id}`;
|
|
31
34
|
const remove = useCallback((directory, paths) => deleteFileEndpointEntries({ paneId, endpointId, directory, paths }), [endpointId, paneId]);
|
|
32
35
|
const header = _jsxs("div", { className: "dsh-ssh-sftp-hostbar", children: [_jsx("span", { className: "dsh-ssh-host-monogram", children: profile.name.slice(0, 1).toUpperCase() }), _jsxs("label", { children: [_jsx("span", { className: "sr-only", children: "\u9009\u62E9\u8FDC\u7AEF\u4E3B\u673A" }), _jsx("select", { value: profile.id, onChange: event => onProfile(event.target.value), children: profiles.map(item => _jsx("option", { value: item.id, children: item.name }, item.id)) }), _jsxs("small", { children: [profile.username, "@", profile.host, ":", profile.port] })] })] });
|
|
33
|
-
return _jsx(SftpExplorer, { initialPath: profile.cwd, header: header, loadDirectory: loadDirectory, loadPreview: loadPreview, fileUrl: fileUrl, uploadFile: uploadFile, operations: { paneId, endpointId, endpointName: profile.name }, deletion: { locationName: profile.name, locationKind: 'remote', remove } });
|
|
36
|
+
return _jsx(SftpExplorer, { initialPath: profile.cwd, header: header, loadPathEntry: loadPathEntry, loadDirectory: loadDirectory, loadPreview: loadPreview, fileUrl: fileUrl, uploadFile: uploadFile, operations: { paneId, endpointId, endpointName: profile.name }, deletion: { locationName: profile.name, locationKind: 'remote', remove } }, `${sessionId}:${profile.id}`);
|
|
34
37
|
}
|
|
35
38
|
export function ProfileSftpPane({ profile, initialPath = '~', onEdit, onDelete, embedded = false }) {
|
|
39
|
+
const loadPathEntry = useCallback((path) => loadProfileSftpPathEntry(profile.id, path), [profile.id]);
|
|
36
40
|
const loadDirectory = useCallback((path) => loadProfileSftpDirectory(profile.id, path), [profile.id]);
|
|
37
41
|
const loadPreview = useCallback((path) => loadProfileSftpFilePreview(profile.id, path), [profile.id]);
|
|
38
42
|
const fileUrl = useCallback((path, inline = false) => profileSftpFileUrl(profile.id, path, inline), [profile.id]);
|
|
@@ -40,9 +44,11 @@ export function ProfileSftpPane({ profile, initialPath = '~', onEdit, onDelete,
|
|
|
40
44
|
const paneId = safePaneId(`profile-sftp-${profile.id}`);
|
|
41
45
|
const endpointId = `sftp:${profile.id}`;
|
|
42
46
|
const remove = useCallback((directory, paths) => deleteFileEndpointEntries({ paneId, endpointId, directory, paths }), [endpointId, paneId]);
|
|
43
|
-
return _jsxs("div", { className: `dsh-ssh-profile-sftp-pane${embedded ? ' is-embedded' : ''}`, children: [_jsxs("div", { className: "dsh-ssh-content-heading", children: [_jsxs("div", { children: [_jsx("h1", { children: embedded ? 'SFTP' : `${profile.name} · SFTP` }), _jsx("p", { children: embedded ? initialPath : `${profileAddress(profile)} · ${initialPath}` })] }), _jsxs("div", { className: "dsh-ssh-heading-actions", children: [onDelete && _jsx("button", { type: "button", className: "dsh-ssh-icon-button is-danger", "aria-label": `删除主机 ${profile.name}`, title: "\u5220\u9664\u4E3B\u673A", onClick: onDelete, children: _jsx(IconTrashOutline16, { size: 16 }) }), onEdit && _jsxs("button", { type: "button", className: "dsh-ssh-secondary-button", onClick: onEdit, children: [_jsx(IconEditOutline16, { size: 16 }), "\u7F16\u8F91\u4E3B\u673A"] })] })] }), _jsx(SftpExplorer, { workspace: true, initialPath: initialPath, loadDirectory: loadDirectory, loadPreview: loadPreview, fileUrl: fileUrl, uploadFile: uploadFile, operations: { paneId, endpointId, endpointName: profile.name }, deletion: { locationName: profile.name, locationKind: 'remote', remove } })] });
|
|
47
|
+
return _jsxs("div", { className: `dsh-ssh-profile-sftp-pane${embedded ? ' is-embedded' : ''}`, children: [_jsxs("div", { className: "dsh-ssh-content-heading", children: [_jsxs("div", { children: [_jsx("h1", { children: embedded ? 'SFTP' : `${profile.name} · SFTP` }), _jsx("p", { children: embedded ? initialPath : `${profileAddress(profile)} · ${initialPath}` })] }), _jsxs("div", { className: "dsh-ssh-heading-actions", children: [onDelete && _jsx("button", { type: "button", className: "dsh-ssh-icon-button is-danger", "aria-label": `删除主机 ${profile.name}`, title: "\u5220\u9664\u4E3B\u673A", onClick: onDelete, children: _jsx(IconTrashOutline16, { size: 16 }) }), onEdit && _jsxs("button", { type: "button", className: "dsh-ssh-secondary-button", onClick: onEdit, children: [_jsx(IconEditOutline16, { size: 16 }), "\u7F16\u8F91\u4E3B\u673A"] })] })] }), _jsx(SftpExplorer, { workspace: true, initialPath: initialPath, loadPathEntry: loadPathEntry, loadDirectory: loadDirectory, loadPreview: loadPreview, fileUrl: fileUrl, uploadFile: uploadFile, operations: { paneId, endpointId, endpointName: profile.name }, deletion: { locationName: profile.name, locationKind: 'remote', remove } }, profile.id)] });
|
|
44
48
|
}
|
|
45
|
-
function SftpExplorer({ initialPath, header, workspace = false, loadDirectory, loadPreview, fileUrl, uploadFile, operations, deletion }) {
|
|
49
|
+
function SftpExplorer({ initialPath, header, workspace = false, loadDirectory, loadPreview, loadPathEntry, fileUrl, uploadFile, operations, deletion }) {
|
|
50
|
+
const navigationId = useRef(0);
|
|
51
|
+
const errorId = useId();
|
|
46
52
|
const fileInputRef = useRef(null);
|
|
47
53
|
const dragDepthRef = useRef(0);
|
|
48
54
|
const [directory, setDirectory] = useState();
|
|
@@ -58,24 +64,63 @@ function SftpExplorer({ initialPath, header, workspace = false, loadDirectory, l
|
|
|
58
64
|
const [operationMessage, setOperationMessage] = useState();
|
|
59
65
|
const [error, setError] = useState();
|
|
60
66
|
const browse = useCallback(async (target, persist) => {
|
|
67
|
+
const request = ++navigationId.current;
|
|
61
68
|
setLoading(true);
|
|
62
69
|
setError(undefined);
|
|
63
70
|
setOpenedFile(undefined);
|
|
64
71
|
setPendingOverwrite(undefined);
|
|
65
72
|
try {
|
|
66
73
|
const next = await loadDirectory(target, persist);
|
|
74
|
+
if (request !== navigationId.current)
|
|
75
|
+
return;
|
|
67
76
|
setDirectory(next);
|
|
68
77
|
setPath(next.path);
|
|
69
78
|
}
|
|
70
79
|
catch (reason) {
|
|
71
|
-
|
|
80
|
+
if (request === navigationId.current)
|
|
81
|
+
setError(errorMessage(reason));
|
|
72
82
|
}
|
|
73
83
|
finally {
|
|
74
|
-
|
|
84
|
+
if (request === navigationId.current)
|
|
85
|
+
setLoading(false);
|
|
75
86
|
}
|
|
76
87
|
}, [loadDirectory]);
|
|
77
|
-
useEffect(() => { void browse(initialPath, false); }, [browse, initialPath]);
|
|
78
|
-
const
|
|
88
|
+
useEffect(() => { void browse(initialPath, false); return () => { navigationId.current++; }; }, [browse, initialPath]);
|
|
89
|
+
const openEntry = (entry) => {
|
|
90
|
+
if (isNavigableRemoteEntry(entry)) {
|
|
91
|
+
void browse(entry.path, true);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
navigationId.current++;
|
|
95
|
+
setLoading(false);
|
|
96
|
+
setError(undefined);
|
|
97
|
+
setPath(directory?.path ?? initialPath);
|
|
98
|
+
setOpenedFile(entry);
|
|
99
|
+
};
|
|
100
|
+
const submit = async (event) => {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
if (loading)
|
|
103
|
+
return;
|
|
104
|
+
const request = ++navigationId.current;
|
|
105
|
+
setLoading(true);
|
|
106
|
+
setError(undefined);
|
|
107
|
+
try {
|
|
108
|
+
const entry = await loadPathEntry(explorerInputPath(path, directory?.path ?? initialPath));
|
|
109
|
+
if (request !== navigationId.current)
|
|
110
|
+
return;
|
|
111
|
+
if (entry.kind !== 'directory' && entry.kind !== 'file')
|
|
112
|
+
throw new Error('此路径不是普通文件或目录,请检查路径后重试');
|
|
113
|
+
openEntry(entry);
|
|
114
|
+
}
|
|
115
|
+
catch (reason) {
|
|
116
|
+
if (request === navigationId.current)
|
|
117
|
+
setError(errorMessage(reason));
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (request === navigationId.current)
|
|
121
|
+
setLoading(false);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
79
124
|
const uploadFiles = async (files, targetDirectory = directory?.path, overwriteFirst = false) => {
|
|
80
125
|
if (uploadFile === undefined || targetDirectory === undefined || files.length === 0)
|
|
81
126
|
return;
|
|
@@ -184,24 +229,17 @@ function SftpExplorer({ initialPath, header, workspace = false, loadDirectory, l
|
|
|
184
229
|
await deletion.remove(directory.path, [deleteTarget.path]);
|
|
185
230
|
await browse(directory.path, false);
|
|
186
231
|
};
|
|
187
|
-
return _jsxs("div", { className: `dsh-ssh-sftp${workspace ? ' is-workspace' : ''}${draggingFiles ? ' is-dragging-files' : ''}`, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, children: [header, openedFile ? _jsx(SftpFilePreview, { entry: openedFile, loadPreview: loadPreview, fileUrl: fileUrl, onBack: () => setOpenedFile(undefined) }) : _jsxs(_Fragment, { children: [_jsxs("form", { className: `dsh-ssh-sftp-pathbar${uploadFile === undefined ? '' : ' has-upload'}`, onSubmit: submit, children: [_jsx("button", { type: "button", "aria-label": "\u8FD4\u56DE\u4E0A\u7EA7\u76EE\u5F55", title: "\u8FD4\u56DE\u4E0A\u7EA7\u76EE\u5F55", disabled: directory?.parent == null || loading, onClick: () => { if (directory?.parent)
|
|
188
|
-
void browse(directory.parent, true); }, children: _jsx(IconChevronLeftOutline14, { size: 14 }) }), _jsx("input", { "aria-label": "\
|
|
189
|
-
|
|
232
|
+
return _jsxs("div", { className: `dsh-ssh-sftp${workspace ? ' is-workspace' : ''}${draggingFiles ? ' is-dragging-files' : ''}`, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, children: [header, openedFile ? _jsx(SftpFilePreview, { entry: openedFile, loadPreview: loadPreview, fileUrl: fileUrl, onBack: () => setOpenedFile(undefined) }) : _jsxs(_Fragment, { children: [_jsxs("form", { className: `dsh-ssh-sftp-pathbar${uploadFile === undefined ? '' : ' has-upload'}`, "aria-busy": loading, onSubmit: event => { void submit(event); }, children: [_jsx("button", { type: "button", "aria-label": "\u8FD4\u56DE\u4E0A\u7EA7\u76EE\u5F55", title: "\u8FD4\u56DE\u4E0A\u7EA7\u76EE\u5F55", disabled: directory?.parent == null || loading, onClick: () => { if (directory?.parent)
|
|
233
|
+
void browse(directory.parent, true); }, children: _jsx(IconChevronLeftOutline14, { size: 14 }) }), _jsx("input", { "aria-label": "\u76EE\u5F55\u6216\u6587\u4EF6\u8DEF\u5F84", title: "\u8F93\u5165\u76EE\u5F55\u8FDB\u5165\uFF0C\u8F93\u5165\u6587\u4EF6\u8DEF\u5F84\u6253\u5F00\u9884\u89C8\uFF1B\u6309 Enter \u786E\u8BA4", placeholder: "\u76EE\u5F55\u6216\u6587\u4EF6\u8DEF\u5F84\uFF0C\u6309 Enter \u6253\u5F00", value: path, readOnly: loading, "aria-invalid": Boolean(error), "aria-describedby": error ? errorId : undefined, spellCheck: false, onChange: event => { setPath(event.target.value); setError(undefined); }, onKeyDown: event => { if (event.key === 'Enter' && event.nativeEvent.isComposing)
|
|
234
|
+
event.preventDefault(); } }), _jsx("button", { type: "button", "aria-label": "\u5237\u65B0\u76EE\u5F55", title: "\u5237\u65B0\u76EE\u5F55", disabled: loading, onClick: () => { void browse(directory?.path ?? path, false); }, children: _jsx(IconRefreshOutline16, { size: 15 }) }), uploadFile !== undefined && _jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, className: "sr-only", type: "file", multiple: true, tabIndex: -1, onChange: event => { const files = Array.from(event.target.files ?? []); event.target.value = ''; if (files.length > 0)
|
|
235
|
+
void uploadFiles(files); } }), _jsxs("button", { type: "button", className: "dsh-ssh-sftp-upload-button", disabled: directory === undefined || uploading !== undefined || pendingOverwrite !== undefined, onClick: () => fileInputRef.current?.click(), children: [_jsx(IconSendOutline14, { size: 14 }), uploading === undefined ? '上传' : '上传中'] })] })] }), pendingOverwrite !== undefined && _jsxs("div", { className: "dsh-ssh-upload-conflict", role: "alert", children: [_jsxs("span", { children: [_jsx("strong", { children: "\u540C\u540D\u6587\u4EF6\u5DF2\u5B58\u5728" }), _jsx("small", { children: pendingOverwrite.file.name })] }), _jsxs("span", { children: [_jsx("button", { type: "button", onClick: () => { const pending = pendingOverwrite; setPendingOverwrite(undefined); void uploadFiles(pending.remaining, pending.directory); }, children: "\u8DF3\u8FC7" }), _jsx("button", { type: "button", className: "is-primary", disabled: uploading !== undefined, onClick: () => { const pending = pendingOverwrite; void uploadFiles([pending.file, ...pending.remaining], pending.directory, true); }, children: "\u8986\u76D6\u4E0A\u4F20" })] })] }), operationMessage && _jsxs("div", { className: "dsh-ssh-sftp-operation-status", role: "status", children: [_jsx("span", { children: operationMessage }), _jsx("button", { type: "button", "aria-label": "\u5173\u95ED\u63D0\u793A", onClick: () => setOperationMessage(undefined), children: _jsx(IconCloseOutline16, { size: 14 }) })] }), error && _jsx("p", { id: errorId, className: "dsh-ssh-directory-error", role: "alert", children: error }), _jsxs("div", { className: "dsh-ssh-sftp-table dsh-ssh-scroll-surface", "aria-busy": loading, children: [_jsxs("div", { className: "dsh-ssh-sftp-columns", children: [_jsx("span", { children: "\u540D\u79F0" }), _jsx("span", { children: "\u5927\u5C0F" }), _jsx("span", { children: "\u4FEE\u6539\u65F6\u95F4" }), _jsx("span", { "aria-hidden": "true" })] }), loading && directory === undefined ? _jsx("p", { className: "dsh-ssh-sftp-state", children: "\u6B63\u5728\u8BFB\u53D6\u8FDC\u7AEF\u76EE\u5F55\u2026" })
|
|
190
236
|
: directory?.entries.length === 0 ? _jsx("p", { className: "dsh-ssh-sftp-state", children: "\u6B64\u76EE\u5F55\u4E3A\u7A7A" })
|
|
191
237
|
: directory?.entries.map(entry => {
|
|
192
238
|
const directoryEntry = isNavigableRemoteEntry(entry);
|
|
193
239
|
const dragOperation = remoteDragSource === undefined || operations === undefined ? undefined : remoteDropOperation(remoteDragSource, { endpointId: operations.endpointId, directory: entry.path });
|
|
194
240
|
const acceptsRemoteDrop = directoryEntry && dragOperation !== 'none' && dragOperation !== 'invalid';
|
|
195
|
-
return _jsxs("div", { role: "row", tabIndex: 0, "aria-label": `${entry.name}${directoryEntry ? ',目录,单击进入;可接收拖放' : ',文件,单击预览'}`, "data-ssh-interactive": "row", "data-ssh-context-row": true, draggable: operations !== undefined && (entry.kind === 'file' || directoryEntry), className: `dsh-ssh-sftp-row is-${directoryEntry ? 'directory' : entry.kind}${remoteDropTarget === entry.path ? ' is-drop-target' : ''}`, onClick: () => { if (
|
|
196
|
-
|
|
197
|
-
else
|
|
198
|
-
setOpenedFile(entry); }, onKeyDown: event => { if (event.target !== event.currentTarget)
|
|
199
|
-
return; if (event.key === 'Enter') {
|
|
200
|
-
if (directoryEntry)
|
|
201
|
-
void browse(entry.path, true);
|
|
202
|
-
else
|
|
203
|
-
setOpenedFile(entry);
|
|
204
|
-
} }, onDragStart: event => { if (operations === undefined || directory === undefined)
|
|
241
|
+
return _jsxs("div", { role: "row", tabIndex: 0, "aria-label": `${entry.name}${directoryEntry ? ',目录,单击进入;可接收拖放' : ',文件,单击预览'}`, "data-ssh-interactive": "row", "data-ssh-context-row": true, draggable: operations !== undefined && (entry.kind === 'file' || directoryEntry), className: `dsh-ssh-sftp-row is-${directoryEntry ? 'directory' : entry.kind}${remoteDropTarget === entry.path ? ' is-drop-target' : ''}`, onClick: () => openEntry(entry), onKeyDown: event => { if (event.target === event.currentTarget && event.key === 'Enter')
|
|
242
|
+
openEntry(entry); }, onDragStart: event => { if (operations === undefined || directory === undefined)
|
|
205
243
|
return; const source = { paneId: operations.paneId, endpointId: operations.endpointId, directory: directory.path, paths: [entry.path] }; setRemoteDragSource(source); event.dataTransfer.effectAllowed = 'copyMove'; event.dataTransfer.setData(REMOTE_FILES_DRAG_TYPE, JSON.stringify(source)); }, onDragEnd: () => { setRemoteDragSource(undefined); setRemoteDropTarget(undefined); }, onDragOver: event => { const fileDrop = canDropFiles && isFileDrag(event); if (!directoryEntry || (!fileDrop && !isRemoteDrag(event)) || (!fileDrop && !acceptsRemoteDrop))
|
|
206
244
|
return; event.preventDefault(); event.stopPropagation(); event.dataTransfer.dropEffect = fileDrop || dragOperation !== 'move' ? 'copy' : 'move'; setRemoteDropTarget(entry.path); }, onDragLeave: event => { if (!event.currentTarget.contains(event.relatedTarget))
|
|
207
245
|
setRemoteDropTarget(undefined); }, onDrop: event => { if (!directoryEntry)
|