fix: 移除课程门数上限,避免与每日积分目标冲突
maxCourses 按整门课计数,而积分按课时计;只剩考试的课会白占名额, 曾出现 5 门用光但今日视频积分只拿到 1/3 就停止的情况。现在只由 今日积分完成、没有可学内容或 budgetMinutes 决定收尾。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
0eb4c40629
commit
f41fc72fe2
20 files changed
+45
-106
No files matched your search
+4
-12
@@ -23,7 +23,6 @@ export const SCRIPT_FILE = path.join(ROOT, 'yun-xue-tang-assistant.user.js');
|
||||
// 一层:内置默认值
|
||||
// ---------------------------------------------------------------------------
|
||||
const DEFAULTS = {
|
||||
maxCourses: 0, // 0 = 不限(一直刷到没有未学完的课)
|
||||
budgetMinutes: 0, // 0 = 不限
|
||||
preferShort: true,
|
||||
pointsMode: true, // 每日积分模式:按课时类型计分,四类封顶后停止(文档1/视频3/音频2/微课2)
|
||||
@@ -56,7 +55,6 @@ const DEPRECATED = {
|
||||
};
|
||||
/** 旧参数名 -> 配置字段(保持向后兼容,dev/tests/ 下的脚本还在用) */
|
||||
const ALIASES = {
|
||||
'--max': 'maxCourses',
|
||||
'--budget': 'budgetMinutes',
|
||||
'--restart': 'restartMinutes',
|
||||
'--idle': 'idleRestartMinutes',
|
||||
@@ -110,10 +108,10 @@ if (CONFIG_FILE) {
|
||||
// 命令行解析:--key value / --key=value / --flag
|
||||
// ---------------------------------------------------------------------------
|
||||
const BOOL_KEYS = ['preferShort', 'pointsMode', 'headless', 'check', 'tui', 'color'];
|
||||
const NUM_KEYS = ['maxCourses', 'budgetMinutes', 'restartMinutes', 'idleRestartMinutes', 'port', 'logMaxBytes', 'barkTtl'];
|
||||
const NUM_KEYS = ['budgetMinutes', 'restartMinutes', 'idleRestartMinutes', 'port', 'logMaxBytes', 'barkTtl'];
|
||||
const STR_KEYS = ['origin', 'url', 'profile', 'logFile', 'chrome', 'extraArgs', 'config', 'barkUrl', 'barkGroup'];
|
||||
|
||||
/** kebab-case → camelCase:--max-courses → maxCourses */
|
||||
/** kebab-case → camelCase:--budget-minutes → budgetMinutes */
|
||||
function toCamel(flag) {
|
||||
return flag.replace(/^--/, '').replace(/-([a-z])/g, (m, c) => c.toUpperCase());
|
||||
}
|
||||
@@ -207,7 +205,6 @@ const envStr = (name, cur) => {
|
||||
// ---------------------------------------------------------------------------
|
||||
const merged = { ...DEFAULTS, ...fileConfig };
|
||||
|
||||
merged.maxCourses = envNum('YUN_XUE_TANG_MAX_COURSES', merged.maxCourses);
|
||||
merged.budgetMinutes = envNum('YUN_XUE_TANG_BUDGET_MINUTES', merged.budgetMinutes);
|
||||
merged.restartMinutes = envNum('YUN_XUE_TANG_RESTART_MINUTES', merged.restartMinutes);
|
||||
merged.idleRestartMinutes = envNum('YUN_XUE_TANG_IDLE_RESTART_MINUTES', merged.idleRestartMinutes);
|
||||
@@ -249,7 +246,6 @@ for (const [key, raw] of Object.entries(cliRaw)) {
|
||||
const problems = [...numBad];
|
||||
if (numBad.length === 0) {
|
||||
if (!(merged.port >= 1 && merged.port <= 65535)) problems.push('port 必须在 1-65535 之间,收到 ' + merged.port);
|
||||
if (!(merged.maxCourses >= 0)) problems.push('maxCourses 不能为负,收到 ' + merged.maxCourses);
|
||||
if (!(merged.budgetMinutes >= 0)) problems.push('budgetMinutes 不能为负,收到 ' + merged.budgetMinutes);
|
||||
if (!(merged.restartMinutes >= 0)) problems.push('restartMinutes 不能为负,收到 ' + merged.restartMinutes);
|
||||
if (!(merged.idleRestartMinutes >= 0)) problems.push('idleRestartMinutes 不能为负,收到 ' + merged.idleRestartMinutes);
|
||||
@@ -282,8 +278,6 @@ export const START_URL = merged.url ? String(merged.url) : ORIGIN + '/login.html
|
||||
export const USR = process.env.YUN_XUE_TANG_USR || '';
|
||||
export const PWD = process.env.YUN_XUE_TANG_PWD || '';
|
||||
export const PORT = merged.port;
|
||||
/** 本次最多完成几门课(0 = 不限) */
|
||||
export const MAX_COURSES = merged.maxCourses;
|
||||
/** 运行多少分钟后收尾(0 = 不限) */
|
||||
export const BUDGET_MINUTES = merged.budgetMinutes;
|
||||
export const PROFILE_DIR = merged.profile
|
||||
@@ -352,7 +346,6 @@ export function describeRun() {
|
||||
checkOnly: CHECK_ONLY,
|
||||
headless: !VISIBLE,
|
||||
port: PORT,
|
||||
maxCourses: MAX_COURSES > 0 ? MAX_COURSES : '不限',
|
||||
budgetMinutes: BUDGET_MINUTES > 0 ? BUDGET_MINUTES : '不限',
|
||||
preferShort: PREFER_SHORT,
|
||||
pointsMode: POINTS_MODE,
|
||||
@@ -370,7 +363,6 @@ export function describeRun() {
|
||||
export function helpText() {
|
||||
const rows = [
|
||||
['配置字段', '命令行', '环境变量', '当前生效', '说明'],
|
||||
['maxCourses', '--max-courses', 'YUN_XUE_TANG_MAX_COURSES', MAX_COURSES, '本次最多完成几门课;0 = 不限'],
|
||||
['budgetMinutes', '--budget-minutes', 'YUN_XUE_TANG_BUDGET_MINUTES', BUDGET_MINUTES, '跑多少分钟后收尾;0 = 不限'],
|
||||
['preferShort', '--prefer-short', 'YUN_XUE_TANG_PREFER_SHORT', PREFER_SHORT, '优先总时长最短的课程'],
|
||||
['pointsMode', '--points-mode', 'YUN_XUE_TANG_POINTS_MODE', POINTS_MODE, '每日积分模式:文档1/视频3/音频2/微课2,封顶即停'],
|
||||
@@ -410,11 +402,11 @@ export function helpText() {
|
||||
lines.push('');
|
||||
lines.push('示例:');
|
||||
lines.push(' node runner/headless.mjs --check # 只做环境自检');
|
||||
lines.push(' node runner/headless.mjs --max-courses 3 # 本次最多 3 门');
|
||||
lines.push(' node runner/headless.mjs --budget-minutes 15 # 最多跑 15 分钟');
|
||||
lines.push(' node runner/headless.mjs --headless 0 # 开有界面浏览器调试');
|
||||
lines.push(' node runner/headless.mjs --no-tui # 不用面板,回到逐行日志');
|
||||
lines.push(' node runner/headless.mjs --config ./config/runner.config.mjs # 显式指定配置文件');
|
||||
lines.push('');
|
||||
lines.push('旧参数名(仍然兼容):--max / --budget / --restart / --idle / --log / --log-max / --visible');
|
||||
lines.push('旧参数名(仍然兼容):--budget / --restart / --idle / --log / --log-max / --visible');
|
||||
return lines.join('\n');
|
||||
}
|
||||
Reference in new issue
Block a user