@cloud411716/fancy-webnovel 0.1.99 → 0.2.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/package.json +1 -1
- package/plugins/fancy-scan/index.js +12 -82
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { dirname, join } from 'path';
|
|
6
6
|
import { existsSync } from 'fs';
|
|
7
|
-
import { notify, llmFollowup, spawnScript, startActivity
|
|
7
|
+
import { notify, llmFollowup, spawnScript, startActivity } from '../../infra.js';
|
|
8
8
|
import { scan, PLATFORM_TABLE, platformLabel } from './templates.js';
|
|
9
9
|
|
|
10
10
|
export const inject = ['commands', 'userQuestions'];
|
|
@@ -109,12 +109,10 @@ export async function apply(ctx) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* 执行采集,检测 Chromium
|
|
113
|
-
* 返回 undefined 表示已处理完毕(取消/失败),返回 'retry'
|
|
112
|
+
* 执行采集,检测 Chromium 缺失则提示用户手动安装。
|
|
113
|
+
* 返回 undefined 表示已处理完毕(取消/失败),返回 'retry' 表示重试完成。
|
|
114
114
|
*/
|
|
115
115
|
async function runScanWithChromiumFix(ctx, session, invocation, { platform, length, projectRoot }) {
|
|
116
|
-
const { spawn } = await import('child_process');
|
|
117
|
-
|
|
118
116
|
const runOnce = async (isRetry = false) => {
|
|
119
117
|
const stop = startActivity(session);
|
|
120
118
|
if (isRetry) notify(session, '⏳ 重新采集...\n');
|
|
@@ -147,84 +145,16 @@ async function runScanWithChromiumFix(ctx, session, invocation, { platform, leng
|
|
|
147
145
|
? (scriptResult.error.message || JSON.stringify(scriptResult.error))
|
|
148
146
|
: String(scriptResult.error || '未知错误');
|
|
149
147
|
|
|
150
|
-
// Chromium 未找到 →
|
|
148
|
+
// Chromium 未找到 → 提示用户手动安装
|
|
151
149
|
if (rawErr.includes("Executable doesn't exist") || rawErr.includes('Executable doesn')) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// 用户选择自动安装
|
|
162
|
-
notify(session, '⏳ 正在下载 Chromium 浏览器(首次约 2-3 分钟),请耐心等待...\n');
|
|
163
|
-
const installStop = startActivity(session);
|
|
164
|
-
|
|
165
|
-
// 预先弹出密码框(不等 sudo 提示出现)
|
|
166
|
-
// 密码通过 stdin pipe 传入,用 sudo -S 确保 sudo 从 stdin 读
|
|
167
|
-
const pwdAskPromise = ctx.userQuestions.ask({
|
|
168
|
-
questions: [{
|
|
169
|
-
question: '🔐 安装 Chromium 需要 sudo 权限,请输入密码:',
|
|
170
|
-
hideCustomInput: false,
|
|
171
|
-
}],
|
|
172
|
-
}).then(() => {
|
|
173
|
-
notify(session, '✅ 密码已收到,正在安装...\n');
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const installProc = spawn('sh', ['-c',
|
|
177
|
-
'sudo -S npm install -g playwright@1.40.0 --registry=https://registry.npmmirror.com && ' +
|
|
178
|
-
'sudo -S PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/ playwright install chromium --with-deps'
|
|
179
|
-
], {
|
|
180
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
181
|
-
cwd: process.cwd(),
|
|
182
|
-
});
|
|
183
|
-
const installOut = [], installErr = [];
|
|
184
|
-
|
|
185
|
-
installProc.stdout.on('data', d => { installOut.push(d.toString()); });
|
|
186
|
-
installProc.stderr.on('data', d => { installErr.push(d.toString()); });
|
|
187
|
-
|
|
188
|
-
// 注册 CTRL+C 取消处理:kill 安装进程
|
|
189
|
-
const stopCancel = onUserCancel(session, () => {
|
|
190
|
-
installProc.kill('SIGTERM');
|
|
191
|
-
installStop();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// 预先弹出的密码框结果 → 写入子进程 stdin
|
|
195
|
-
pwdAskPromise.then(async (pwdResult) => {
|
|
196
|
-
const pwd = pwdResult.answers[0]?.custom ?? '';
|
|
197
|
-
if (pwd) installProc.stdin?.write(pwd + '\n');
|
|
198
|
-
}).catch(() => {});
|
|
199
|
-
|
|
200
|
-
return new Promise((resolve) => {
|
|
201
|
-
installProc.on('close', async (code) => {
|
|
202
|
-
// 等预弹框完成
|
|
203
|
-
await Promise.race([
|
|
204
|
-
pwdAskPromise.catch(() => {}),
|
|
205
|
-
new Promise(r => setTimeout(r, 180000)),
|
|
206
|
-
]);
|
|
207
|
-
stopCancel(); // 移除取消监听
|
|
208
|
-
installStop();
|
|
209
|
-
if (code === 0) {
|
|
210
|
-
notify(session, '✅ Chromium 安装完成,正在重新采集...\n');
|
|
211
|
-
const retryResult = await runOnce(true);
|
|
212
|
-
if (!retryResult.ok) {
|
|
213
|
-
const err2 = String(retryResult.error || '未知错误');
|
|
214
|
-
notify(session, scan.notify({ type: 'failed', err: err2 }));
|
|
215
|
-
resolve(undefined);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
handleSuccess(retryResult.output);
|
|
219
|
-
resolve('retry');
|
|
220
|
-
} else {
|
|
221
|
-
const out = installOut.join('').slice(-300);
|
|
222
|
-
const err = installErr.join('').slice(-300);
|
|
223
|
-
notify(session, `❌ Chromium 安装失败(exit ${code})。\n请手动运行以下命令后重试:\n npm install -g playwright@1.40.0 --registry=https://registry.npmmirror.com && PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/ playwright install chromium --with-deps\n\nstdout末尾:\n${out}\n\nstderr末尾:\n${err}`);
|
|
224
|
-
resolve(undefined);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
150
|
+
notify(session,
|
|
151
|
+
'⚠️ 未找到 Chromium 浏览器,请手动安装后再次运行 /fancy-scan。\n\n' +
|
|
152
|
+
'安装命令:\n' +
|
|
153
|
+
' npm install -g playwright@1.40.0 --registry=https://registry.npmmirror.com\n' +
|
|
154
|
+
' PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/ playwright install chromium --with-deps\n\n' +
|
|
155
|
+
'安装完成后重新运行 /fancy-scan 即可。'
|
|
156
|
+
);
|
|
157
|
+
return undefined;
|
|
228
158
|
}
|
|
229
159
|
|
|
230
160
|
notify(session, scan.notify({ type: 'failed', err: rawErr }));
|