@qodalis/cli-scp 2.0.0-beta.1
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/package.json +34 -0
- package/public-api.d.mts +22 -0
- package/public-api.d.ts +22 -0
- package/public-api.js +900 -0
- package/public-api.js.map +1 -0
- package/public-api.mjs +895 -0
- package/public-api.mjs.map +1 -0
- package/umd/cli-entrypoint.global.js +3562 -0
package/public-api.js
ADDED
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cliCore = require('@qodalis/cli-core');
|
|
4
|
+
|
|
5
|
+
// src/lib/processors/cli-scp-command-processor.ts
|
|
6
|
+
|
|
7
|
+
// src/lib/version.ts
|
|
8
|
+
var LIBRARY_VERSION = "2.0.0-beta.1";
|
|
9
|
+
var API_VERSION = 2;
|
|
10
|
+
|
|
11
|
+
// src/lib/interfaces/index.ts
|
|
12
|
+
var IScpTransferService_TOKEN = "scp-transfer-service";
|
|
13
|
+
|
|
14
|
+
// src/lib/processors/scp-utils.ts
|
|
15
|
+
function resolveServer(serverName, context) {
|
|
16
|
+
const servers = context.options?.servers;
|
|
17
|
+
if (!servers || servers.length === 0) {
|
|
18
|
+
context.writer.writeError("No servers configured. Add servers to CLI options.");
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (!serverName) {
|
|
22
|
+
if (servers.length === 1) {
|
|
23
|
+
return servers[0];
|
|
24
|
+
}
|
|
25
|
+
context.writer.writeError("Multiple servers configured. Specify server name.");
|
|
26
|
+
context.writer.writeInfo("Available: " + servers.map((s) => s.name).join(", "));
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const server = servers.find((s) => s.name.toLowerCase() === serverName.toLowerCase());
|
|
30
|
+
if (!server) {
|
|
31
|
+
context.writer.writeError(`Unknown server: ${serverName}`);
|
|
32
|
+
context.writer.writeInfo("Available: " + servers.map((s) => s.name).join(", "));
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return server;
|
|
36
|
+
}
|
|
37
|
+
function serverUrl(server) {
|
|
38
|
+
return server.url.replace(/\/+$/, "");
|
|
39
|
+
}
|
|
40
|
+
function formatBytes(bytes) {
|
|
41
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
42
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
43
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
44
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
45
|
+
}
|
|
46
|
+
function parseServerAndPath(value, context, args) {
|
|
47
|
+
const serverArg = args?.["server"];
|
|
48
|
+
const pathArg = args?.["path"];
|
|
49
|
+
if (serverArg && pathArg) {
|
|
50
|
+
return [String(serverArg), String(pathArg)];
|
|
51
|
+
}
|
|
52
|
+
if (!value?.trim()) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const parts = value.trim().split(/\s+/);
|
|
56
|
+
if (parts.length < 2) {
|
|
57
|
+
if (serverArg && parts.length >= 1) {
|
|
58
|
+
return [String(serverArg), parts.join(" ")];
|
|
59
|
+
}
|
|
60
|
+
if (pathArg && parts.length >= 1) {
|
|
61
|
+
return [parts[0], String(pathArg)];
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return [parts[0], parts.slice(1).join(" ")];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/lib/processors/cli-scp-ls-processor.ts
|
|
69
|
+
var CliScpLsProcessor = class {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.command = "ls";
|
|
72
|
+
this.description = "List files and directories on a remote server";
|
|
73
|
+
this.acceptsRawInput = true;
|
|
74
|
+
this.valueRequired = true;
|
|
75
|
+
this.parameters = [
|
|
76
|
+
{
|
|
77
|
+
name: "server",
|
|
78
|
+
description: "Server name",
|
|
79
|
+
required: true,
|
|
80
|
+
type: "string"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "path",
|
|
84
|
+
description: "Remote directory path",
|
|
85
|
+
required: true,
|
|
86
|
+
type: "string"
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
async processCommand(command, context) {
|
|
91
|
+
const parsed = parseServerAndPath(command.value, context, command.args);
|
|
92
|
+
if (!parsed) {
|
|
93
|
+
context.writer.writeError("Usage: scp ls <server> <path>");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const [serverName, path] = parsed;
|
|
97
|
+
const server = resolveServer(serverName, context);
|
|
98
|
+
if (!server) return;
|
|
99
|
+
const transferService = context.services.get(
|
|
100
|
+
IScpTransferService_TOKEN
|
|
101
|
+
);
|
|
102
|
+
if (!transferService) {
|
|
103
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
context.spinner?.show(`Listing ${path} on ${server.name}...`);
|
|
107
|
+
try {
|
|
108
|
+
const entries = await transferService.ls(
|
|
109
|
+
serverUrl(server),
|
|
110
|
+
path,
|
|
111
|
+
server.headers
|
|
112
|
+
);
|
|
113
|
+
context.spinner?.hide();
|
|
114
|
+
if (entries.length === 0) {
|
|
115
|
+
context.writer.writeInfo(`Directory is empty: ${path}`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const headers = ["Name", "Type", "Size", "Modified"];
|
|
119
|
+
const rows = entries.map((entry) => [
|
|
120
|
+
entry.name,
|
|
121
|
+
entry.type,
|
|
122
|
+
entry.type === "file" ? formatBytes(entry.size) : "-",
|
|
123
|
+
entry.modified || "-"
|
|
124
|
+
]);
|
|
125
|
+
context.writer.writeTable(headers, rows);
|
|
126
|
+
context.writer.writeInfo(`${entries.length} item(s)`);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
context.spinner?.hide();
|
|
129
|
+
context.writer.writeError(err.message || "Failed to list directory");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
writeDescription(context) {
|
|
133
|
+
context.writer.writeln("List files and directories on a remote server.");
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/lib/processors/cli-scp-cat-processor.ts
|
|
138
|
+
var CliScpCatProcessor = class {
|
|
139
|
+
constructor() {
|
|
140
|
+
this.command = "cat";
|
|
141
|
+
this.description = "Display contents of a remote file";
|
|
142
|
+
this.acceptsRawInput = true;
|
|
143
|
+
this.valueRequired = true;
|
|
144
|
+
this.parameters = [
|
|
145
|
+
{
|
|
146
|
+
name: "server",
|
|
147
|
+
description: "Server name",
|
|
148
|
+
required: true,
|
|
149
|
+
type: "string"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "path",
|
|
153
|
+
description: "Remote file path",
|
|
154
|
+
required: true,
|
|
155
|
+
type: "string"
|
|
156
|
+
}
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
async processCommand(command, context) {
|
|
160
|
+
const parsed = parseServerAndPath(command.value, context, command.args);
|
|
161
|
+
if (!parsed) {
|
|
162
|
+
context.writer.writeError("Usage: scp cat <server> <path>");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const [serverName, path] = parsed;
|
|
166
|
+
const server = resolveServer(serverName, context);
|
|
167
|
+
if (!server) return;
|
|
168
|
+
const transferService = context.services.get(
|
|
169
|
+
IScpTransferService_TOKEN
|
|
170
|
+
);
|
|
171
|
+
if (!transferService) {
|
|
172
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
context.spinner?.show(`Reading ${path} on ${server.name}...`);
|
|
176
|
+
try {
|
|
177
|
+
const content = await transferService.cat(
|
|
178
|
+
serverUrl(server),
|
|
179
|
+
path,
|
|
180
|
+
server.headers
|
|
181
|
+
);
|
|
182
|
+
context.spinner?.hide();
|
|
183
|
+
context.writer.writeln(content);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
context.spinner?.hide();
|
|
186
|
+
context.writer.writeError(err.message || "Failed to read file");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
writeDescription(context) {
|
|
190
|
+
context.writer.writeln("Display the contents of a remote file.");
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var CliScpDownloadProcessor = class {
|
|
194
|
+
constructor() {
|
|
195
|
+
this.command = "download";
|
|
196
|
+
this.aliases = ["get"];
|
|
197
|
+
this.description = "Download a file from a remote server";
|
|
198
|
+
this.acceptsRawInput = true;
|
|
199
|
+
this.valueRequired = true;
|
|
200
|
+
this.parameters = [
|
|
201
|
+
{
|
|
202
|
+
name: "server",
|
|
203
|
+
description: "Server name",
|
|
204
|
+
required: false,
|
|
205
|
+
type: "string"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "remote-path",
|
|
209
|
+
aliases: ["path"],
|
|
210
|
+
description: "Remote file path",
|
|
211
|
+
required: false,
|
|
212
|
+
type: "string"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "local-path",
|
|
216
|
+
description: "Local destination path",
|
|
217
|
+
required: false,
|
|
218
|
+
type: "string"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
name: "save",
|
|
222
|
+
description: "Save directly to browser downloads instead of virtual filesystem",
|
|
223
|
+
required: false,
|
|
224
|
+
type: "boolean"
|
|
225
|
+
}
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
async processCommand(command, context) {
|
|
229
|
+
const args = command.args || {};
|
|
230
|
+
let serverName;
|
|
231
|
+
let remotePath;
|
|
232
|
+
let localPath;
|
|
233
|
+
if (args["server"] && (args["remote-path"] || args["path"])) {
|
|
234
|
+
serverName = String(args["server"]);
|
|
235
|
+
remotePath = String(args["remote-path"] || args["path"]);
|
|
236
|
+
localPath = args["local-path"] ? String(args["local-path"]) : void 0;
|
|
237
|
+
} else {
|
|
238
|
+
const value = command.value?.trim();
|
|
239
|
+
if (!value) {
|
|
240
|
+
context.writer.writeError("Usage: scp download <server> <remote-path> [local-path]");
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const parts = value.split(/\s+/);
|
|
244
|
+
if (parts.length < 2) {
|
|
245
|
+
context.writer.writeError("Usage: scp download <server> <remote-path> [local-path]");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
serverName = parts[0];
|
|
249
|
+
remotePath = parts[1];
|
|
250
|
+
localPath = parts[2];
|
|
251
|
+
}
|
|
252
|
+
if (!serverName || !remotePath) {
|
|
253
|
+
context.writer.writeError("Usage: scp download <server> <remote-path> [local-path]");
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
localPath = localPath || remotePath.split("/").pop() || "download";
|
|
257
|
+
const server = resolveServer(serverName, context);
|
|
258
|
+
if (!server) return;
|
|
259
|
+
const transferService = context.services.get(
|
|
260
|
+
IScpTransferService_TOKEN
|
|
261
|
+
);
|
|
262
|
+
if (!transferService) {
|
|
263
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const useBrowserDownload = command.args?.["save"] === true;
|
|
267
|
+
context.spinner?.show(`Downloading ${remotePath} from ${server.name}...`);
|
|
268
|
+
const abortController = new AbortController();
|
|
269
|
+
const abortSub = context.onAbort.subscribe(() => abortController.abort());
|
|
270
|
+
try {
|
|
271
|
+
let lastProgressUpdate = 0;
|
|
272
|
+
const { content, size } = await transferService.download(
|
|
273
|
+
serverUrl(server),
|
|
274
|
+
remotePath,
|
|
275
|
+
server.headers,
|
|
276
|
+
(received, total) => {
|
|
277
|
+
const now = Date.now();
|
|
278
|
+
if (now - lastProgressUpdate < 200) return;
|
|
279
|
+
lastProgressUpdate = now;
|
|
280
|
+
if (total > 0) {
|
|
281
|
+
const pct = Math.round(received / total * 100);
|
|
282
|
+
context.spinner?.show(
|
|
283
|
+
`Downloading ${remotePath}... ${pct}% (${formatBytes(received)}/${formatBytes(total)})`
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
context.spinner?.show(
|
|
287
|
+
`Downloading ${remotePath}... ${formatBytes(received)}`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
abortController.signal
|
|
292
|
+
);
|
|
293
|
+
context.spinner?.hide();
|
|
294
|
+
if (useBrowserDownload) {
|
|
295
|
+
const fileService = context.services.get(
|
|
296
|
+
cliCore.ICliFileTransferService_TOKEN
|
|
297
|
+
);
|
|
298
|
+
if (fileService) {
|
|
299
|
+
fileService.downloadToBrowser(localPath, content);
|
|
300
|
+
context.writer.writeSuccess(
|
|
301
|
+
`Downloaded ${formatBytes(size)} to browser downloads as "${localPath}"`
|
|
302
|
+
);
|
|
303
|
+
} else {
|
|
304
|
+
context.writer.writeError("File transfer service not available for browser download.");
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
const fileService = context.services.get(
|
|
308
|
+
cliCore.ICliFileTransferService_TOKEN
|
|
309
|
+
);
|
|
310
|
+
if (fileService) {
|
|
311
|
+
await fileService.writeFile(localPath, content);
|
|
312
|
+
context.writer.writeSuccess(
|
|
313
|
+
`Downloaded ${formatBytes(size)} to "${localPath}"`
|
|
314
|
+
);
|
|
315
|
+
} else {
|
|
316
|
+
context.writer.writeError("File transfer service not available.");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} catch (err) {
|
|
320
|
+
context.spinner?.hide();
|
|
321
|
+
context.writer.writeError(err.message || "Download failed");
|
|
322
|
+
} finally {
|
|
323
|
+
abortSub.unsubscribe();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
writeDescription(context) {
|
|
327
|
+
context.writer.writeln("Download a file from a remote server.");
|
|
328
|
+
context.writer.writeln("Usage: scp download <server> <remote-path> [local-path]");
|
|
329
|
+
context.writer.writeln(" --save Save directly to browser downloads");
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var CliScpUploadProcessor = class {
|
|
333
|
+
constructor() {
|
|
334
|
+
this.command = "upload";
|
|
335
|
+
this.aliases = ["put"];
|
|
336
|
+
this.description = "Upload a local file to a remote server";
|
|
337
|
+
this.acceptsRawInput = true;
|
|
338
|
+
this.valueRequired = true;
|
|
339
|
+
this.parameters = [
|
|
340
|
+
{
|
|
341
|
+
name: "server",
|
|
342
|
+
description: "Server name",
|
|
343
|
+
required: true,
|
|
344
|
+
type: "string"
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "local-path",
|
|
348
|
+
description: "Local file path",
|
|
349
|
+
required: true,
|
|
350
|
+
type: "string"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "remote-path",
|
|
354
|
+
description: "Remote destination path",
|
|
355
|
+
required: true,
|
|
356
|
+
type: "string"
|
|
357
|
+
}
|
|
358
|
+
];
|
|
359
|
+
}
|
|
360
|
+
async processCommand(command, context) {
|
|
361
|
+
const args = command.args || {};
|
|
362
|
+
let serverName;
|
|
363
|
+
let localPath;
|
|
364
|
+
let remotePath;
|
|
365
|
+
if (args["server"] && args["local-path"] && args["remote-path"]) {
|
|
366
|
+
serverName = String(args["server"]);
|
|
367
|
+
localPath = String(args["local-path"]);
|
|
368
|
+
remotePath = String(args["remote-path"]);
|
|
369
|
+
} else {
|
|
370
|
+
const value = command.value?.trim();
|
|
371
|
+
if (!value) {
|
|
372
|
+
context.writer.writeError("Usage: scp upload <server> <local-path> <remote-path>");
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const parts = value.split(/\s+/);
|
|
376
|
+
if (parts.length < 3) {
|
|
377
|
+
context.writer.writeError("Usage: scp upload <server> <local-path> <remote-path>");
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
serverName = parts[0];
|
|
381
|
+
localPath = parts[1];
|
|
382
|
+
remotePath = parts[2];
|
|
383
|
+
}
|
|
384
|
+
if (!serverName || !localPath || !remotePath) {
|
|
385
|
+
context.writer.writeError("Usage: scp upload <server> <local-path> <remote-path>");
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const server = resolveServer(serverName, context);
|
|
389
|
+
if (!server) return;
|
|
390
|
+
const fileService = context.services.get(
|
|
391
|
+
cliCore.ICliFileTransferService_TOKEN
|
|
392
|
+
);
|
|
393
|
+
if (!fileService) {
|
|
394
|
+
context.writer.writeError("File transfer service not available.");
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const transferService = context.services.get(
|
|
398
|
+
IScpTransferService_TOKEN
|
|
399
|
+
);
|
|
400
|
+
if (!transferService) {
|
|
401
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
context.spinner?.show(`Reading local file "${localPath}"...`);
|
|
405
|
+
try {
|
|
406
|
+
const content = await fileService.readFile(localPath);
|
|
407
|
+
if (content === null) {
|
|
408
|
+
context.spinner?.hide();
|
|
409
|
+
context.writer.writeError(`Local file not found: ${localPath}`);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const filename = localPath.split("/").pop() || "file";
|
|
413
|
+
context.spinner?.show(
|
|
414
|
+
`Uploading "${filename}" (${formatBytes(content.length)}) to ${server.name}:${remotePath}...`
|
|
415
|
+
);
|
|
416
|
+
await transferService.upload(
|
|
417
|
+
serverUrl(server),
|
|
418
|
+
remotePath,
|
|
419
|
+
content,
|
|
420
|
+
filename,
|
|
421
|
+
server.headers
|
|
422
|
+
);
|
|
423
|
+
context.spinner?.hide();
|
|
424
|
+
context.writer.writeSuccess(
|
|
425
|
+
`Uploaded "${filename}" (${formatBytes(content.length)}) to ${server.name}:${remotePath}`
|
|
426
|
+
);
|
|
427
|
+
} catch (err) {
|
|
428
|
+
context.spinner?.hide();
|
|
429
|
+
context.writer.writeError(err.message || "Upload failed");
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
writeDescription(context) {
|
|
433
|
+
context.writer.writeln("Upload a local file to a remote server.");
|
|
434
|
+
context.writer.writeln("Usage: scp upload <server> <local-path> <remote-path>");
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/lib/processors/cli-scp-rm-processor.ts
|
|
439
|
+
var CliScpRmProcessor = class {
|
|
440
|
+
constructor() {
|
|
441
|
+
this.command = "rm";
|
|
442
|
+
this.description = "Delete a file on a remote server";
|
|
443
|
+
this.acceptsRawInput = true;
|
|
444
|
+
this.valueRequired = true;
|
|
445
|
+
this.parameters = [
|
|
446
|
+
{
|
|
447
|
+
name: "server",
|
|
448
|
+
description: "Server name",
|
|
449
|
+
required: true,
|
|
450
|
+
type: "string"
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
name: "path",
|
|
454
|
+
description: "Remote file path to delete",
|
|
455
|
+
required: true,
|
|
456
|
+
type: "string"
|
|
457
|
+
}
|
|
458
|
+
];
|
|
459
|
+
}
|
|
460
|
+
async processCommand(command, context) {
|
|
461
|
+
const parsed = parseServerAndPath(command.value, context, command.args);
|
|
462
|
+
if (!parsed) {
|
|
463
|
+
context.writer.writeError("Usage: scp rm <server> <path>");
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const [serverName, path] = parsed;
|
|
467
|
+
const server = resolveServer(serverName, context);
|
|
468
|
+
if (!server) return;
|
|
469
|
+
const transferService = context.services.get(
|
|
470
|
+
IScpTransferService_TOKEN
|
|
471
|
+
);
|
|
472
|
+
if (!transferService) {
|
|
473
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
context.spinner?.show(`Deleting ${path} on ${server.name}...`);
|
|
477
|
+
try {
|
|
478
|
+
await transferService.rm(
|
|
479
|
+
serverUrl(server),
|
|
480
|
+
path,
|
|
481
|
+
server.headers
|
|
482
|
+
);
|
|
483
|
+
context.spinner?.hide();
|
|
484
|
+
context.writer.writeSuccess(`Deleted: ${server.name}:${path}`);
|
|
485
|
+
} catch (err) {
|
|
486
|
+
context.spinner?.hide();
|
|
487
|
+
context.writer.writeError(err.message || "Failed to delete file");
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
writeDescription(context) {
|
|
491
|
+
context.writer.writeln("Delete a file on a remote server.");
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// src/lib/processors/cli-scp-mkdir-processor.ts
|
|
496
|
+
var CliScpMkdirProcessor = class {
|
|
497
|
+
constructor() {
|
|
498
|
+
this.command = "mkdir";
|
|
499
|
+
this.description = "Create a directory on a remote server";
|
|
500
|
+
this.acceptsRawInput = true;
|
|
501
|
+
this.valueRequired = true;
|
|
502
|
+
this.parameters = [
|
|
503
|
+
{
|
|
504
|
+
name: "server",
|
|
505
|
+
description: "Server name",
|
|
506
|
+
required: true,
|
|
507
|
+
type: "string"
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: "path",
|
|
511
|
+
description: "Remote directory path to create",
|
|
512
|
+
required: true,
|
|
513
|
+
type: "string"
|
|
514
|
+
}
|
|
515
|
+
];
|
|
516
|
+
}
|
|
517
|
+
async processCommand(command, context) {
|
|
518
|
+
const parsed = parseServerAndPath(command.value, context, command.args);
|
|
519
|
+
if (!parsed) {
|
|
520
|
+
context.writer.writeError("Usage: scp mkdir <server> <path>");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const [serverName, path] = parsed;
|
|
524
|
+
const server = resolveServer(serverName, context);
|
|
525
|
+
if (!server) return;
|
|
526
|
+
const transferService = context.services.get(
|
|
527
|
+
IScpTransferService_TOKEN
|
|
528
|
+
);
|
|
529
|
+
if (!transferService) {
|
|
530
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
context.spinner?.show(`Creating directory ${path} on ${server.name}...`);
|
|
534
|
+
try {
|
|
535
|
+
await transferService.mkdir(
|
|
536
|
+
serverUrl(server),
|
|
537
|
+
path,
|
|
538
|
+
server.headers
|
|
539
|
+
);
|
|
540
|
+
context.spinner?.hide();
|
|
541
|
+
context.writer.writeSuccess(`Created directory: ${server.name}:${path}`);
|
|
542
|
+
} catch (err) {
|
|
543
|
+
context.spinner?.hide();
|
|
544
|
+
context.writer.writeError(err.message || "Failed to create directory");
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
writeDescription(context) {
|
|
548
|
+
context.writer.writeln("Create a directory on a remote server.");
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
// src/lib/processors/cli-scp-stat-processor.ts
|
|
553
|
+
var CliScpStatProcessor = class {
|
|
554
|
+
constructor() {
|
|
555
|
+
this.command = "stat";
|
|
556
|
+
this.description = "Show file or directory information on a remote server";
|
|
557
|
+
this.acceptsRawInput = true;
|
|
558
|
+
this.valueRequired = true;
|
|
559
|
+
this.parameters = [
|
|
560
|
+
{
|
|
561
|
+
name: "server",
|
|
562
|
+
description: "Server name",
|
|
563
|
+
required: true,
|
|
564
|
+
type: "string"
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
name: "path",
|
|
568
|
+
description: "Remote file or directory path",
|
|
569
|
+
required: true,
|
|
570
|
+
type: "string"
|
|
571
|
+
}
|
|
572
|
+
];
|
|
573
|
+
}
|
|
574
|
+
async processCommand(command, context) {
|
|
575
|
+
const parsed = parseServerAndPath(command.value, context, command.args);
|
|
576
|
+
if (!parsed) {
|
|
577
|
+
context.writer.writeError("Usage: scp stat <server> <path>");
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const [serverName, path] = parsed;
|
|
581
|
+
const server = resolveServer(serverName, context);
|
|
582
|
+
if (!server) return;
|
|
583
|
+
const transferService = context.services.get(
|
|
584
|
+
IScpTransferService_TOKEN
|
|
585
|
+
);
|
|
586
|
+
if (!transferService) {
|
|
587
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
context.spinner?.show(`Getting info for ${path} on ${server.name}...`);
|
|
591
|
+
try {
|
|
592
|
+
const stat = await transferService.stat(
|
|
593
|
+
serverUrl(server),
|
|
594
|
+
path,
|
|
595
|
+
server.headers
|
|
596
|
+
);
|
|
597
|
+
context.spinner?.hide();
|
|
598
|
+
const entries = {
|
|
599
|
+
Name: stat.name,
|
|
600
|
+
Type: stat.type,
|
|
601
|
+
Size: formatBytes(stat.size),
|
|
602
|
+
Modified: stat.modified || "-",
|
|
603
|
+
Created: stat.created || "-"
|
|
604
|
+
};
|
|
605
|
+
if (stat.permissions) {
|
|
606
|
+
entries["Permissions"] = stat.permissions;
|
|
607
|
+
}
|
|
608
|
+
context.writer.writeKeyValue(entries);
|
|
609
|
+
} catch (err) {
|
|
610
|
+
context.spinner?.hide();
|
|
611
|
+
context.writer.writeError(err.message || "Failed to get file info");
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
writeDescription(context) {
|
|
615
|
+
context.writer.writeln("Show file or directory information on a remote server.");
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// src/lib/processors/cli-scp-command-processor.ts
|
|
620
|
+
var CliScpCommandCommandProcessor = class {
|
|
621
|
+
constructor() {
|
|
622
|
+
this.command = "scp";
|
|
623
|
+
this.description = "SCP-like file transfer between browser and remote servers";
|
|
624
|
+
this.author = cliCore.DefaultLibraryAuthor;
|
|
625
|
+
this.version = LIBRARY_VERSION;
|
|
626
|
+
this.acceptsRawInput = true;
|
|
627
|
+
this.processors = [
|
|
628
|
+
new CliScpLsProcessor(),
|
|
629
|
+
new CliScpCatProcessor(),
|
|
630
|
+
new CliScpDownloadProcessor(),
|
|
631
|
+
new CliScpUploadProcessor(),
|
|
632
|
+
new CliScpRmProcessor(),
|
|
633
|
+
new CliScpMkdirProcessor(),
|
|
634
|
+
new CliScpStatProcessor()
|
|
635
|
+
];
|
|
636
|
+
}
|
|
637
|
+
async processCommand(command, context) {
|
|
638
|
+
const value = command.value?.trim();
|
|
639
|
+
if (value && value.includes(":") && !value.startsWith("-")) {
|
|
640
|
+
const colonIdx = value.indexOf(":");
|
|
641
|
+
const spaceBeforeColon = value.lastIndexOf(" ", colonIdx);
|
|
642
|
+
if (spaceBeforeColon === -1) {
|
|
643
|
+
const serverName = value.substring(0, colonIdx);
|
|
644
|
+
const rest = value.substring(colonIdx + 1);
|
|
645
|
+
const parts2 = rest.trim().split(/\s+/);
|
|
646
|
+
const remotePath = parts2[0];
|
|
647
|
+
const localPath = parts2[1] || remotePath.split("/").pop() || "download";
|
|
648
|
+
if (remotePath) {
|
|
649
|
+
await this.doDownload(serverName, remotePath, localPath, command, context);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const parts = value.split(/\s+/);
|
|
654
|
+
if (parts.length >= 2) {
|
|
655
|
+
const secondPart = parts[1];
|
|
656
|
+
if (secondPart.includes(":")) {
|
|
657
|
+
const localPath = parts[0];
|
|
658
|
+
const srvColonIdx = secondPart.indexOf(":");
|
|
659
|
+
const serverName = secondPart.substring(0, srvColonIdx);
|
|
660
|
+
const remotePath = secondPart.substring(srvColonIdx + 1);
|
|
661
|
+
if (remotePath) {
|
|
662
|
+
await this.doUpload(serverName, localPath, remotePath, context);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
context.executor.showHelp(command, context);
|
|
669
|
+
}
|
|
670
|
+
writeDescription(context) {
|
|
671
|
+
context.writer.writeln(this.description);
|
|
672
|
+
}
|
|
673
|
+
async doDownload(serverName, remotePath, localPath, command, context) {
|
|
674
|
+
const server = resolveServer(serverName, context);
|
|
675
|
+
if (!server) return;
|
|
676
|
+
const transferService = context.services.get(
|
|
677
|
+
IScpTransferService_TOKEN
|
|
678
|
+
);
|
|
679
|
+
if (!transferService) {
|
|
680
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const useBrowserDownload = command.args?.["save"] === true;
|
|
684
|
+
context.spinner?.show(`Downloading ${remotePath} from ${server.name}...`);
|
|
685
|
+
try {
|
|
686
|
+
let lastProgressUpdate = 0;
|
|
687
|
+
const { content, size } = await transferService.download(
|
|
688
|
+
serverUrl(server),
|
|
689
|
+
remotePath,
|
|
690
|
+
server.headers,
|
|
691
|
+
(received, total) => {
|
|
692
|
+
const now = Date.now();
|
|
693
|
+
if (now - lastProgressUpdate < 200) return;
|
|
694
|
+
lastProgressUpdate = now;
|
|
695
|
+
if (total > 0) {
|
|
696
|
+
const pct = Math.round(received / total * 100);
|
|
697
|
+
context.spinner?.show(
|
|
698
|
+
`Downloading ${remotePath}... ${pct}% (${formatBytes(received)}/${formatBytes(total)})`
|
|
699
|
+
);
|
|
700
|
+
} else {
|
|
701
|
+
context.spinner?.show(
|
|
702
|
+
`Downloading ${remotePath}... ${formatBytes(received)}`
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
context.spinner?.hide();
|
|
708
|
+
const fileService = context.services.get(
|
|
709
|
+
cliCore.ICliFileTransferService_TOKEN
|
|
710
|
+
);
|
|
711
|
+
if (!fileService) {
|
|
712
|
+
context.writer.writeError("File transfer service not available.");
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (useBrowserDownload) {
|
|
716
|
+
fileService.downloadToBrowser(localPath, content);
|
|
717
|
+
context.writer.writeSuccess(
|
|
718
|
+
`Downloaded ${formatBytes(size)} to browser downloads as "${localPath}"`
|
|
719
|
+
);
|
|
720
|
+
} else {
|
|
721
|
+
await fileService.writeFile(localPath, content);
|
|
722
|
+
context.writer.writeSuccess(
|
|
723
|
+
`Downloaded ${formatBytes(size)} to "${localPath}"`
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
} catch (err) {
|
|
727
|
+
context.spinner?.hide();
|
|
728
|
+
context.writer.writeError(err.message || "Download failed");
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
async doUpload(serverName, localPath, remotePath, context) {
|
|
732
|
+
const server = resolveServer(serverName, context);
|
|
733
|
+
if (!server) return;
|
|
734
|
+
const fileService = context.services.get(
|
|
735
|
+
cliCore.ICliFileTransferService_TOKEN
|
|
736
|
+
);
|
|
737
|
+
if (!fileService) {
|
|
738
|
+
context.writer.writeError("File transfer service not available.");
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const transferService = context.services.get(
|
|
742
|
+
IScpTransferService_TOKEN
|
|
743
|
+
);
|
|
744
|
+
if (!transferService) {
|
|
745
|
+
context.writer.writeError("SCP transfer service not available.");
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
context.spinner?.show(`Reading local file "${localPath}"...`);
|
|
749
|
+
try {
|
|
750
|
+
const content = await fileService.readFile(localPath);
|
|
751
|
+
if (content === null) {
|
|
752
|
+
context.spinner?.hide();
|
|
753
|
+
context.writer.writeError(`Local file not found: ${localPath}`);
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
const filename = localPath.split("/").pop() || "file";
|
|
757
|
+
context.spinner?.show(
|
|
758
|
+
`Uploading "${filename}" (${formatBytes(content.length)}) to ${server.name}:${remotePath}...`
|
|
759
|
+
);
|
|
760
|
+
await transferService.upload(
|
|
761
|
+
serverUrl(server),
|
|
762
|
+
remotePath,
|
|
763
|
+
content,
|
|
764
|
+
filename,
|
|
765
|
+
server.headers
|
|
766
|
+
);
|
|
767
|
+
context.spinner?.hide();
|
|
768
|
+
context.writer.writeSuccess(
|
|
769
|
+
`Uploaded "${filename}" (${formatBytes(content.length)}) to ${server.name}:${remotePath}`
|
|
770
|
+
);
|
|
771
|
+
} catch (err) {
|
|
772
|
+
context.spinner?.hide();
|
|
773
|
+
context.writer.writeError(err.message || "Upload failed");
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/lib/services/scp-transfer.service.ts
|
|
779
|
+
var ScpTransferService = class {
|
|
780
|
+
async ls(serverUrl2, path, headers) {
|
|
781
|
+
const res = await this._fetch(`${serverUrl2}/api/cli/fs/ls?path=${encodeURIComponent(path)}`, {
|
|
782
|
+
headers
|
|
783
|
+
});
|
|
784
|
+
const data = await res.json();
|
|
785
|
+
return data.entries;
|
|
786
|
+
}
|
|
787
|
+
async cat(serverUrl2, path, headers) {
|
|
788
|
+
const res = await this._fetch(`${serverUrl2}/api/cli/fs/cat?path=${encodeURIComponent(path)}`, {
|
|
789
|
+
headers
|
|
790
|
+
});
|
|
791
|
+
const data = await res.json();
|
|
792
|
+
return data.content;
|
|
793
|
+
}
|
|
794
|
+
async stat(serverUrl2, path, headers) {
|
|
795
|
+
const res = await this._fetch(`${serverUrl2}/api/cli/fs/stat?path=${encodeURIComponent(path)}`, {
|
|
796
|
+
headers
|
|
797
|
+
});
|
|
798
|
+
return await res.json();
|
|
799
|
+
}
|
|
800
|
+
async download(serverUrl2, path, headers, onProgress, signal) {
|
|
801
|
+
const res = await this._fetch(`${serverUrl2}/api/cli/fs/download?path=${encodeURIComponent(path)}`, {
|
|
802
|
+
headers,
|
|
803
|
+
signal
|
|
804
|
+
});
|
|
805
|
+
const contentLength = parseInt(res.headers.get("content-length") || "0", 10);
|
|
806
|
+
const reader = res.body?.getReader();
|
|
807
|
+
if (!reader) {
|
|
808
|
+
const text = await res.text();
|
|
809
|
+
return { content: text, size: text.length };
|
|
810
|
+
}
|
|
811
|
+
const chunks = [];
|
|
812
|
+
let receivedBytes = 0;
|
|
813
|
+
while (true) {
|
|
814
|
+
const { done, value } = await reader.read();
|
|
815
|
+
if (done) break;
|
|
816
|
+
chunks.push(value);
|
|
817
|
+
receivedBytes += value.length;
|
|
818
|
+
onProgress?.(receivedBytes, contentLength);
|
|
819
|
+
}
|
|
820
|
+
const combined = new Uint8Array(receivedBytes);
|
|
821
|
+
let offset = 0;
|
|
822
|
+
for (const chunk of chunks) {
|
|
823
|
+
combined.set(chunk, offset);
|
|
824
|
+
offset += chunk.length;
|
|
825
|
+
}
|
|
826
|
+
return {
|
|
827
|
+
content: new TextDecoder().decode(combined),
|
|
828
|
+
size: receivedBytes
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
async upload(serverUrl2, remotePath, content, filename, headers) {
|
|
832
|
+
const formData = new FormData();
|
|
833
|
+
formData.append("path", remotePath);
|
|
834
|
+
formData.append("file", new Blob([content]), filename);
|
|
835
|
+
await this._fetch(`${serverUrl2}/api/cli/fs/upload`, {
|
|
836
|
+
method: "POST",
|
|
837
|
+
body: formData,
|
|
838
|
+
headers
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
async mkdir(serverUrl2, path, headers) {
|
|
842
|
+
await this._fetch(`${serverUrl2}/api/cli/fs/mkdir`, {
|
|
843
|
+
method: "POST",
|
|
844
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
845
|
+
body: JSON.stringify({ path })
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
async rm(serverUrl2, path, headers) {
|
|
849
|
+
await this._fetch(`${serverUrl2}/api/cli/fs/rm?path=${encodeURIComponent(path)}`, {
|
|
850
|
+
method: "DELETE",
|
|
851
|
+
headers
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
async _fetch(url, init) {
|
|
855
|
+
const res = await fetch(url, init);
|
|
856
|
+
if (!res.ok) {
|
|
857
|
+
const body = await res.text().catch(() => "");
|
|
858
|
+
if (res.status === 403) {
|
|
859
|
+
throw new Error(`Permission denied: ${body || "path is not in server's allowed paths"}`);
|
|
860
|
+
}
|
|
861
|
+
if (res.status === 404) {
|
|
862
|
+
throw new Error(`Not found: ${body || "file or directory does not exist"}`);
|
|
863
|
+
}
|
|
864
|
+
throw new Error(`Server error (${res.status}): ${body || res.statusText}`);
|
|
865
|
+
}
|
|
866
|
+
return res;
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
// src/public-api.ts
|
|
871
|
+
var scpModule = {
|
|
872
|
+
apiVersion: API_VERSION,
|
|
873
|
+
name: "@qodalis/cli-scp",
|
|
874
|
+
processors: [new CliScpCommandCommandProcessor()],
|
|
875
|
+
services: [
|
|
876
|
+
{
|
|
877
|
+
provide: IScpTransferService_TOKEN,
|
|
878
|
+
useValue: new ScpTransferService()
|
|
879
|
+
}
|
|
880
|
+
],
|
|
881
|
+
translations: {
|
|
882
|
+
es: { "cli.scp.description": "Transferencia de archivos tipo SCP" },
|
|
883
|
+
fr: { "cli.scp.description": "Transfert de fichiers de type SCP" },
|
|
884
|
+
de: { "cli.scp.description": "SCP-\xE4hnliche Datei\xFCbertragung" },
|
|
885
|
+
pt: { "cli.scp.description": "Transfer\xEAncia de arquivos tipo SCP" },
|
|
886
|
+
it: { "cli.scp.description": "Trasferimento file di tipo SCP" },
|
|
887
|
+
ja: { "cli.scp.description": "SCP\u98A8\u30D5\u30A1\u30A4\u30EB\u8EE2\u9001" },
|
|
888
|
+
ko: { "cli.scp.description": "SCP \uBC29\uC2DD \uD30C\uC77C \uC804\uC1A1" },
|
|
889
|
+
zh: { "cli.scp.description": "SCP \u98CE\u683C\u6587\u4EF6\u4F20\u8F93" },
|
|
890
|
+
ru: { "cli.scp.description": "\u041F\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0444\u0430\u0439\u043B\u043E\u0432 \u0432 \u0441\u0442\u0438\u043B\u0435 SCP" },
|
|
891
|
+
ro: { "cli.scp.description": "Transfer de fi\u0219iere de tip SCP" }
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
exports.API_VERSION = API_VERSION;
|
|
896
|
+
exports.CliScpCommandCommandProcessor = CliScpCommandCommandProcessor;
|
|
897
|
+
exports.LIBRARY_VERSION = LIBRARY_VERSION;
|
|
898
|
+
exports.scpModule = scpModule;
|
|
899
|
+
//# sourceMappingURL=public-api.js.map
|
|
900
|
+
//# sourceMappingURL=public-api.js.map
|