Add operations overview and category usage tracking

This commit is contained in:
wuyang
2026-11-04 11:10:29 +08:00
parent 7fc9d4d843
commit dde9742f9c
5 changed files with 47 additions and 6 deletions
+17 -2
View File
@@ -106,11 +106,24 @@ function renderLedger() {
table.append(head, body); wrapper.append(table); host.append(wrapper);
}
function showView(view) {
for (const name of ['report', 'evolution', 'daily']) $(`#${name}-view`).hidden = view !== name;
for (const [selector, active] of [['#show-report', view === 'report'], ['#show-evolution', view === 'evolution'], ['#show-daily', view === 'daily']]) {
for (const name of ['overview', 'report', 'evolution', 'daily']) $(`#${name}-view`).hidden = view !== name;
for (const [selector, active] of [['#show-overview', view === 'overview'], ['#show-report', view === 'report'], ['#show-evolution', view === 'evolution'], ['#show-daily', view === 'daily']]) {
$(selector).classList.toggle('active', active); $(selector).setAttribute('aria-pressed', String(active));
}
}
async function openOverview() {
showView('overview'); history.replaceState(null, '', '/');
const host = $('#overview-content'); host.replaceChildren(el('p', '正在读取运营全景…', 'muted'));
try {
const [data, queue] = await Promise.all([api('/api/overview'), api('/api/workqueue')]); host.replaceChildren(); const strategy = data.strategy || {}, market = data.market || {};
const hero = el('section', undefined, 'report-section'); hero.append(el('h2', '方向与当前阶段'), el('p', strategy.mission || '方向待补充'), el('p', strategy.phase || '', 'muted')); const pillars = el('ul'); for (const item of strategy.pillars || []) pillars.append(el('li', item)); hero.append(pillars, el('p', strategy.cadence || '', 'muted')); host.append(hero);
const works = el('section', undefined, 'report-section'); works.append(el('h2', '已发布作品'), el('p', `采样时间:${market.observed_at ? dateTime(market.observed_at) : '暂无'};播放量不是曝光或完播率。`, 'muted'));
for (const v of market.account_videos || []) { const p = el('p'); if (v.bvid) { const a = el('a', v.title); a.href = `https://www.bilibili.com/video/${v.bvid}/`; a.target = '_blank'; a.rel = 'noopener noreferrer'; p.append(a); } else p.append(el('span', v.title)); p.append(document.createTextNode(` · 播放 ${v.views ?? '未知'} · 点赞 ${v.likes ?? '未知'} · 评论 ${v.comments ?? '未知'}`)); works.append(p); } host.append(works);
const budget = el('section', undefined, 'report-section'); budget.append(el('h2', '计划投入'), el('p', (strategy.budget || []).map(x => `${x.name} ${x.percent}%`).join(' · ')), el('p', strategy.budget_note || '', 'muted')); host.append(budget);
const work = el('section', undefined, 'report-section'); work.append(el('h2', '持续工作')); const cats = {content:'内容',engineering:'工程',research:'研究',community:'社区',management:'管理'}, status = {pending:'待继续',running:'进行中',done:'已完成',blocked:'需要处理'}, list = el('ul'); for (const t of queue.tasks || []) if (t.status !== 'done') list.append(el('li', `${cats[t.category] || '管理'} · ${t.title} · ${status[t.status] || t.status}`)); work.append(list); host.append(work);
const trends = el('section', undefined, 'report-section'); trends.append(el('h2', 'B 站公开榜单快照'), el('p', '单时点观察,基于标题和公开数据,不能代表趋势或保证效果。', 'muted')); const ul = el('ul'); for (const v of market.ranking || []) { const li = el('li'); if (v.bvid) { const a = el('a', v.title); a.href = `https://www.bilibili.com/video/${v.bvid}/`; a.target = '_blank'; a.rel = 'noopener noreferrer'; li.append(a); } else li.append(el('span', v.title)); li.append(document.createTextNode(` · ${v.owner} · ${v.views ?? '未知'} 播放`)); ul.append(li); } trends.append(ul); host.append(trends);
} catch (error) { host.replaceChildren(el('p', error.message, 'error')); }
}
async function openDaily() {
showView('daily');
const host = $('#daily-content'); host.replaceChildren(el('p', '正在读取每日记录…', 'muted'));
@@ -190,7 +203,9 @@ async function loadDashboard() {
if (selected && dashboard.reports.some(r => r.id === selected)) await openReport(selected); else renderReport(dashboard.latest);
if (initialView === 'evolution') await openEvolution();
if (initialView === 'daily') await openDaily();
if (!selected && !initialView) await openOverview();
}
$('#show-overview').addEventListener('click', openOverview);
$('#show-evolution').addEventListener('click', openEvolution);
$('#show-daily').addEventListener('click', openDaily);
$('#show-report').addEventListener('click', () => { showView('report'); history.replaceState(null, '', currentReportId ? `/?report=${encodeURIComponent(currentReportId)}` : '/'); });
+1 -1
View File
@@ -16,7 +16,7 @@
<div id="dashboard-view" hidden>
<header class="topbar"><a class="wordmark" href="/">pawplay<span>运营台</span></a><div class="top-right"><span class="private-pill">私有档案</span><button id="logout" class="quiet">退出</button></div></header>
<div class="workspace"><aside class="sidebar"><div class="sidebar-heading"><p class="eyebrow">每周运营</p><h2>进展档案</h2></div><nav id="report-nav" aria-label="历史周报"></nav><div class="sidebar-foot"><span class="status-dot"></span>北京时间归档<br><span class="muted">费用与收益独立核算</span></div></aside>
<main class="main"><nav class="view-tabs" aria-label="浏览内容"><button id="show-report" class="active" type="button" aria-pressed="true">运营报告</button><button id="show-evolution" type="button" aria-pressed="false">演变路径</button><button id="show-daily" type="button" aria-pressed="false">每日计划与复盘</button></nav><div id="report-view"><div class="page-heading"><div><p class="eyebrow">PAWPLAY · WEEKLY REVIEW</p><h1 id="report-title">运营概览</h1><p id="report-period" class="muted"></p></div><a id="download-report" class="download" hidden>下载 JSON ↓</a></div><p id="global-error" class="error" role="alert"></p><div id="report-content"></div><section class="ledger-section"><div class="section-heading"><h2>收支台账</h2><span class="muted">现金、分摊、预估分别保留</span></div><div id="ledger"></div></section></div><section id="evolution-view" hidden><div class="page-heading"><div><p class="eyebrow">PAWPLAY · EVOLUTION</p><h1>演变路径</h1><p class="muted">从起因到下一步,回看每次探索的依据与决定。</p></div></div><div id="evolution-content"></div></section><section id="daily-view" hidden><div class="page-heading"><div><p class="eyebrow">PAWPLAY · DAILY</p><h1>每日计划与复盘</h1><p class="muted">按日期查看计划、执行、证据与下一步。</p></div></div><div id="daily-content"></div></section><footer class="main-footer">PawPlay 猫爪游乐场 <span>让每一笔投入有依据,让每一步进展可回看。</span></footer></main>
<main class="main"><nav class="view-tabs" aria-label="浏览内容"><button id="show-overview" class="active" type="button" aria-pressed="true">运营全景</button><button id="show-report" type="button" aria-pressed="false">运营报告</button><button id="show-evolution" type="button" aria-pressed="false">演变路径</button><button id="show-daily" type="button" aria-pressed="false">每日计划与复盘</button></nav><section id="overview-view"><div class="page-heading"><div><p class="eyebrow">XINGQI · OPERATIONS</p><h1>星栖运营全景</h1><p class="muted">方向、作品、研究和预算,放在一起看。</p></div></div><div id="overview-content"></div></section><div id="report-view" hidden><div class="page-heading"><div><p class="eyebrow">PAWPLAY · WEEKLY REVIEW</p><h1 id="report-title">运营概览</h1><p id="report-period" class="muted"></p></div><a id="download-report" class="download" hidden>下载 JSON ↓</a></div><p id="global-error" class="error" role="alert"></p><div id="report-content"></div><section class="ledger-section"><div class="section-heading"><h2>收支台账</h2><span class="muted">现金、分摊、预估分别保留</span></div><div id="ledger"></div></section></div><section id="evolution-view" hidden><div class="page-heading"><div><p class="eyebrow">PAWPLAY · EVOLUTION</p><h1>演变路径</h1><p class="muted">从起因到下一步,回看每次探索的依据与决定。</p></div></div><div id="evolution-content"></div></section><section id="daily-view" hidden><div class="page-heading"><div><p class="eyebrow">PAWPLAY · DAILY</p><h1>每日计划与复盘</h1><p class="muted">按日期查看计划、执行、证据与下一步。</p></div></div><div id="daily-content"></div></section><footer class="main-footer">PawPlay 猫爪游乐场 <span>让每一笔投入有依据,让每一步进展可回看。</span></footer></main>
</div>
</div>
<p id="loading" class="loading" role="status">正在打开运营台…</p>
+8 -1
View File
@@ -154,13 +154,20 @@ export function createApp(options = process.env) {
}
if (route.startsWith('/api/')) {
if (!session(req)) return json(res, 401, { error: '请先登录' });
if (req.method === 'GET' && route === '/api/overview') {
const strategy = await jsonFile('ops-strategy.json', {}), market = await jsonFile('market-latest.json', {});
const short = (v, n = 300) => typeof v === 'string' ? v.slice(0, n) : '';
const video = v => ({ bvid: /^BV[0-9A-Za-z]+$/.test(v?.bvid || '') ? v.bvid : '', title: short(v?.title, 150), owner: short(v?.owner, 80), views: Number.isFinite(v?.views) ? v.views : null, likes: Number.isFinite(v?.likes) ? v.likes : null, comments: Number.isFinite(v?.comments) ? v.comments : null });
return json(res, 200, { strategy: { mission: short(strategy.mission), pillars: Array.isArray(strategy.pillars) ? strategy.pillars.slice(0, 6).map(v => short(v)) : [], cadence: short(strategy.cadence), phase: short(strategy.phase), budget_note: short(strategy.budget_note), budget: Array.isArray(strategy.budget) ? strategy.budget.slice(0, 8).map(v => ({ name: short(v?.name, 50), percent: Number.isFinite(v?.percent) ? v.percent : null })) : [] }, market: { observed_at: short(market.observed_at), ranking: Array.isArray(market.ranking) ? market.ranking.slice(0, 5).map(video) : [], account_videos: Array.isArray(market.account_videos) ? market.account_videos.slice(0, 20).map(video) : [] } });
}
if (req.method === 'GET' && route === '/api/workqueue') {
const value = await jsonFile('workqueue.json', { schema: 1, tasks: [] });
if (value?.schema !== 1 || !Array.isArray(value.tasks)) return json(res, 500, { error: '工作队列格式无效' });
const valid = new Set(['pending', 'running', 'done', 'blocked']);
const categories = new Set(['content', 'engineering', 'research', 'community', 'management']);
const tasks = value.tasks.filter(t => t && typeof t.id === 'string' && typeof t.title === 'string' && valid.has(t.status))
.map(t => ({ title: t.id.startsWith('interaction-') ? '核查新互动' : t.title.slice(0, 100), status: t.status,
attempts: Number.isInteger(t.attempts) ? t.attempts : 0, updated_at: typeof t.updated_at === 'string' ? t.updated_at : null }));
category: categories.has(t.category) ? t.category : 'management', attempts: Number.isInteger(t.attempts) ? t.attempts : 0, updated_at: typeof t.updated_at === 'string' ? t.updated_at : null }));
return json(res, 200, { tasks });
}
if (req.method === 'GET' && route === '/api/evolution') return json(res, 200, await jsonFile('evolution.json', { schema_version: 1, events: [] }));
+11
View File
@@ -174,3 +174,14 @@ test('daily symlinks cannot disclose files outside DATA_DIR', async t => {
assert.equal(response.status, 200); const text = await response.text(); assert.doesNotMatch(text, /OUTSIDE-SECRET/);
assert.deepEqual(JSON.parse(text), { records: [], invalid_count: 1 });
});
test('overview is authenticated and exposes only selected fields', async t => {
const { directory, request, login } = await fixture(t);
await writeFile(path.join(directory, 'ops-strategy.json'), JSON.stringify({ mission:'星栖', private:'SECRET' }));
await writeFile(path.join(directory, 'market-latest.json'), JSON.stringify({ observed_at:'2026-11-04', ranking:[{bvid:'https://evil.test',title:'榜单',views:1,private:'SECRET'}],account_videos:[] }));
assert.equal((await request('/api/overview')).status, 401);
const cookie = (await login()).headers.get('set-cookie').split(';')[0];
const response = await request('/api/overview', { headers:{cookie} }); const text = await response.text();
assert.doesNotMatch(text, /SECRET|evil/); const data = JSON.parse(text);
assert.equal(data.strategy.mission, '星栖'); assert.equal(data.market.ranking[0].bvid, '');
});