feat: v2.8.0 无头运行器、考试自动交卷、改为退避重试不跳课
新增无头运行能力,解决 Linux 无图形化服务器上无法常驻的问题;同时改掉 "遇到考试课/无进展课就跳过"的策略,改为在同门课上退避重试。 - runner/:自己起无头 Chromium,用 CDP 把构建产物注入页面主世界(等价 @grant none),不装插件、不需要桌面环境或 Xvfb;含浏览器探测与启动参数、 持久化 profile、陈旧 SingletonLock 清理、优雅退出、日志轮转、启动预检 - runner.config.mjs / start-headless.cmd:通用配置 + Windows 一键入口; 凭据只走 YUN_XUE_TANG_USR / YUN_XUE_TANG_PWD 环境变量 - src/exam.js:含考试章节的课程自动进考试 → 开始/继续 → 空卷提交 → 确定, 交卷后靠平台记账推进课程;maxExamTries 限制同门课交卷次数,防不记账时死循环 - 去掉跳过与黑名单:没学完就退避重试(30s 起翻倍,最长 5 分钟), 同门课超过 maxCourseRetries 次才停整轮并提示,替代原 maxConsecutiveFailures - 每完成一门都重新拉列表接口取平台实时状态再选下一门,避免用陈旧队列 - 学习进度改存 sessionStorage(yun-xue-tang-run-state-v3),整页跳转/刷新可续; 运行开关不跨会话,浏览器重启后必须显式开跑 - dev/:新增 real-cdp / real-run / real-test / real-e2e 实跑脚本与 check.mjs 统一静态检查(JS 22 + 批处理 2),替代逐文件 node --check - docs/evidence/headless-linux-evidence.txt + 实跑截图,README 补无头部署章节
This commit is contained in:
1 parent
8193326b70
commit
ae117222df
47 files changed
+6198
-837
No files matched your search
@@ -0,0 +1,62 @@
|
||||
// 环境自检(--check):只读,不登录、不点课程、不动进度。
|
||||
//
|
||||
// 检查项:页面能不能打开、脚本能不能注入、面板是否唯一可见、版本是否可读、
|
||||
// 这个 Chromium 到底带不带 H.264/AAC(服务器上最常见的问题:装了发行版 chromium 却放不了视频)。
|
||||
import { sleep } from './cdp.mjs';
|
||||
import { EXPR_SELF_CHECK } from './page.mjs';
|
||||
|
||||
/**
|
||||
* @param {object} o
|
||||
* @param {object} o.page page.mjs 的 page 对象
|
||||
* @param {Function} o.tickWatchdog 会话里负责注入 / 重登的看护函数
|
||||
* @param {Function} o.isDisconnected 判断 CDP 是否已断开
|
||||
* @param {number} [o.timeoutMs] 注入自检的最长等待
|
||||
* @returns {Promise<{ok:boolean, failed:string[], reason:string}>}
|
||||
*/
|
||||
export async function runSelfCheck(o) {
|
||||
const timeoutMs = o.timeoutMs || 60000;
|
||||
const log = o.log;
|
||||
|
||||
// 等页面加载完 + 注入成功(tickWatchdog 会补注入)
|
||||
const info = await (async () => {
|
||||
const started = Date.now();
|
||||
while (Date.now() - started < timeoutMs) {
|
||||
if (o.isDisconnected()) throw new Error('CDP 连接断开');
|
||||
try {
|
||||
await o.tickWatchdog();
|
||||
const v = await o.page.json(EXPR_SELF_CHECK);
|
||||
if (v && v.api === 'object') return v;
|
||||
} catch (e) { /* 页面仍在加载 */ }
|
||||
await sleep(1000);
|
||||
}
|
||||
throw new Error(Math.round(timeoutMs / 1000) + ' 秒内未能完成注入自检');
|
||||
})();
|
||||
|
||||
const failed = [];
|
||||
const ck = (name, ok, detail) => {
|
||||
log((ok ? ' PASS ' : ' FAIL ') + name + (detail === undefined ? '' : ' → ' + JSON.stringify(detail)));
|
||||
if (!ok) failed.push(name);
|
||||
};
|
||||
|
||||
log('--- 无头环境自检(只读)---');
|
||||
ck('页面可访问', /yunxuetang\.cn$/.test(new URL(info.url).host), info.url);
|
||||
ck('脚本已注入 window.__yunXueTangAuto', info.api === 'object', info.api);
|
||||
ck('面板渲染唯一', info.panels === 1 && info.panelVisible, { 面板数: info.panels, 可见: info.panelVisible });
|
||||
ck('脚本版本可读', /^v\d+\.\d+\.\d+$/.test(info.version || ''), info.version);
|
||||
ck('视频编解码 H.264 可用', info.codecs.h264 === 'probably' || info.codecs.h264 === 'maybe',
|
||||
{ h264: info.codecs.h264, aac: info.codecs.aac, vp9: info.codecs.vp9 });
|
||||
|
||||
log(' 提示:H.264 为 "maybe" 通常仍可播放;为空字符串说明该 Chromium 不带专有编解码器,');
|
||||
log(' 请改装 google-chrome-stable(官方包带 H.264/AAC),否则课程视频会一直是 0 秒。');
|
||||
log(' 页面识别的路由:' + info.route + ' 是否登录页:' + info.isLoginPage);
|
||||
log(' UA:' + String(info.ua).slice(0, 110));
|
||||
if (info.fonts && info.fonts !== 'ok') {
|
||||
log(' 提示:中文字体可能缺失(fonts=' + info.fonts + '),只影响截图观感;需要截图时 apt install fonts-noto-cjk');
|
||||
}
|
||||
|
||||
return {
|
||||
ok: failed.length === 0,
|
||||
failed,
|
||||
reason: failed.length ? '自检失败:' + failed.join('、') : '',
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user