|
1 | 1 | /* eslint-disable @typescript-eslint/no-loop-func */
|
2 | 2 | /* eslint-disable no-await-in-loop */
|
3 |
| -import { spawn } from 'child_process'; |
4 | 3 | import { gunzipSync } from 'zlib';
|
5 | 4 | import { decode } from 'base16384';
|
6 | 5 | import Logger from 'reggol';
|
@@ -94,46 +93,11 @@ export function StaticHTML(context, randomHash) {
|
94 | 93 | return `<html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>@Hydro/XCPC-TOOLS</title></head><body><div id="root"></div><script>window.Context=JSON.parse('${JSON.stringify(context)}')</script><script src="/main.js?${randomHash}"></script></body></html>`;
|
95 | 94 | }
|
96 | 95 |
|
97 |
| -// wait for undefined to write |
98 |
| -export async function remoteRunner(user: string, target: string, targetPort: string, timeout = 10, RETRY = 3, command) { |
99 |
| - let log = ''; |
100 |
| - const defaultCommand = `-o ConnectTimeout=${timeout} -o StrictHostKeyChecking=no -P ${targetPort}`; |
101 |
| - const cmds = { |
102 |
| - exec: [defaultCommand, `${user}@${target}`, command], |
103 |
| - upload: [defaultCommand, command.from, `${user}@${target}:${command.to}`], |
104 |
| - download: [defaultCommand, `${user}@${target}:${command.from.replace('{target}', target)}`, command.to.replace('{target}', target)], |
105 |
| - }; |
106 |
| - let retry = 0; |
107 |
| - while (retry < RETRY) { |
108 |
| - const child = spawn(command.type === 'exec' ? 'ssh' : 'scp', cmds[command.type]); |
109 |
| - // 输出命令行执行的结果 |
110 |
| - let success = false; |
111 |
| - child.stdout.on('data', (data) => { |
112 |
| - success = true; |
113 |
| - log += data; |
114 |
| - }); |
115 |
| - child.stderr.on('data', (data) => { |
116 |
| - success = false; |
117 |
| - log += data; |
118 |
| - }); |
119 |
| - // 执行命令行错误 |
120 |
| - child.on('error', (err) => { |
121 |
| - log += err; |
122 |
| - return { success: false, log }; |
123 |
| - }); |
124 |
| - // 命令行执行结束 |
125 |
| - child.on('close', (e) => { |
126 |
| - if (e === 0) return { success: true, log }; |
127 |
| - if (success) return { success: true, log }; |
128 |
| - log += `retry ${retry} times`; |
129 |
| - retry++; |
130 |
| - }); |
131 |
| - } |
132 |
| - return { success: false, log }; |
133 |
| -} |
134 |
| - |
135 | 96 | export function decodeBinary(file: string) {
|
136 | 97 | if (process.env.NODE_ENV === 'development') return Buffer.from(file, 'base64');
|
137 | 98 | const buf = decode(file);
|
138 | 99 | return gunzipSync(buf);
|
139 | 100 | }
|
| 101 | + |
| 102 | +export * from './commandRunner'; |
| 103 | +export * from './printers'; |
0 commit comments