fix: 按不活跃时间限制 trans 下载
This commit is contained in:
@@ -924,6 +924,7 @@ async function runRemoteSshOverFrontend(session: FrontendSession, target: string
|
||||
const invocation = parseSshInvocation(target, normalizedArgs);
|
||||
if (isSshFileTransferOperation(normalizedArgs)) {
|
||||
const executor: SshRemoteCommandExecutor = {
|
||||
streamInactivityTimeoutMs: sshRuntimeTimeoutMs(),
|
||||
runRemoteCommand: (remoteCommand, input) => runRemoteSshWebSocketCaptureRemoteCommand(session, invocation, remoteCommand, input),
|
||||
streamRemoteCommand: (remoteCommand, handlers, input, options) => runRemoteSshWebSocketStreamRemoteCommand(session, invocation, remoteCommand, handlers, input, options),
|
||||
};
|
||||
|
||||
@@ -1589,6 +1589,7 @@ async function runRemoteSshOverFrontend(session: FrontendSession, target: string
|
||||
const invocation = parseSshInvocation(target, normalizedArgs);
|
||||
if (isSshFileTransferOperation(normalizedArgs)) {
|
||||
const executor: SshRemoteCommandExecutor = {
|
||||
streamInactivityTimeoutMs: sshRuntimeTimeoutMs(),
|
||||
runRemoteCommand: (remoteCommand, input) => runRemoteSshWebSocketCaptureRemoteCommand(session, invocation, remoteCommand, input),
|
||||
streamRemoteCommand: (remoteCommand, handlers, input, options) => runRemoteSshWebSocketStreamRemoteCommand(session, invocation, remoteCommand, handlers, input, options),
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ function fakeTransfer(content: Buffer): { executor: SshRemoteCommandExecutor; bu
|
||||
},
|
||||
},
|
||||
executor: {
|
||||
streamInactivityTimeoutMs: 60_000,
|
||||
async runRemoteCommand(remoteCommand) {
|
||||
const command = JSON.parse(remoteCommand) as string[];
|
||||
const marker = command.indexOf("unidesk-file-transfer");
|
||||
@@ -153,12 +154,14 @@ describe("ssh text transfer preflight", () => {
|
||||
},
|
||||
};
|
||||
const executor: SshRemoteCommandExecutor = {
|
||||
streamInactivityTimeoutMs: 60_000,
|
||||
async runRemoteCommand(remoteCommand) {
|
||||
commands.push(remoteCommand);
|
||||
return { exitCode: 0, stdout: `${content.length} ${sha256}\n`, stderr: "" };
|
||||
},
|
||||
async streamRemoteCommand(remoteCommand, handlers) {
|
||||
async streamRemoteCommand(remoteCommand, handlers, _input, options) {
|
||||
commands.push(remoteCommand);
|
||||
expect(options?.inactivityTimeoutMs).toBe(60_000);
|
||||
await handlers.onStdout(content);
|
||||
return { exitCode: 0, stdout: "", stderr: "" };
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface SshRemoteCommandStreamHandlers {
|
||||
}
|
||||
|
||||
export interface SshRemoteCommandExecutor {
|
||||
streamInactivityTimeoutMs: number;
|
||||
runRemoteCommand(remoteCommand: string, input?: string): Promise<SshCaptureResult>;
|
||||
streamRemoteCommand?(
|
||||
remoteCommand: string,
|
||||
@@ -98,7 +99,8 @@ class SshFileTransferError extends Error {
|
||||
const fileTransferWriteB64ArgvLimit = 48_000;
|
||||
const fileTransferWriteRawChunkBytes = 3 * 1024 * 1024;
|
||||
const fileTransferWriteB64ChunkChars = 1_398_104;
|
||||
const fileTransferProgressEveryChunks = 16;
|
||||
const fileTransferUploadProgressEveryChunks = 16;
|
||||
const fileTransferDownloadProgressEveryChunks = 256;
|
||||
|
||||
const knownTextExtensions = new Set([
|
||||
".bat", ".bib", ".c", ".cc", ".cfg", ".cmd", ".conf", ".cpp", ".css", ".csv", ".cts", ".cxx",
|
||||
@@ -412,7 +414,7 @@ async function downloadRemoteFileVerified(
|
||||
hash.update(chunk);
|
||||
emitDownloadProgress(invocation, remotePath, chunkCount, actualBytes, remote.bytes, chunk.length, startedAtMs);
|
||||
},
|
||||
}, undefined, { inactivityTimeoutMs });
|
||||
}, undefined, { inactivityTimeoutMs: inactivityTimeoutMs ?? executor.streamInactivityTimeoutMs });
|
||||
await closeWriteStream(output);
|
||||
if (result.exitCode !== 0) {
|
||||
throw new SshFileTransferError("remote ssh download stream failed", {
|
||||
@@ -512,7 +514,7 @@ function emitDownloadProgress(
|
||||
startedAtMs: number,
|
||||
force = false,
|
||||
): void {
|
||||
if (!force && chunkCount !== 1 && actualBytes < expectedBytes && chunkCount % fileTransferProgressEveryChunks !== 0) return;
|
||||
if (!force && chunkCount !== 1 && actualBytes < expectedBytes && chunkCount % fileTransferDownloadProgressEveryChunks !== 0) return;
|
||||
const elapsedMs = Math.max(1, Date.now() - startedAtMs);
|
||||
process.stderr.write(`${JSON.stringify({
|
||||
event: "unidesk.ssh.download.progress",
|
||||
@@ -544,7 +546,7 @@ function emitUploadProgress(
|
||||
startedAtMs: number,
|
||||
force = false,
|
||||
): void {
|
||||
if (!force && chunkCount !== 1 && actualBytes < expectedBytes && chunkCount % fileTransferProgressEveryChunks !== 0) return;
|
||||
if (!force && chunkCount !== 1 && actualBytes < expectedBytes && chunkCount % fileTransferUploadProgressEveryChunks !== 0) return;
|
||||
const elapsedMs = Math.max(1, Date.now() - startedAtMs);
|
||||
process.stderr.write(`${JSON.stringify({
|
||||
event: "unidesk.ssh.upload.progress",
|
||||
|
||||
@@ -1422,6 +1422,7 @@ export async function runSsh(config: UniDeskConfig, providerId: string, args: st
|
||||
const operationName = normalizedArgs[0] ?? "";
|
||||
if (isSshFileTransferOperation(normalizedArgs)) {
|
||||
const executor: SshRemoteCommandExecutor = {
|
||||
streamInactivityTimeoutMs: sshRuntimeTimeoutMs(),
|
||||
runRemoteCommand: (remoteCommand, input) => runSshCaptureRemoteCommand(config, invocation, remoteCommand, input),
|
||||
streamRemoteCommand: (remoteCommand, handlers, input, options) => runSshStreamRemoteCommand(config, invocation, remoteCommand, handlers, input, options),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user