顶栏任务状态灯: hr1/hr2四态(运行中/已收工/异常/今日未运行+聊天剩余), 只读挂载runner状态目录

This commit is contained in:
mzl92
2026-08-27 17:17:06 +08:00
parent 896795462a
commit e3cdadab88
4 changed files with 47 additions and 0 deletions
+20
View File
@@ -286,6 +286,26 @@ app.post('/api/users/:id/resetpwd', requireAuth, requireSuper, (req, res) => {
res.json({ ok: true });
});
// ---------- 筛选任务状态(所有登录用户, 读runner状态文件) ----------
app.get('/api/task-status', requireAuth, (req, res) => {
const stateDir = process.env.STATE_DIR || '/state';
const bjToday = new Date(Date.now() + 8 * 3600e3).toISOString().slice(0, 10);
const doneSet = new Set(['time_cutoff', 'chat_exhausted', 'done']);
const errSet = new Set(['login_expired', 'alert', 'tunnel_failed', 'platform_blocked', 'qr_expired', 'error', 'stopped_by_user']);
const out = {};
for (const acct of ['hr1', 'hr2']) {
try {
const s = JSON.parse(fs.readFileSync(path.join(stateDir, `state-${acct}.json`), 'utf8'));
if (s.date !== bjToday) { out[acct] = { state: 'idle', text: '今日未运行' }; continue; }
if (s.status === 'running') out[acct] = { state: 'running', text: '运行中', chatLeft: s.chatLeft };
else if (doneSet.has(s.status)) out[acct] = { state: 'done', text: '已收工', chatLeft: s.chatLeft };
else if (errSet.has(s.status)) out[acct] = { state: 'error', text: '异常停止', detail: s.status };
else out[acct] = { state: 'done', text: '已收工', chatLeft: s.chatLeft };
} catch (_) { out[acct] = { state: 'idle', text: '今日未运行' }; }
}
res.json(out);
});
// ---------- 筛选规则文档(所有登录用户) ----------
app.get('/api/rules', requireAuth, (req, res) => {
res.type('text/markdown; charset=utf-8').send(fs.readFileSync(path.join(__dirname, 'public', 'rules.md'), 'utf8'));