@chendb888/dsh-project-steward 0.1.0 → 0.1.3
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/CHANGELOG.md +14 -0
- package/README.md +5 -1
- package/client.js +161 -16
- package/docs/images/cover.png +0 -0
- package/docs/images/icon.png +0 -0
- package/icon.svg +13 -12
- package/index.js +5 -0
- package/package.json +2 -1
- package/src/channel-import.js +8 -2
- package/src/collector-sched.js +8 -2
- package/src/collectors/index.js +15 -6
- package/src/docs-tools.js +6 -0
- package/src/docs.js +96 -0
- package/src/listing.js +5 -0
- package/src/registry.js +2 -0
- package/src/routes.js +50 -1
- package/src/schemas.js +21 -0
- package/src/service.js +20 -9
- package/src/tools.js +2 -0
- package/src/website-tools.js +47 -0
- package/src/website.js +193 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
本文件记录 `@chendb888/dsh-project-steward`(项目管家)逐版本变更。
|
|
4
4
|
格式参考 [Keep a Changelog](https://keepachangelog.com/),版本遵循 [SemVer](https://semver.org/)。
|
|
5
5
|
|
|
6
|
+
## [0.1.3] - 2026-11-28
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- **运营采集漏采修复**:移除违反数值 schema 的字符串字段,npm 渠道自动采集恢复(此前漏采两天)。
|
|
10
|
+
- **顶部卡片与分项数据同源**:卡片直接由 perProject 汇总,杜绝"上面 0、下面有数"的对不上。
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **各商品运营列表 + 点击详情**:一行一个商品(按下载排序),点击滑出详情抽屉看总量 + 分渠道明细。
|
|
14
|
+
- **分项运营数据**:perProject.channels 每渠道最新快照(下载/昨日/浏览/克隆/留言/star/fork)。
|
|
15
|
+
- **页面防缓存拦截器**:tapIndex 注入 fetch no-store,破解浏览器一年 immutable 缓存致界面陈旧。
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- 下载口径=安装量(npm install / dsh plugin add 命令行均计);浏览=GitHub 真实页面浏览;克隆独立统计。
|
|
19
|
+
|
|
6
20
|
## [0.1.0] - 2026-11-23
|
|
7
21
|
|
|
8
22
|
### Added
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 项目管家 · Project Steward
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
> 像经营百货商店一样管理你全部**软件项目**的发布、上架与运营。一个 DSH 插件:分区货架看板 + 全自动发布 + 定时运营采集 + 市场竞品情报 + 全项目文档标准。
|
|
4
6
|
|
|
5
7
|
## 功能特性
|
|
@@ -28,6 +30,8 @@ dsh plugin --profile web add @chendb888/dsh-project-steward
|
|
|
28
30
|
4. 「📊 市场情报」扫描对比竞品 + 市场空白。
|
|
29
31
|
5. 对话中可用 `steward_*` 工具:`steward_release_start`(全自动发布)、`steward_doc_update_image`(生成版本更新图)、`steward_market_compare`(竞品研判)等。
|
|
30
32
|
|
|
33
|
+
「店铺概况」显示在售商品和渠道上架记录数。npm 下载显示近 30 天总量及最近报告日下载量,包含命令行安装。GitHub 浏览和克隆使用 14 天流量窗口。总数和明细显示精确数值,汇总字段缺失时使用商品上架记录和渠道明细计算。项目管家的中文界面保留原文,避免浏览器翻译改写实时数据。
|
|
34
|
+
|
|
31
35
|
## 版本更新说明
|
|
32
36
|
|
|
33
37
|
### 0.1.0(2026-11-23)
|
|
@@ -60,4 +64,4 @@ dsh plugin --profile web add @chendb888/dsh-project-steward
|
|
|
60
64
|
|
|
61
65
|
## 许可
|
|
62
66
|
|
|
63
|
-
MIT
|
|
67
|
+
MIT
|
package/client.js
CHANGED
|
@@ -27,6 +27,7 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
}
|
|
28
28
|
const STATUS_LABEL = { listed: '出售中', reviewing: '审核中', submitted: '审核中', draft: '待上架', rejected: '审核拒绝', delisted: '已下架' }
|
|
29
29
|
const fmt = n => n == null ? '0' : (n >= 10000 ? (n / 10000).toFixed(1) + 'w' : n >= 1000 ? (n / 1000).toFixed(1) + 'k' : String(n))
|
|
30
|
+
const count = n => n == null ? '—' : n.toLocaleString('zh-CN')
|
|
30
31
|
const money = n => '¥' + (n == null ? '0' : Number(n).toLocaleString())
|
|
31
32
|
const bg = 'var(--dsw-alias-bg-base)', layer = 'var(--dsw-alias-bg-layer-1)', layer2 = 'var(--dsw-alias-bg-layer-2)'
|
|
32
33
|
const border = 'var(--dsw-alias-border-l1)', text = 'var(--dsw-alias-label-primary)', sub = 'var(--dsw-alias-label-secondary)'
|
|
@@ -82,18 +83,30 @@ window.__ModuleLoader__.load({
|
|
|
82
83
|
input: { padding: '7px 10px', borderRadius: '8px', border: '1px solid ' + border, background: layer, color: text, fontSize: '12px', outline: 'none' },
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
async function api(path) {
|
|
86
|
+
async function api(path) {
|
|
87
|
+
for (let i = 0; i < 4; i++) {
|
|
88
|
+
try { const r = await fetch(path, { cache: 'no-store' }); if (r.ok) { const j = await r.json(); if (j && (j.ok !== false)) return j } } catch {}
|
|
89
|
+
await new Promise(res => setTimeout(res, 500 * (i + 1)))
|
|
90
|
+
}
|
|
91
|
+
return {}
|
|
92
|
+
}
|
|
86
93
|
async function post(path, body) { const r = await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) }); return r.json() }
|
|
87
94
|
|
|
88
95
|
function useData() {
|
|
89
|
-
const [data, setData] = useState({ projects:
|
|
96
|
+
const [data, setData] = useState({ projects: null, channels: [], summary: null, overview: null, gaps: [] })
|
|
90
97
|
const reload = useCallback(async () => {
|
|
91
98
|
try {
|
|
92
99
|
const [pj, sum, ov, gaps] = await Promise.all([api('/project-steward/api/projects'), api('/project-steward/api/summary'), api('/project-steward/api/overview'), api('/project-steward/api/market/gaps')])
|
|
93
|
-
setData(
|
|
100
|
+
setData(previous => ({
|
|
101
|
+
projects: Array.isArray(pj.projects) ? pj.projects : previous.projects,
|
|
102
|
+
channels: Array.isArray(pj.channels) ? pj.channels : previous.channels,
|
|
103
|
+
summary: Array.isArray(sum.perProject) ? sum : previous.summary,
|
|
104
|
+
overview: ov.counts || Array.isArray(ov.anomalies) ? ov : previous.overview,
|
|
105
|
+
gaps: Array.isArray(gaps.gaps) ? gaps.gaps : previous.gaps,
|
|
106
|
+
}))
|
|
94
107
|
} catch {}
|
|
95
108
|
}, [])
|
|
96
|
-
useEffect(() => { reload(); const id = setInterval(reload,
|
|
109
|
+
useEffect(() => { reload(); const id = setInterval(reload, 30000); const onFocus = () => reload(); window.addEventListener('focus', onFocus); return () => { clearInterval(id); window.removeEventListener('focus', onFocus) } }, [reload])
|
|
97
110
|
return { data, reload }
|
|
98
111
|
}
|
|
99
112
|
|
|
@@ -101,18 +114,100 @@ window.__ModuleLoader__.load({
|
|
|
101
114
|
const Thumb = ({ p, size }) => { const m = TYPE_META[p.type] || { icon: '📦', color: '#8c8c8c' }; const st = statusOf(p); return h('div', { style: { ...T.thumb, width: size || 104, height: size || 104, background: 'linear-gradient(135deg,' + m.color + ',' + m.color + 'cc)' } }, m.icon, h('span', { style: { ...T.statusDot, background: C[st] } })) }
|
|
102
115
|
|
|
103
116
|
// ---- 店铺概况 ----
|
|
117
|
+
// ---- 各商品运营情况(列表 + 点击打开详情)----
|
|
118
|
+
function BreakdownPanel({ summary }) {
|
|
119
|
+
const pp = summary?.perProject || []
|
|
120
|
+
const [sel, setSel] = useState(null)
|
|
121
|
+
const chLabel = { 'ch-npmjs': 'npm', 'ch-npmmirror': '镜像', 'ch-github': 'GitHub', 'ch-dsh-market': 'DSH市场', 'ch-itch-io': 'itch', 'ch-steam': 'Steam' }
|
|
122
|
+
const sorted = [...pp].sort((a, b) => (b.downloadsCumulative || 0) - (a.downloadsCumulative || 0))
|
|
123
|
+
const cell = (v, color) => h('td', { style: { ...T.td, color: color || text, fontWeight: 600 } }, count(v))
|
|
124
|
+
const detail = sel && h('div', { style: T.overlay, onClick: () => setSel(null) }, h('div', { style: T.drawer, onClick: e => e.stopPropagation() },
|
|
125
|
+
h('div', { style: { display: 'flex', alignItems: 'center', marginBottom: '14px' } }, h('div', { style: { fontWeight: 700, fontSize: '16px' } }, sel.name), h('span', { style: { ...T.btnGhost, marginLeft: 'auto' }, onClick: () => setSel(null) }, '✕')),
|
|
126
|
+
h('div', { style: { display: 'flex', gap: '22px', marginBottom: '16px' } },
|
|
127
|
+
[['下载', sel.downloadsCumulative, BRAND], ['浏览', sel.views, '#0ea5e9'], ['克隆', sel.clones, '#22a06b'], ['留言', sel.comments, '#f5a623']].map(([l, v, c]) => h('div', { key: l }, h('div', { style: { fontSize: '22px', fontWeight: 800, color: c } }, count(v)), h('div', { style: { fontSize: '11px', color: sub } }, l)))),
|
|
128
|
+
h('div', { style: T.panelTitle }, '分渠道明细'),
|
|
129
|
+
h('table', { style: T.table },
|
|
130
|
+
h('thead', null, h('tr', null, ['渠道', '下载', '昨日', '浏览', '克隆', '留言'].map(x => h('th', { key: x, style: T.th }, x)))),
|
|
131
|
+
h('tbody', null, (sel.channels || []).map((c, i) => h('tr', { key: i },
|
|
132
|
+
h('td', { style: T.td }, h('span', { style: { ...T.badge, background: '#333', color: '#ddd' } }, chLabel[c.channelId] || c.channelId)),
|
|
133
|
+
h('td', { style: { ...T.td, fontWeight: 700 } }, count(c.downloads)),
|
|
134
|
+
cell(c.downloadsYesterday, c.downloadsYesterday > 0 ? C.listed : sub),
|
|
135
|
+
cell(c.views), cell(c.clones), cell(c.comments)))))))
|
|
136
|
+
return h('div', { style: T.panel },
|
|
137
|
+
h('div', { style: T.panelTitle }, '📊 各商品运营情况', h('span', { style: { fontSize: '11px', color: sub, marginLeft: 'auto' } }, '点击商品行打开详情')),
|
|
138
|
+
sorted.length === 0 ? h('div', { style: { color: sub, fontSize: '12px' } }, '暂无采集数据。') :
|
|
139
|
+
h('table', { style: T.table },
|
|
140
|
+
h('thead', null, h('tr', null, ['商品', '下载', '浏览', '克隆', '留言', ''].map((x, i) => h('th', { key: i, style: T.th }, x)))),
|
|
141
|
+
h('tbody', null, sorted.map((p, i) => h('tr', { key: p.projectId, style: { cursor: 'pointer', ...(i === 0 ? { background: BRAND_SOFT } : {}) }, onClick: () => setSel(p) },
|
|
142
|
+
h('td', { style: { ...T.td, fontWeight: 700 } }, p.name, i === 0 ? ' 🏆' : ''),
|
|
143
|
+
h('td', { style: { ...T.td, fontWeight: 800, color: BRAND } }, count(p.downloadsCumulative)),
|
|
144
|
+
cell(p.views), cell(p.clones), cell(p.comments),
|
|
145
|
+
h('td', { style: T.td }, h('span', { style: { color: BRAND, fontSize: '12px' } }, '详情 →')))))),
|
|
146
|
+
detail)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function dashboardMetric(summary, field, channelField = field) {
|
|
150
|
+
const reported = summary?.totals?.[field]
|
|
151
|
+
if (Number.isFinite(reported)) return reported
|
|
152
|
+
if (!Array.isArray(summary?.perProject)) return
|
|
153
|
+
|
|
154
|
+
let total = 0
|
|
155
|
+
for (const project of summary.perProject) {
|
|
156
|
+
const subtotal = project[field]
|
|
157
|
+
if (Number.isFinite(subtotal)) {
|
|
158
|
+
total += subtotal
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
if (!Array.isArray(project.channels)) return
|
|
162
|
+
for (const channel of project.channels) {
|
|
163
|
+
const value = channel[channelField]
|
|
164
|
+
if (!Number.isFinite(value)) return
|
|
165
|
+
total += value
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return total
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function dashboardListingCounts(projects) {
|
|
172
|
+
if (!projects) return {}
|
|
173
|
+
let listed = 0, listedListings = 0
|
|
174
|
+
for (const project of projects) {
|
|
175
|
+
const listings = project.listings ?? project.channels
|
|
176
|
+
if (!Array.isArray(listings) || listings.some(l => typeof l.status !== 'string')) return {}
|
|
177
|
+
const active = listings.filter(l => l.status === 'listed').length
|
|
178
|
+
if (active > 0) listed++
|
|
179
|
+
listedListings += active
|
|
180
|
+
}
|
|
181
|
+
return { listed, listedListings }
|
|
182
|
+
}
|
|
183
|
+
|
|
104
184
|
function Dashboard({ data, goShelf }) {
|
|
105
|
-
const
|
|
185
|
+
const metric = (field, channelField) => dashboardMetric(data.summary, field, channelField)
|
|
186
|
+
const ov = data.overview || {}
|
|
187
|
+
const fallback = dashboardListingCounts(data.projects)
|
|
188
|
+
const listed = ov.counts?.listed ?? fallback.listed
|
|
189
|
+
const listedListings = ov.counts?.listedListings ?? fallback.listedListings
|
|
190
|
+
const change = n => n == null ? '—' : '+' + count(n)
|
|
191
|
+
const revenue = metric('revenue')
|
|
106
192
|
const stats = [
|
|
107
|
-
{ label: '在售商品', value:
|
|
108
|
-
{ label: '
|
|
109
|
-
{ label: '
|
|
110
|
-
{ label: '
|
|
111
|
-
{ label: '累计收入', value: money(
|
|
193
|
+
{ label: '在售商品', value: count(listed), note: count(listedListings) + ' 条渠道上架记录', icon: '🏪', color: BRAND },
|
|
194
|
+
{ label: '下载', period: '近 30 天', value: count(metric('downloadsCumulative', 'downloads') ?? data.summary?.totals?.downloads), delta: metric('downloadsYesterday') ?? null, deltaLabel: '最近报告日', note: 'npm 下载量(含命令行安装)', icon: '⬇️', color: '#5b6cff' },
|
|
195
|
+
{ label: '浏览', period: '近 14 天', value: count(metric('views')), delta: metric('viewsYesterday') ?? null, deltaLabel: '昨日增加', icon: '👁️', color: '#0ea5e9' },
|
|
196
|
+
{ label: '留言', value: count(metric('comments')), note: '克隆 ' + count(metric('clones')) + ' · 昨日 ' + change(metric('clonesYesterday')), icon: '💬', color: '#22a06b' },
|
|
197
|
+
{ label: '累计收入', value: revenue == null ? '—' : money(revenue), icon: '💰', color: '#f5a623' },
|
|
112
198
|
]
|
|
113
199
|
const anomalies = ov.anomalies || []
|
|
114
200
|
return h('div', null,
|
|
115
|
-
h('div', { style: T.cards }, stats.map(s => h('div', { key: s.label, style: T.stat },
|
|
201
|
+
h('div', { style: T.cards }, stats.map(s => h('div', { key: s.label, style: T.stat },
|
|
202
|
+
h('span', { style: T.statIcon }, s.icon),
|
|
203
|
+
h('div', { style: T.statLabel }, s.label),
|
|
204
|
+
s.delta !== undefined
|
|
205
|
+
? h('div', { style: { display: 'flex', gap: '14px', marginTop: '4px' } },
|
|
206
|
+
h('div', null, h('div', { style: { ...T.statNum, color: s.color } }, s.value), h('div', { style: { fontSize: '10px', color: sub } }, s.period)),
|
|
207
|
+
h('div', { style: { borderLeft: '1px solid ' + border, paddingLeft: '14px' } }, h('div', { style: { ...T.statNum, color: s.delta > 0 ? C.listed : sub } }, change(s.delta)), h('div', { style: { fontSize: '10px', color: sub } }, s.deltaLabel)))
|
|
208
|
+
: h('div', { style: { ...T.statNum, color: s.color } }, s.value),
|
|
209
|
+
s.note ? h('div', { style: { fontSize: '10px', color: sub, marginTop: '3px' } }, s.note) : null))),
|
|
210
|
+
h(BreakdownPanel, { summary: data.summary }),
|
|
116
211
|
h('div', { style: T.panel }, h('div', { style: T.panelTitle }, '⚠️ 待处理异常', anomalies.length ? h('span', { style: { ...T.badge, background: 'rgba(229,72,77,.12)', color: C.rejected } }, anomalies.length) : null),
|
|
117
212
|
anomalies.length === 0 ? h('div', { style: { color: sub, fontSize: '12px' } }, '一切正常,暂无异常 🎉') :
|
|
118
213
|
anomalies.map((a, i) => h('div', { key: i, style: { display: 'flex', gap: '8px', padding: '6px 0', borderBottom: '1px solid ' + border, fontSize: '12px' } }, h('span', { style: { color: C.rejected } }, '●'), h('span', null, { 'blocked-run': '发布阻断', 'rejected-listing': '上架被拒', 'expired-reminder': '提醒过期' }[a.kind] || a.kind), h('span', { style: { color: sub, marginLeft: 'auto' } }, a.projectId)))),
|
|
@@ -167,7 +262,7 @@ window.__ModuleLoader__.load({
|
|
|
167
262
|
const [mode, setMode] = useState('shelf')
|
|
168
263
|
const [q, setQ] = useState('')
|
|
169
264
|
const [cat, setCat] = useState('all')
|
|
170
|
-
const all = data.projects
|
|
265
|
+
const all = data.projects || []
|
|
171
266
|
const counts = { all: all.length, listed: 0, reviewing: 0, draft: 0, delisted: 0, rejected: 0 }
|
|
172
267
|
for (const p of all) counts[statusOf(p)] = (counts[statusOf(p)] || 0) + 1
|
|
173
268
|
let ps = all
|
|
@@ -364,6 +459,54 @@ window.__ModuleLoader__.load({
|
|
|
364
459
|
h('div', { style: { display: 'flex', gap: '8px', marginTop: '16px', justifyContent: 'flex-end' } }, h('span', { style: T.btnGhost, onClick: onClose }, '关闭'), candidates && candidates.some(c => selected[c.url]) ? h('span', { style: T.btn, onClick: doImport }, busy ? '导入中…' : '导入选中') : null)))
|
|
365
460
|
}
|
|
366
461
|
|
|
462
|
+
// ---- 个人网站维护页(FR8,域名可配置)----
|
|
463
|
+
function WebsitePage() {
|
|
464
|
+
const [tab, setTab] = useState('showcase')
|
|
465
|
+
const [sites, setSites] = useState([])
|
|
466
|
+
const [show, setShow] = useState(null)
|
|
467
|
+
const [busy, setBusy] = useState(false)
|
|
468
|
+
const [url, setUrl] = useState('')
|
|
469
|
+
const [msg, setMsg] = useState('')
|
|
470
|
+
const load = () => api('/project-steward/api/website/list').then(j => setSites(j.websites || [])).catch(() => {})
|
|
471
|
+
const loadShow = () => api('/project-steward/api/website/showcase').then(j => setShow(j.showcase)).catch(() => {})
|
|
472
|
+
const sync = async () => { const w = sites[0]; if (!w) { setMsg('请先在维护监控页登记网站'); return } setBusy(true); setMsg(''); try { const j = await post('/project-steward/api/website/sync', { websiteId: w.id }); setMsg(j.ok ? (j.result.synced ? '已同步到网站:' + (j.result.log || []).join(' ') : '已生成(未配置自动部署)') : (j.error?.message || '同步失败')) } catch (e) { setMsg(String(e)) } finally { setBusy(false) } }
|
|
473
|
+
useEffect(() => { load(); loadShow() }, [])
|
|
474
|
+
const check = async () => { setBusy(true); setMsg(''); try { await post('/project-steward/api/website/check', {}); await load(); setMsg('检查完成') } catch (e) { setMsg(String(e)) } finally { setBusy(false) } }
|
|
475
|
+
const add = async () => { if (!url.trim()) return; setBusy(true); try { const j = await post('/project-steward/api/website/add', { url: url.trim() }); if (j.ok) { setUrl(''); await load() } else setMsg(j.error?.message || '添加失败') } finally { setBusy(false) } }
|
|
476
|
+
const certColor = d => d == null ? sub : d < 0 ? C.rejected : d <= 30 ? C.reviewing : C.listed
|
|
477
|
+
const tabBar = h('div', { style: { display: 'flex', gap: '8px', marginBottom: '14px' } },
|
|
478
|
+
[['showcase', '🎨 作品展示·宣传'], ['maint', '🛡️ 维护监控']].map(([k, label]) => h('span', { key: k, style: { ...T.btnGhost, ...(tab === k ? { background: BRAND_SOFT, color: BRAND, borderColor: BRAND, fontWeight: 700 } : {}) }, onClick: () => setTab(k) }, label)))
|
|
479
|
+
const showcasePanel = h('div', { style: T.panel },
|
|
480
|
+
h('div', { style: T.panelTitle }, '🎨 作品展示专栏(宣传)', h('span', { style: { ...T.btn, marginLeft: 'auto' }, onClick: sync }, busy ? '同步中…' : '⬆ 同步到网站'), h('span', { style: T.btnGhost, onClick: loadShow }, '⟳ 刷新')),
|
|
481
|
+
h('div', { style: { fontSize: '11px', color: sub, marginBottom: '12px' } }, '个人网站第一专栏「作品展示」——自动从货架已上架公开商品生成,展示封面/简介/版本/下载/渠道。可同步到个人网站。'),
|
|
482
|
+
!show || !show.items.length ? h('div', { style: T.empty }, '暂无已上架公开商品。先在货架上架商品。') :
|
|
483
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(260px,1fr))', gap: '14px' } }, show.items.map(it => h('div', { key: it.id, style: { border: '1px solid ' + border, borderRadius: '10px', overflow: 'hidden', background: '#2a2a2a' } },
|
|
484
|
+
(it.icon || it.cover) ? h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '14px', background: '#222', borderBottom: '1px solid ' + border } }, h('img', { src: it.icon || it.cover, alt: it.name, style: { height: '88px', width: '88px', objectFit: 'contain', borderRadius: '12px' } })) : null,
|
|
485
|
+
h('div', { style: { padding: '12px' } },
|
|
486
|
+
h('div', { style: { fontWeight: 700, fontSize: '14px', color: '#fff' } }, it.name, it.version ? h('span', { style: { fontSize: '11px', color: sub, fontWeight: 400 } }, ' v' + it.version) : null),
|
|
487
|
+
h('div', { style: { fontSize: '12px', color: sub, margin: '6px 0', minHeight: '32px' } }, (it.description || '').slice(0, 60)),
|
|
488
|
+
h('div', { style: { display: 'flex', gap: '12px', fontSize: '12px', color: sub } }, h('span', null, '⬇ ' + (it.metrics?.downloads ?? it.downloads ?? 0)), h('span', null, '👁 ' + (it.metrics?.views ?? 0)), h('span', null, '💬 ' + (it.metrics?.comments ?? 0)), h('span', null, it.channels.length + ' 渠道')),
|
|
489
|
+
it.url ? h('a', { href: it.url, target: '_blank', rel: 'noreferrer', style: { color: BRAND, fontSize: '12px' } }, '查看项目 →') : null)))))
|
|
490
|
+
const maintPanel = h('div', { style: T.panel },
|
|
491
|
+
h('div', { style: T.panelTitle }, '🛡️ 网站维护监控', h('span', { style: { ...T.btn, marginLeft: 'auto' }, onClick: check }, busy ? '检查中…' : '检查证书/可用性')),
|
|
492
|
+
h('div', { style: { fontSize: '11px', color: sub, marginBottom: '10px' } }, '监控 SSL 证书到期 + 网站可用性;到期前自动生成续期提醒。域名可配置——他人使用可替换为自己的网站。'),
|
|
493
|
+
msg ? h('div', { style: { fontSize: '12px', color: sub, marginBottom: '8px' } }, msg) : null,
|
|
494
|
+
sites.length === 0 ? h('div', { style: T.empty }, '尚未登记网站。下方输入你的网站 URL 添加。') :
|
|
495
|
+
h('table', { style: T.table }, h('thead', null, h('tr', null, ['网站', '域名', 'SSL 证书', '剩余天数', 'HTTP', '响应', '状态'].map(x => h('th', { key: x, style: T.th }, x)))),
|
|
496
|
+
h('tbody', null, sites.map(w => { const l = w.latest || {}; return h('tr', { key: w.id },
|
|
497
|
+
h('td', { style: { ...T.td, fontWeight: 600 } }, w.name),
|
|
498
|
+
h('td', { style: T.td }, h('a', { href: w.url, target: '_blank', rel: 'noreferrer', style: { color: BRAND } }, w.domain)),
|
|
499
|
+
h('td', { style: T.td }, (l.certValidTo || '').slice(0, 10) || '—'),
|
|
500
|
+
h('td', { style: { ...T.td, fontWeight: 800, color: certColor(l.certDaysLeft) } }, l.certDaysLeft ?? '—'),
|
|
501
|
+
h('td', { style: T.td }, l.httpStatus || '—'),
|
|
502
|
+
h('td', { style: T.td }, l.responseMs != null ? l.responseMs + 'ms' : '—'),
|
|
503
|
+
h('td', { style: T.td }, l.ok ? h('span', { style: { color: C.listed } }, '✓ 正常') : h('span', { style: { color: C.rejected } }, (l.issues || []).join(',')))) }))),
|
|
504
|
+
h('div', { style: { display: 'flex', gap: '8px', marginTop: '12px' } },
|
|
505
|
+
h('input', { style: { ...T.search, flex: 1 }, placeholder: '添加网站 URL(如 https://example.com)', value: url, onChange: e => setUrl(e.target.value) }),
|
|
506
|
+
h('span', { style: T.btnGhost, onClick: add }, '+ 添加网站')))
|
|
507
|
+
return h('div', null, tabBar, tab === 'showcase' ? showcasePanel : maintPanel)
|
|
508
|
+
}
|
|
509
|
+
|
|
367
510
|
// ---- 主页面 ----
|
|
368
511
|
function ShelfPage() {
|
|
369
512
|
const { data, reload } = useData()
|
|
@@ -371,9 +514,10 @@ window.__ModuleLoader__.load({
|
|
|
371
514
|
const [open, setOpen] = useState(null)
|
|
372
515
|
const [scanOpen, setScanOpen] = useState(false)
|
|
373
516
|
const [chImportOpen, setChImportOpen] = useState(false)
|
|
374
|
-
const NAV = [['dashboard', '🏬', '店铺概况'], ['products', '🛒', '商品货架'], ['market', '📊', '市场情报'], ['channels', '🔌', '发布渠道'], ['settings', '⚙️', '设置']]
|
|
375
|
-
const titles = { dashboard: '店铺概况', products: '商品货架', market: '市场情报', channels: '发布渠道', settings: '设置' }
|
|
376
|
-
|
|
517
|
+
const NAV = [['dashboard', '🏬', '店铺概况'], ['products', '🛒', '商品货架'], ['market', '📊', '市场情报'], ['website', '🌐', '个人网站'], ['channels', '🔌', '发布渠道'], ['settings', '⚙️', '设置']]
|
|
518
|
+
const titles = { dashboard: '店铺概况', products: '商品货架', market: '市场情报', website: '个人网站', channels: '发布渠道', settings: '设置' }
|
|
519
|
+
// The store already renders Chinese copy. Browser translation can replace React's text nodes before metrics arrive.
|
|
520
|
+
return h('div', { style: T.app, lang: 'zh-CN', translate: 'no', className: 'notranslate' },
|
|
377
521
|
h('div', { style: T.side },
|
|
378
522
|
h('div', { style: T.shop }, h('div', { style: T.shopAvatar }, '🏪'), h('div', null, h('div', { style: { fontWeight: 700, fontSize: '14px' } }, '我的店铺'), h('div', { style: { fontSize: '11px', color: sub } }, '项目管家'))),
|
|
379
523
|
NAV.map(([k, icon, label]) => h('div', { key: k, style: { ...T.navItem, ...(page === k ? { background: BRAND_SOFT, color: BRAND, fontWeight: 700 } : {}) }, onClick: () => setPage(k) }, h('span', null, icon), label)),
|
|
@@ -384,6 +528,7 @@ window.__ModuleLoader__.load({
|
|
|
384
528
|
page === 'dashboard' ? h(Dashboard, { data, goShelf: () => setPage('products') }) :
|
|
385
529
|
page === 'products' ? h(ProductsPage, { data, onOpen: setOpen, onScan: () => setScanOpen(true) }) :
|
|
386
530
|
page === 'market' ? h(MarketPage, { data, reload }) :
|
|
531
|
+
page === 'website' ? h(WebsitePage) :
|
|
387
532
|
page === 'settings' ? h(SettingsPage, { data }) : h(ChannelsPage, { data }))),
|
|
388
533
|
open ? h(DetailDrawer, { p: open, onClose: () => setOpen(null) }) : null,
|
|
389
534
|
scanOpen ? h(ScanDialog, { onClose: () => setScanOpen(false), onDone: reload }) : null,
|
|
@@ -414,4 +559,4 @@ window.__ModuleLoader__.load({
|
|
|
414
559
|
},
|
|
415
560
|
}
|
|
416
561
|
},
|
|
417
|
-
})
|
|
562
|
+
})
|
|
Binary file
|
|
Binary file
|
package/icon.svg
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" font-family="Segoe UI, sans-serif">
|
|
2
|
+
<defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#ff6a00"/><stop offset="1" stop-color="#ffa028"/></linearGradient></defs>
|
|
3
|
+
<rect width="256" height="256" rx="56" fill="url(#g)"/>
|
|
4
|
+
<circle cx="200" cy="56" r="60" fill="#ffffff" opacity="0.08"/>
|
|
5
|
+
<g>
|
|
6
|
+
<rect x="60.8" y="100" width="134.4" height="83.2" rx="8" fill="#ffffff" opacity="0.92"/>
|
|
7
|
+
<path d="M 54.4 100 L 67.2 68 L 188.8 68 L 201.6 100 Z" fill="#ffffff"/>
|
|
8
|
+
<path d="M 54.4 100 q 12.32 19.2 24.64 0 q 12.32 19.2 24.64 0 q 12.32 19.2 24.64 0 q 12.32 19.2 24.64 0 q 12.32 19.2 24.64 0 q 12.32 19.2 24.64 0" fill="#ffd166"/>
|
|
9
|
+
<rect x="73.6" y="122.4" width="32" height="25.6" rx="3.2" fill="#ffd166"/>
|
|
10
|
+
<rect x="112" y="122.4" width="32" height="25.6" rx="3.2" fill="#cbd5e1"/>
|
|
11
|
+
<rect x="150.4" y="122.4" width="32" height="48" rx="3.2" fill="#94a3b8"/>
|
|
12
|
+
<rect x="73.6" y="154.4" width="70.4" height="16" rx="3.2" fill="#e2e8f0"/>
|
|
13
|
+
</g>
|
|
13
14
|
</svg>
|
package/index.js
CHANGED
|
@@ -16,6 +16,11 @@ export function apply(ctx, config = {}) {
|
|
|
16
16
|
disposers.push(registerStewardTools(ctx, service))
|
|
17
17
|
registerRoutes(ctx, service)
|
|
18
18
|
|
|
19
|
+
// R50:注入 fetch 拦截器,强制插件 bundle 走 no-store,破解浏览器一年 immutable 缓存致界面陈旧
|
|
20
|
+
try {
|
|
21
|
+
disposers.push(ctx.webServer.tapIndex(html => html.replace('<head>', '<head><script>(function(){var of=window.fetch;window.fetch=function(u,o){try{if(typeof u==="string"&&u.indexOf("/plugins/")>=0){o=Object.assign({},o,{cache:"no-store"});}}catch(e){}return of.call(this,u,o);};})();</script>')))
|
|
22
|
+
} catch {}
|
|
23
|
+
|
|
19
24
|
// 定时运营采集(R9/R13:默认 60min)
|
|
20
25
|
service.collector.start(config.collectIntervalMinutes ?? 60)
|
|
21
26
|
disposers.push(() => service.collector.stop())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chendb888/dsh-project-steward",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "项目管家:软件项目发布/上架/运营统一管家——百货分区货架、常驻迷你条、全自动发布、定时采集、市场情报",
|
|
6
6
|
"meta": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"test": "node --test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"edge-tts": "^1.0.1",
|
|
32
33
|
"zod": "^3.25.76"
|
|
33
34
|
},
|
|
34
35
|
"dsh": {
|
package/src/channel-import.js
CHANGED
|
@@ -70,8 +70,14 @@ export class ChannelImport {
|
|
|
70
70
|
|
|
71
71
|
// 导入一个渠道商品为纳管项目 + 上架记录
|
|
72
72
|
async importProduct(candidate, actor = 'user') {
|
|
73
|
-
const rootPath = candidate.localRoot || candidate.url // 无本地源时用 remote URL
|
|
74
|
-
|
|
73
|
+
const rootPath = candidate.localRoot || candidate.url // 无本地源时用 remote URL(远程-only)
|
|
74
|
+
const candRepo = (candidate.url.match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/)?.[1] || '').toLowerCase()
|
|
75
|
+
const candShort = candidate.name.split('/').pop().toLowerCase()
|
|
76
|
+
let project = this.service.listProjects().find(p => {
|
|
77
|
+
const pRepo = ((p.remote || '').match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/)?.[1] || '').toLowerCase()
|
|
78
|
+
const pShort = (p.name || '').split('/').pop().toLowerCase()
|
|
79
|
+
return p.remote === candidate.url || p.name === candidate.name || (candRepo && pRepo === candRepo) || (pRepo && pRepo.split('/')[1] === candShort) || (pShort && pShort === candShort)
|
|
80
|
+
})
|
|
75
81
|
if (!project) {
|
|
76
82
|
const type = candidate.source === 'npm' ? 'dsh-plugin' : 'research'
|
|
77
83
|
project = await this.service.registerProject({ name: candidate.name, rootPath, type, remote: candidate.url, notes: candidate.description, tags: [candidate.source] }, actor)
|
package/src/collector-sched.js
CHANGED
|
@@ -54,7 +54,13 @@ export class Collector {
|
|
|
54
54
|
const items = listings.map(l => {
|
|
55
55
|
const proj = this.service.getProject(l.projectId) || {}
|
|
56
56
|
const meta = deriveMeta(proj)
|
|
57
|
-
|
|
57
|
+
// 发布日(含次日镜像滞后):用于剔除自动化下载脉冲,估算真实下载
|
|
58
|
+
const publishDays = new Set()
|
|
59
|
+
for (const r of this.store.list('releases').filter(r => r.projectId === l.projectId)) {
|
|
60
|
+
const d = (r.releasedAt || '').slice(0, 10)
|
|
61
|
+
if (d) { publishDays.add(d); const nx = new Date(d + 'T00:00:00Z'); nx.setUTCDate(nx.getUTCDate() + 1); publishDays.add(nx.toISOString().slice(0, 10)) }
|
|
62
|
+
}
|
|
63
|
+
return { id: l.id, name: l.platformUrl || l.id, pkgName: l.pkgName || meta.pkgName, repo: l.repo || meta.repo, healthUrl: l.healthUrl || meta.healthUrl, publishDays: [...publishDays] }
|
|
58
64
|
})
|
|
59
65
|
let result, lastErr
|
|
60
66
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
@@ -76,7 +82,7 @@ export class Collector {
|
|
|
76
82
|
for (const l of listings) {
|
|
77
83
|
const m = result.metrics?.[l.id]
|
|
78
84
|
if (m && Object.keys(m).length) {
|
|
79
|
-
await this.service.ops.addMetric({ projectId: l.projectId, channelId: channel.id, date: today, metrics: m }, 'collector', 'collector')
|
|
85
|
+
await this.service.ops.addMetric({ projectId: l.projectId, channelId: channel.id, date: today, metrics: m, overwrite: true }, 'collector', 'collector')
|
|
80
86
|
run.metricsWritten++
|
|
81
87
|
}
|
|
82
88
|
}
|
package/src/collectors/index.js
CHANGED
|
@@ -15,14 +15,22 @@ export const adapters = {
|
|
|
15
15
|
async fetch(listings, credRef, io = {}) {
|
|
16
16
|
const f = io.fetch || defaultFetch
|
|
17
17
|
const metrics = {}
|
|
18
|
+
const fmt = d => d.toISOString().slice(0, 10)
|
|
19
|
+
const end = new Date(); end.setUTCDate(end.getUTCDate() - 1)
|
|
20
|
+
const start = new Date(end); start.setUTCDate(start.getUTCDate() - 29)
|
|
18
21
|
for (const l of listings) {
|
|
19
22
|
const pkg = l.pkgName || l.name
|
|
20
23
|
if (!pkg) continue
|
|
21
24
|
try {
|
|
22
|
-
|
|
25
|
+
// 下载量=安装量(npm install / dsh plugin add 命令行安装都算,R46);逐日取昨日新增
|
|
26
|
+
const r = await f(`https://api.npmjs.org/downloads/range/${fmt(start)}:${fmt(end)}/${encodeURIComponent(pkg)}`)
|
|
23
27
|
const j = await r.json()
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
const days = j.downloads || []
|
|
29
|
+
const raw = days.reduce((a, d) => a + (d.downloads || 0), 0)
|
|
30
|
+
const last = days[days.length - 1] // npm 最新报告日
|
|
31
|
+
const downloadsYesterday = last?.downloads || 0
|
|
32
|
+
metrics[l.id] = { downloads: raw, downloadsRaw: raw, downloadsYesterday }
|
|
33
|
+
} catch { metrics[l.id] = { downloads: 0, downloadsRaw: 0, downloadsYesterday: 0 } }
|
|
26
34
|
}
|
|
27
35
|
return { metrics, comments: [], payments: [] }
|
|
28
36
|
},
|
|
@@ -43,10 +51,11 @@ export const adapters = {
|
|
|
43
51
|
const j = await r.json()
|
|
44
52
|
m.stars = j.stargazers_count || 0; m.forks = j.forks_count || 0; m.watchers = j.subscribers_count || 0; m.issues = j.open_issues_count || 0
|
|
45
53
|
} catch {}
|
|
46
|
-
// 浏览量(页面访问,与下载分开)+ 克隆量,需鉴权 traffic API
|
|
54
|
+
// 浏览量(页面访问,与下载分开)+ 克隆量,需鉴权 traffic API;含昨日增量
|
|
47
55
|
if (token) {
|
|
48
|
-
|
|
49
|
-
try { const
|
|
56
|
+
const yday = new Date(Date.now() - 86400000).toISOString().slice(0, 10)
|
|
57
|
+
try { const v = await (await f(`https://api.github.com/repos/${repo}/traffic/views`, { headers: auth })).json(); m.views = v.count || 0; m.viewUniques = v.uniques || 0; m.viewsYesterday = (v.views || []).find(d => (d.timestamp || '').slice(0, 10) === yday)?.count || 0 } catch {}
|
|
58
|
+
try { const c = await (await f(`https://api.github.com/repos/${repo}/traffic/clones`, { headers: auth })).json(); m.clones = c.count || 0; m.cloneUniques = c.uniques || 0; m.clonesYesterday = (c.clones || []).find(d => (d.timestamp || '').slice(0, 10) === yday)?.count || 0 } catch {}
|
|
50
59
|
}
|
|
51
60
|
metrics[l.id] = m
|
|
52
61
|
}
|
package/src/docs-tools.js
CHANGED
|
@@ -40,5 +40,11 @@ export function buildDocsTools(service) {
|
|
|
40
40
|
parameters: { type: 'object', properties: { projectId: { type: 'string' }, version: { type: 'string' } }, required: ['projectId', 'version'], additionalProperties: false },
|
|
41
41
|
execute: async args => guard(z.object({ projectId: z.string(), version: z.string() }), args, d => need(service).generateUpdateImage(d.projectId, d.version)),
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
name: 'steward_doc_cover',
|
|
45
|
+
description: '为项目设计应用封面+图标(按类型/品牌色生成 icon 256 与 cover 1200x630,SVG→PNG,本地项目更新 icon.svg)。FR7.8。',
|
|
46
|
+
parameters: { type: 'object', properties: { projectId: { type: 'string' } }, required: ['projectId'], additionalProperties: false },
|
|
47
|
+
execute: async args => guard(idSchema, args, d => need(service).generateCover(d.projectId)),
|
|
48
|
+
},
|
|
43
49
|
]
|
|
44
50
|
}
|
package/src/docs.js
CHANGED
|
@@ -249,6 +249,102 @@ ${bulletSvg}
|
|
|
249
249
|
<text x="40" y="465" fill="#ff5000" font-size="14" font-weight="bold">v${esc(version)} 更新位置图例</text>
|
|
250
250
|
${legend}
|
|
251
251
|
<text x="40" y="528" fill="#888" font-size="11">红虚线框 = 本次更新位置 · 示意图(实际界面以运行时为准)</text>
|
|
252
|
+
</svg>`
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// FR7.8 应用封面/图标设计生成(icon 256 + cover 1200x630,SVG→PNG)
|
|
256
|
+
generateCover(projectId, opts = {}) {
|
|
257
|
+
const p = this.service.getProject(projectId)
|
|
258
|
+
if (!p) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
259
|
+
const root = p.rootPath
|
|
260
|
+
const theme = this._coverTheme(p)
|
|
261
|
+
const iconSvg = this._iconSvg(theme)
|
|
262
|
+
const coverSvg = this._coverSvg(p, theme)
|
|
263
|
+
const imgDir = /^https?:/i.test(root) ? join(this.store.dataDir || 'data', 'covers', p.id) : join(root, 'docs', 'images')
|
|
264
|
+
mkdirSync(imgDir, { recursive: true })
|
|
265
|
+
const out = {}
|
|
266
|
+
const chrome = opts.chrome || 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
|
|
267
|
+
for (const [kind, svg, w, h] of [['icon', iconSvg, 256, 256], ['cover', coverSvg, 1200, 630]]) {
|
|
268
|
+
const svgPath = join(imgDir, `${kind}.svg`)
|
|
269
|
+
const pngPath = join(imgDir, `${kind}.png`)
|
|
270
|
+
const sized = svg.replace('<svg ', `<svg width="${w}" height="${h}" `)
|
|
271
|
+
writeFileSync(svgPath, sized, 'utf8')
|
|
272
|
+
const htmlPath = join(imgDir, `_${kind}.html`)
|
|
273
|
+
writeFileSync(htmlPath, `<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0;padding:0;background:transparent}svg{display:block}</style></head><body>${sized}</body></html>`, 'utf8')
|
|
274
|
+
spawnSync(chrome, ['--headless', '--disable-gpu', '--no-sandbox', '--force-device-scale-factor=1', '--default-background-color=00000000', `--screenshot=${pngPath}`, `--window-size=${w},${h}`, `file:///${htmlPath.replace(/\\/g, '/')}`], { encoding: 'utf8', timeout: 30000 })
|
|
275
|
+
out[kind] = { svg: svgPath, png: pngPath, ok: existsSync(pngPath) }
|
|
276
|
+
}
|
|
277
|
+
// 本地项目:更新 icon.svg 为新生成图标
|
|
278
|
+
if (!/^https?:/i.test(root) && out.icon.ok) { try { writeFileSync(join(root, 'icon.svg'), iconSvg, 'utf8') } catch {} }
|
|
279
|
+
return { projectId, name: p.name, theme: theme.key, ...out }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
_coverTheme(p) {
|
|
283
|
+
const n = (p.name || '').toLowerCase()
|
|
284
|
+
if (/看板|board|可视化|whitebox/.test(n)) return { key: 'board', c1: '#6366f1', c2: '#8b5cf6', accent: '#22c55e', glyph: 'board' }
|
|
285
|
+
if (/管家|steward|store|shop/.test(n)) return { key: 'steward', c1: '#ff6a00', c2: '#ffa028', accent: '#ffd166', glyph: 'store' }
|
|
286
|
+
if (p.type === 'game') return { key: 'game', c1: '#16a34a', c2: '#4ade80', accent: '#facc15', glyph: 'game' }
|
|
287
|
+
if (p.type === 'web-app') return { key: 'web', c1: '#0ea5e9', c2: '#38bdf8', accent: '#a5f3fc', glyph: 'web' }
|
|
288
|
+
return { key: 'default', c1: '#6366f1', c2: '#8b5cf6', accent: '#22c55e', glyph: 'board' }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
_motif(glyph, x, y, s, accent) {
|
|
292
|
+
// s = 尺寸基准;返回以 (x,y) 为左上、边长 s 的白色图案
|
|
293
|
+
if (glyph === 'board') {
|
|
294
|
+
const cw = s * 0.26, gap = s * 0.05, card = (cx, cy, h, fill) => `<rect x="${cx}" y="${cy}" width="${cw}" height="${h}" rx="${s * 0.03}" fill="${fill}"/>`
|
|
295
|
+
return `<g>
|
|
296
|
+
<rect x="${x}" y="${y}" width="${s}" height="${s * 0.82}" rx="${s * 0.06}" fill="#ffffff" opacity="0.16"/>
|
|
297
|
+
${card(x + gap, y + gap, s * 0.3, '#ffffff')}
|
|
298
|
+
${card(x + gap, y + gap + s * 0.34, s * 0.2, '#ffffff')}
|
|
299
|
+
${card(x + gap * 2 + cw, y + gap, s * 0.42, '#ffffff')}
|
|
300
|
+
${card(x + gap * 2 + cw, y + gap + s * 0.46, s * 0.16, accent)}
|
|
301
|
+
${card(x + gap * 3 + cw * 2, y + gap, s * 0.24, '#ffffff')}
|
|
302
|
+
${card(x + gap * 3 + cw * 2, y + gap + s * 0.28, s * 0.3, '#ffffff')}
|
|
303
|
+
<circle cx="${x + s * 0.86}" cy="${y + s * 0.14}" r="${s * 0.13}" fill="none" stroke="${accent}" stroke-width="${s * 0.05}"/>
|
|
304
|
+
</g>`
|
|
305
|
+
}
|
|
306
|
+
if (glyph === 'store') {
|
|
307
|
+
return `<g>
|
|
308
|
+
<rect x="${x + s * 0.08}" y="${y + s * 0.3}" width="${s * 0.84}" height="${s * 0.52}" rx="${s * 0.05}" fill="#ffffff" opacity="0.92"/>
|
|
309
|
+
<path d="M ${x + s * 0.04} ${y + s * 0.3} L ${x + s * 0.12} ${y + s * 0.1} L ${x + s * 0.88} ${y + s * 0.1} L ${x + s * 0.96} ${y + s * 0.3} Z" fill="#ffffff"/>
|
|
310
|
+
<path d="M ${x + s * 0.04} ${y + s * 0.3} q ${s * 0.077} ${s * 0.12} ${s * 0.154} 0 q ${s * 0.077} ${s * 0.12} ${s * 0.154} 0 q ${s * 0.077} ${s * 0.12} ${s * 0.154} 0 q ${s * 0.077} ${s * 0.12} ${s * 0.154} 0 q ${s * 0.077} ${s * 0.12} ${s * 0.154} 0 q ${s * 0.077} ${s * 0.12} ${s * 0.154} 0" fill="${accent}"/>
|
|
311
|
+
<rect x="${x + s * 0.16}" y="${y + s * 0.44}" width="${s * 0.2}" height="${s * 0.16}" rx="${s * 0.02}" fill="${accent}"/>
|
|
312
|
+
<rect x="${x + s * 0.4}" y="${y + s * 0.44}" width="${s * 0.2}" height="${s * 0.16}" rx="${s * 0.02}" fill="#cbd5e1"/>
|
|
313
|
+
<rect x="${x + s * 0.64}" y="${y + s * 0.44}" width="${s * 0.2}" height="${s * 0.3}" rx="${s * 0.02}" fill="#94a3b8"/>
|
|
314
|
+
<rect x="${x + s * 0.16}" y="${y + s * 0.64}" width="${s * 0.44}" height="${s * 0.1}" rx="${s * 0.02}" fill="#e2e8f0"/>
|
|
315
|
+
</g>`
|
|
316
|
+
}
|
|
317
|
+
if (glyph === 'game') return `<g><rect x="${x + s * 0.1}" y="${y + s * 0.3}" width="${s * 0.8}" height="${s * 0.4}" rx="${s * 0.2}" fill="#fff"/><circle cx="${x + s * 0.3}" cy="${y + s * 0.5}" r="${s * 0.09}" fill="${accent}"/><circle cx="${x + s * 0.68}" cy="${y + s * 0.44}" r="${s * 0.06}" fill="${accent}"/><circle cx="${x + s * 0.78}" cy="${y + s * 0.56}" r="${s * 0.06}" fill="${accent}"/></g>`
|
|
318
|
+
return `<g><circle cx="${x + s / 2}" cy="${y + s / 2}" r="${s * 0.35}" fill="#fff" opacity="0.9"/><circle cx="${x + s / 2}" cy="${y + s / 2}" r="${s * 0.18}" fill="${accent}"/></g>`
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
_iconSvg(t) {
|
|
322
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" font-family="Segoe UI, sans-serif">
|
|
323
|
+
<defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="${t.c1}"/><stop offset="1" stop-color="${t.c2}"/></linearGradient></defs>
|
|
324
|
+
<rect width="256" height="256" rx="56" fill="url(#g)"/>
|
|
325
|
+
<circle cx="200" cy="56" r="60" fill="#ffffff" opacity="0.08"/>
|
|
326
|
+
${this._motif(t.glyph, 48, 52, 160, t.accent)}
|
|
327
|
+
</svg>`
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
_coverSvg(p, t) {
|
|
331
|
+
const esc = s => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
332
|
+
const n = (p.name || '').toLowerCase()
|
|
333
|
+
const title = /steward|管家/.test(n) ? '项目管家' : /board|看板/.test(n) ? '项目白盒看板' : (p.name.startsWith('@') ? p.name.split('/').pop() : p.name)
|
|
334
|
+
const tagline = t.key === 'board' ? '蓝图驱动 · 实时白盒看板 · 依赖DAG · 导游解说' : t.key === 'steward' ? '像经营百货商店一样管理你的软件项目' : (p.notes || '').slice(0, 40)
|
|
335
|
+
const chips = t.key === 'board' ? ['蓝图驱动', '实时进度', '依赖DAG', '代码下钻'] : t.key === 'steward' ? ['分区货架', '全自动发布', '运营采集', '市场情报'] : (p.tags || []).slice(0, 4)
|
|
336
|
+
const chipSvg = chips.map((c, i) => `<g><rect x="${70 + i * 150}" y="470" width="136" height="44" rx="22" fill="#ffffff" opacity="0.16"/><text x="${70 + i * 150 + 68}" y="498" fill="#fff" font-size="20" text-anchor="middle">${esc(c)}</text></g>`).join('')
|
|
337
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 630" font-family="Segoe UI, Microsoft YaHei, sans-serif">
|
|
338
|
+
<defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="${t.c1}"/><stop offset="1" stop-color="${t.c2}"/></linearGradient></defs>
|
|
339
|
+
<rect width="1200" height="630" fill="url(#g)"/>
|
|
340
|
+
<circle cx="1050" cy="120" r="220" fill="#ffffff" opacity="0.07"/>
|
|
341
|
+
<circle cx="120" cy="560" r="160" fill="#ffffff" opacity="0.06"/>
|
|
342
|
+
<text x="70" y="200" fill="#ffffff" font-size="64" font-weight="bold">${esc(title)}</text>
|
|
343
|
+
<text x="70" y="260" fill="#ffffff" opacity="0.85" font-size="28">${esc(tagline)}</text>
|
|
344
|
+
<rect x="70" y="300" width="120" height="6" rx="3" fill="${t.accent}"/>
|
|
345
|
+
${chipSvg}
|
|
346
|
+
${this._motif(t.glyph, 780, 140, 330, t.accent)}
|
|
347
|
+
<text x="70" y="580" fill="#ffffff" opacity="0.6" font-size="20">@chendb888 · DSH 插件</text>
|
|
252
348
|
</svg>`
|
|
253
349
|
}
|
|
254
350
|
}
|
package/src/listing.js
CHANGED
|
@@ -16,6 +16,11 @@ export class ListingMgr {
|
|
|
16
16
|
if (!project) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
17
17
|
const channel = this.store.get('channels', channelId)
|
|
18
18
|
if (!channel) throw storeError('NOT_FOUND', `渠道 ${channelId} 不存在`)
|
|
19
|
+
// R38:定制私有项目(给保险公司等客户,非对外)不得上架公共渠道
|
|
20
|
+
const PUBLIC_CATEGORIES = ['npm-registry', 'mirror', 'source-repo', 'plugin-market', 'game-store']
|
|
21
|
+
if (project.distribution === 'custom-private' && PUBLIC_CATEGORIES.includes(channel.category)) {
|
|
22
|
+
throw storeError('CUSTOM_NOT_PUBLIC', `「${project.name}」是定制私有项目(非对外),不能上架公共渠道 ${channel.name};仅可私有交付`)
|
|
23
|
+
}
|
|
19
24
|
const release = this.store.get('releases', releaseId)
|
|
20
25
|
if (!release || release.projectId !== projectId) throw storeError('INVALID_INPUT', 'release 不存在或不属于该项目')
|
|
21
26
|
if (this.store.list('listings').some(l => l.projectId === projectId && l.channelId === channelId && l.releaseId === releaseId)) throw storeError('DUPLICATE', '该 project×channel×release 已有上架记录')
|
package/src/registry.js
CHANGED
|
@@ -39,6 +39,8 @@ export class Registry {
|
|
|
39
39
|
constructor(store) { this.store = store }
|
|
40
40
|
|
|
41
41
|
_normalizeRoot(rootPath) {
|
|
42
|
+
// 远程-only 项目(从渠道导入,无本地源):rootPath 为 URL,跳过本地存在校验
|
|
43
|
+
if (/^https?:\/\//i.test(rootPath)) return rootPath
|
|
42
44
|
const r = resolve(rootPath)
|
|
43
45
|
if (!existsSync(r)) throw storeError('PATH_NOT_FOUND', `路径不存在:${r}`)
|
|
44
46
|
return r
|
package/src/routes.js
CHANGED
|
@@ -6,7 +6,13 @@ function sendJson(res, code, obj) {
|
|
|
6
6
|
function sameOrigin(req) {
|
|
7
7
|
const origin = req.headers.origin
|
|
8
8
|
if (!origin) return true
|
|
9
|
-
try {
|
|
9
|
+
try {
|
|
10
|
+
const oh = new URL(origin).hostname
|
|
11
|
+
const rh = (req.headers.host || '').split(':')[0]
|
|
12
|
+
const loop = h => h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '[::1]'
|
|
13
|
+
if (loop(oh) && loop(rh)) return true // localhost 与 127.0.0.1 同为回环,视为同源
|
|
14
|
+
return new URL(origin).host === req.headers.host
|
|
15
|
+
} catch { return false }
|
|
10
16
|
}
|
|
11
17
|
function query(req) { return new URL(req.url, 'http://localhost').searchParams }
|
|
12
18
|
async function body(req) {
|
|
@@ -155,6 +161,49 @@ export function registerRoutes(ctx, service) {
|
|
|
155
161
|
try { sendJson(res, 200, { ok: true, result: service.docs.generateUpdateImage(b.projectId, b.version, b) }) }
|
|
156
162
|
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
157
163
|
})
|
|
164
|
+
reg('/project-steward/api/doc/cover', async (req, res) => {
|
|
165
|
+
if (!guard(req, res)) return
|
|
166
|
+
const b = await body(req)
|
|
167
|
+
try { sendJson(res, 200, { ok: true, result: service.docs.generateCover(b.projectId, b) }) }
|
|
168
|
+
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
169
|
+
})
|
|
170
|
+
reg('/project-steward/api/website/list', (req, res) => {
|
|
171
|
+
if (!guard(req, res)) return
|
|
172
|
+
const sites = service.website.list()
|
|
173
|
+
const status = service.store.list('website-status')
|
|
174
|
+
const latest = {}
|
|
175
|
+
for (const s of status) if (!latest[s.websiteId] || s.at > latest[s.websiteId].at) latest[s.websiteId] = s
|
|
176
|
+
sendJson(res, 200, { ok: true, websites: sites.map(w => ({ ...w, latest: latest[w.id] || null })) })
|
|
177
|
+
})
|
|
178
|
+
reg('/project-steward/api/website/add', async (req, res) => {
|
|
179
|
+
if (!guard(req, res)) return
|
|
180
|
+
const b = await body(req)
|
|
181
|
+
try { sendJson(res, 200, { ok: true, website: await service.website.add(b) }) }
|
|
182
|
+
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
183
|
+
})
|
|
184
|
+
reg('/project-steward/api/website/check', async (req, res) => {
|
|
185
|
+
if (!guard(req, res)) return
|
|
186
|
+
const b = await body(req)
|
|
187
|
+
try { sendJson(res, 200, { ok: true, results: await service.website.check(b.websiteId) }) }
|
|
188
|
+
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
189
|
+
})
|
|
190
|
+
reg('/project-steward/api/website/remove', async (req, res) => {
|
|
191
|
+
if (!guard(req, res)) return
|
|
192
|
+
const b = await body(req)
|
|
193
|
+
try { sendJson(res, 200, { ok: true, website: await service.website.remove(b.websiteId, b.reason) }) }
|
|
194
|
+
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
195
|
+
})
|
|
196
|
+
reg('/project-steward/api/website/showcase', (req, res) => {
|
|
197
|
+
if (!guard(req, res)) return
|
|
198
|
+
try { sendJson(res, 200, { ok: true, showcase: service.website.showcase(), html: service.website.showcaseHtml() }) }
|
|
199
|
+
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
200
|
+
})
|
|
201
|
+
reg('/project-steward/api/website/sync', async (req, res) => {
|
|
202
|
+
if (!guard(req, res)) return
|
|
203
|
+
const b = await body(req)
|
|
204
|
+
try { sendJson(res, 200, { ok: true, result: await service.website.deployShowcase(b.websiteId, { build: b.build }) }) }
|
|
205
|
+
catch (e) { sendJson(res, 200, { ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } }) }
|
|
206
|
+
})
|
|
158
207
|
reg('/project-steward/api/maintenance', (req, res) => {
|
|
159
208
|
if (!guard(req, res)) return
|
|
160
209
|
try { sendJson(res, 200, { ok: true, report: service.docs.maintenanceReport() }) }
|
package/src/schemas.js
CHANGED
|
@@ -64,6 +64,7 @@ export const Project = z.object({
|
|
|
64
64
|
id: id('p'), name: z.string().min(1).max(80), rootPath: z.string().min(1),
|
|
65
65
|
type: ProjectType, stage: Stage, owner: z.string().optional(), remote: z.string().optional(),
|
|
66
66
|
tags: z.array(z.string()).default([]), notes: z.string().optional(), templateId: z.string().optional(),
|
|
67
|
+
distribution: z.enum(['public', 'custom-private']).default('public'),
|
|
67
68
|
createdAt: iso, updatedAt: iso, lastReleaseAt: iso.optional(),
|
|
68
69
|
})
|
|
69
70
|
export const Channel = z.object({
|
|
@@ -142,6 +143,24 @@ export const MarketGap = z.object({
|
|
|
142
143
|
demandBasis: z.string().optional(),
|
|
143
144
|
evidence: z.array(z.object({ name: z.string(), stars: z.number().optional(), downloads: z.number().optional(), url: z.string().optional() })).default([]),
|
|
144
145
|
})
|
|
146
|
+
// FR8 个人网站维护(R40):域名可配置,他人可替换
|
|
147
|
+
export const Website = z.object({
|
|
148
|
+
id: id('web'), name: z.string().min(1), url: z.string().min(1), domain: z.string().min(1),
|
|
149
|
+
owner: z.string().optional(), tags: z.array(z.string()).default([]),
|
|
150
|
+
certWarnDays: z.number().int().default(30), status: z.enum(['active', 'removed']).default('active'),
|
|
151
|
+
deploy: z.object({
|
|
152
|
+
method: z.enum(['nextjs-json', 'static-html', 'manual']).default('manual'),
|
|
153
|
+
sshHost: z.string().optional(), path: z.string().optional(),
|
|
154
|
+
buildCmd: z.string().optional(), restartCmd: z.string().optional(),
|
|
155
|
+
}).optional(),
|
|
156
|
+
createdAt: iso, updatedAt: iso,
|
|
157
|
+
})
|
|
158
|
+
export const WebsiteStatus = z.object({
|
|
159
|
+
id: id('ws'), websiteId: z.string(), at: iso,
|
|
160
|
+
certValidTo: iso.optional(), certDaysLeft: z.number().optional(), certIssuer: z.string().optional(),
|
|
161
|
+
httpStatus: z.number().optional(), responseMs: z.number().optional(),
|
|
162
|
+
ok: z.boolean(), issues: z.array(z.string()).default([]),
|
|
163
|
+
})
|
|
145
164
|
export const JournalEntry = z.object({
|
|
146
165
|
seq: z.number().int().min(1), at: iso, actor: Actor, entity: z.string(), entityId: z.string(),
|
|
147
166
|
action: z.string(), before: z.record(z.string(), z.unknown()).optional(),
|
|
@@ -163,6 +182,8 @@ export const collections = {
|
|
|
163
182
|
reminders: z.array(Reminder),
|
|
164
183
|
'collect-runs': z.array(CollectRun),
|
|
165
184
|
'market-gaps': z.array(MarketGap),
|
|
185
|
+
websites: z.array(Website),
|
|
186
|
+
'website-status': z.array(WebsiteStatus),
|
|
166
187
|
}
|
|
167
188
|
|
|
168
189
|
// ---- 工具入参 schema(三面共用)----
|
package/src/service.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Collector } from './collector-sched.js'
|
|
|
9
9
|
import { Market } from './market/analyze.js'
|
|
10
10
|
import { Docs } from './docs.js'
|
|
11
11
|
import { ChannelImport } from './channel-import.js'
|
|
12
|
+
import { WebsiteMgr } from './website.js'
|
|
12
13
|
|
|
13
14
|
export class StewardService {
|
|
14
15
|
constructor(opts = {}) {
|
|
@@ -23,6 +24,7 @@ export class StewardService {
|
|
|
23
24
|
this.market = new Market(this, { fetch: opts.fetch })
|
|
24
25
|
this.docs = new Docs(this)
|
|
25
26
|
this.channelImport = new ChannelImport(this)
|
|
27
|
+
this.website = new WebsiteMgr(this)
|
|
26
28
|
this.collector = new Collector(this, { intervalMinutes: opts.collectIntervalMinutes ?? 60, onUrgent: e => this._broadcast({ type: 'steward/urgent', ...e }) })
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -75,21 +77,30 @@ export class StewardService {
|
|
|
75
77
|
storeSummary() {
|
|
76
78
|
const projects = this.registry.list()
|
|
77
79
|
const metrics = this.store.list('metrics')
|
|
78
|
-
const totals = { downloads: 0, views: 0, comments: 0, revenue: 0 }
|
|
80
|
+
const totals = { downloads: 0, views: 0, comments: 0, revenue: 0, downloadsCumulative: 0, downloadsYesterday: 0, organicYesterday: 0, viewsYesterday: 0, clones: 0, clonesYesterday: 0 }
|
|
79
81
|
const perProject = []
|
|
80
82
|
for (const p of projects) {
|
|
81
83
|
const ms = metrics.filter(m => m.projectId === p.id)
|
|
82
84
|
const latest = latestByDate(ms)
|
|
83
|
-
const sum = { downloads: 0, views: 0, comments: 0, revenue: 0 }
|
|
85
|
+
const sum = { downloads: 0, views: 0, comments: 0, revenue: 0, downloadsCumulative: 0, downloadsYesterday: 0, organicYesterday: 0, viewsYesterday: 0, clones: 0, clonesYesterday: 0 }
|
|
86
|
+
const channels = []
|
|
84
87
|
for (const m of latest) {
|
|
85
|
-
|
|
86
|
-
sum.
|
|
87
|
-
sum.
|
|
88
|
-
sum.
|
|
88
|
+
const x = m.metrics
|
|
89
|
+
sum.downloads += x.downloads || 0
|
|
90
|
+
sum.views += x.views || 0
|
|
91
|
+
sum.comments += x.comments || 0
|
|
92
|
+
sum.revenue += x.revenue || 0
|
|
93
|
+
sum.downloadsCumulative += x.downloadsRaw || x.downloads || 0
|
|
94
|
+
sum.downloadsYesterday += x.downloadsYesterday || 0
|
|
95
|
+
sum.organicYesterday += x.organicYesterday || 0
|
|
96
|
+
sum.viewsYesterday += x.viewsYesterday || 0
|
|
97
|
+
sum.clones += x.clones || 0
|
|
98
|
+
sum.clonesYesterday += x.clonesYesterday || 0
|
|
99
|
+
channels.push({ channelId: m.channelId, date: m.date, downloads: x.downloadsRaw || x.downloads || 0, downloadsYesterday: x.downloadsYesterday || 0, views: x.views || 0, comments: x.comments || 0, clones: x.clones || 0, revenue: x.revenue || 0, stars: x.stars || 0, forks: x.forks || 0 })
|
|
89
100
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
perProject.push({ projectId: p.id, name: p.name, type: p.type, stage: p.stage, ...sum })
|
|
101
|
+
channels.sort((a, b) => b.downloads - a.downloads)
|
|
102
|
+
for (const k of Object.keys(totals)) totals[k] += sum[k]
|
|
103
|
+
perProject.push({ projectId: p.id, name: p.name, type: p.type, stage: p.stage, channels, ...sum })
|
|
93
104
|
}
|
|
94
105
|
return { totals, perProject }
|
|
95
106
|
}
|
package/src/tools.js
CHANGED
|
@@ -6,6 +6,7 @@ import { buildListingTools } from './listing-tools.js'
|
|
|
6
6
|
import { buildOpsTools } from './ops-tools.js'
|
|
7
7
|
import { buildMarketTools } from './market/tools.js'
|
|
8
8
|
import { buildDocsTools } from './docs-tools.js'
|
|
9
|
+
import { buildWebsiteTools } from './website-tools.js'
|
|
9
10
|
|
|
10
11
|
const ok = data => ({ ok: true, data })
|
|
11
12
|
const fail = e => ({ ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } })
|
|
@@ -55,6 +56,7 @@ export function buildTools(service) {
|
|
|
55
56
|
...buildOpsTools(service),
|
|
56
57
|
...buildMarketTools(service),
|
|
57
58
|
...buildDocsTools(service),
|
|
59
|
+
...buildWebsiteTools(service),
|
|
58
60
|
]
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// M17 · 个人网站维护 Agent 工具(FR8)。域名可配置,他人可替换。
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
const ok = data => ({ ok: true, data })
|
|
4
|
+
const fail = e => ({ ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } })
|
|
5
|
+
const guard = (schema, args, fn) => { const p = schema.safeParse(args || {}); if (!p.success) return fail({ code: 'INVALID_INPUT', message: p.error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('; ') }); return Promise.resolve(fn(p.data)).then(ok, fail) }
|
|
6
|
+
const need = s => { if (!s.website) throw { code: 'NOT_READY', message: 'website 未挂载' }; return s.website }
|
|
7
|
+
|
|
8
|
+
export function buildWebsiteTools(service) {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
name: 'steward_website_list',
|
|
12
|
+
description: '列出纳管的个人网站(域名可配置)。只读。',
|
|
13
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
14
|
+
execute: async () => ok(need(service).list()),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'steward_website_add',
|
|
18
|
+
description: '登记一个个人网站用于维护监控(url/domain 可配置,他人可替换自己的域名)。',
|
|
19
|
+
parameters: { type: 'object', properties: { name: { type: 'string' }, url: { type: 'string' }, domain: { type: 'string' }, owner: { type: 'string' }, certWarnDays: { type: 'number' } }, required: ['url'], additionalProperties: false },
|
|
20
|
+
execute: async args => guard(z.object({ name: z.string().optional(), url: z.string(), domain: z.string().optional(), owner: z.string().optional(), certWarnDays: z.number().optional() }), args, d => need(service).add(d)),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'steward_website_check',
|
|
24
|
+
description: '检查网站 SSL 证书到期+可用性,生成状态/异常事件/续期提醒。',
|
|
25
|
+
parameters: { type: 'object', properties: { websiteId: { type: 'string' } }, additionalProperties: false },
|
|
26
|
+
execute: async args => guard(z.object({ websiteId: z.string().optional() }), args, d => need(service).check(d.websiteId)),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'steward_website_remove',
|
|
30
|
+
description: '移除网站(G4,必填 reason)。',
|
|
31
|
+
parameters: { type: 'object', properties: { websiteId: { type: 'string' }, reason: { type: 'string' } }, required: ['websiteId', 'reason'], additionalProperties: false },
|
|
32
|
+
execute: async args => guard(z.object({ websiteId: z.string(), reason: z.string() }), args, d => need(service).remove(d.websiteId, d.reason)),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'steward_website_showcase',
|
|
36
|
+
description: '宣传·作品展示:从货架已上架公开商品生成个人网站「作品展示」专栏(HTML+数据)。format=html 返回可嵌入网页的 HTML。',
|
|
37
|
+
parameters: { type: 'object', properties: { format: { type: 'string', enum: ['data', 'html'] } }, additionalProperties: false },
|
|
38
|
+
execute: async args => guard(z.object({ format: z.enum(['data', 'html']).optional() }), args, d => d.format === 'html' ? ok({ html: need(service).showcaseHtml() }) : ok(need(service).showcase())),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'steward_website_sync',
|
|
42
|
+
description: '把已上架公开商品同步到个人网站作品展示专栏(GEO/AIO 宣传)。按网站 deploy 配置适配(nextjs-json/static-html/manual),可触发构建+重启。',
|
|
43
|
+
parameters: { type: 'object', properties: { websiteId: { type: 'string' }, build: { type: 'boolean' } }, required: ['websiteId'], additionalProperties: false },
|
|
44
|
+
execute: async args => guard(z.object({ websiteId: z.string(), build: z.boolean().optional() }), args, d => need(service).deployShowcase(d.websiteId, { build: d.build })),
|
|
45
|
+
},
|
|
46
|
+
]
|
|
47
|
+
}
|
package/src/website.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// M17 · 个人网站(FR8 / R40/R41/R42)。宣传·作品展示同步(GEO)+ 维护监控;域名/部署可配置,适配任何个人域名。
|
|
2
|
+
import tls from 'node:tls'
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import { writeFileSync, copyFileSync } from 'node:fs'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { Website, WebsiteStatus } from './schemas.js'
|
|
8
|
+
import { genId, storeError } from './store.js'
|
|
9
|
+
const now = () => new Date().toISOString()
|
|
10
|
+
const defaultFetch = (...a) => globalThis.fetch(...a)
|
|
11
|
+
|
|
12
|
+
export class WebsiteMgr {
|
|
13
|
+
constructor(service, opts = {}) { this.service = service; this.store = service.store; this.fetch = opts.fetch || defaultFetch }
|
|
14
|
+
|
|
15
|
+
list() { return this.store.list('websites').filter(w => w.status !== 'removed') }
|
|
16
|
+
|
|
17
|
+
async add({ name, url, domain, owner, tags, certWarnDays }, actor = 'user') {
|
|
18
|
+
const d = domain || new URL(url).hostname
|
|
19
|
+
if (this.store.list('websites').some(w => w.domain === d)) throw storeError('DUPLICATE', `网站 ${d} 已登记`)
|
|
20
|
+
const w = Website.parse({ id: genId('web'), name: name || d, url, domain: d, owner, tags: tags || [], certWarnDays: certWarnDays || 30, createdAt: now(), updatedAt: now() })
|
|
21
|
+
return this.store.create('websites', w, actor, 'website-add')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
remove(id, reason, actor = 'user') {
|
|
25
|
+
const w = this.store.get('websites', id)
|
|
26
|
+
if (!w) throw storeError('NOT_FOUND', `网站 ${id} 不存在`)
|
|
27
|
+
if (!reason) throw storeError('REASON_REQUIRED', '移除网站需 reason(G4)')
|
|
28
|
+
return this.store.update('websites', id, d => { d.status = 'removed'; d.updatedAt = now() }, actor, 'website-remove', reason)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_cert(domain, timeout = 10000) {
|
|
32
|
+
return new Promise(resolve => {
|
|
33
|
+
const s = tls.connect(443, domain, { servername: domain, rejectUnauthorized: false }, () => {
|
|
34
|
+
const c = s.getPeerCertificate()
|
|
35
|
+
const days = Math.round((Date.parse(c.valid_to) - Date.now()) / 86400000)
|
|
36
|
+
resolve({ validTo: new Date(c.valid_to).toISOString(), daysLeft: days, issuer: c.issuer?.O || c.issuer?.CN || '' })
|
|
37
|
+
s.end()
|
|
38
|
+
})
|
|
39
|
+
s.on('error', () => resolve(null))
|
|
40
|
+
setTimeout(() => { try { s.destroy() } catch {} resolve(null) }, timeout)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async _uptime(url, timeout = 10000) {
|
|
45
|
+
const t0 = Date.now()
|
|
46
|
+
try {
|
|
47
|
+
const ctrl = new AbortController(); const t = setTimeout(() => ctrl.abort(), timeout)
|
|
48
|
+
const r = await this.fetch(url, { signal: ctrl.signal, redirect: 'follow' })
|
|
49
|
+
clearTimeout(t)
|
|
50
|
+
return { status: r.status, ms: Date.now() - t0 }
|
|
51
|
+
} catch { return { status: 0, ms: Date.now() - t0 } }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async check(id, actor = 'agent') {
|
|
55
|
+
const sites = id ? [this.store.get('websites', id)].filter(Boolean) : this.list()
|
|
56
|
+
const results = []
|
|
57
|
+
for (const w of sites) {
|
|
58
|
+
const cert = await this._cert(w.domain)
|
|
59
|
+
const up = await this._uptime(w.url)
|
|
60
|
+
const issues = []
|
|
61
|
+
if (!cert) issues.push('cert-unreachable')
|
|
62
|
+
else if (cert.daysLeft < 0) issues.push('cert-expired')
|
|
63
|
+
else if (cert.daysLeft <= w.certWarnDays) issues.push('cert-expiring')
|
|
64
|
+
if (up.status === 0) issues.push('site-down')
|
|
65
|
+
else if (up.status >= 400) issues.push('http-' + up.status)
|
|
66
|
+
const st = WebsiteStatus.parse({
|
|
67
|
+
id: genId('ws'), websiteId: w.id, at: now(),
|
|
68
|
+
certValidTo: cert?.validTo, certDaysLeft: cert?.daysLeft, certIssuer: cert?.issuer,
|
|
69
|
+
httpStatus: up.status, responseMs: up.ms, ok: issues.length === 0, issues,
|
|
70
|
+
})
|
|
71
|
+
await this.store.create('website-status', st, actor, 'website-check')
|
|
72
|
+
// 异常事件 + 证书续期提醒
|
|
73
|
+
for (const iss of issues) {
|
|
74
|
+
await this.store.create('events', { id: genId('ev'), projectId: w.id, kind: iss.startsWith('cert') ? 'notice' : 'incident', severity: iss === 'cert-expired' || iss === 'site-down' ? 'critical' : 'warn', text: `网站 ${w.domain}:${iss}(证书剩 ${cert?.daysLeft ?? '?'} 天 / HTTP ${up.status})`, at: now() }, actor, 'website-issue').catch(() => {})
|
|
75
|
+
}
|
|
76
|
+
if (cert && cert.daysLeft <= w.certWarnDays) {
|
|
77
|
+
const due = cert.validTo
|
|
78
|
+
const exists = this.store.list('reminders').some(r => r.projectId === w.id && r.kind === 'renewal' && r.status === 'active')
|
|
79
|
+
if (!exists) await this.store.create('reminders', { id: genId('rm'), projectId: w.id, kind: 'renewal', dueAt: due, leadDays: Math.min(w.certWarnDays, 30), note: `网站 ${w.domain} SSL 证书 ${due.slice(0, 10)} 到期,需续期`, status: 'active' }, actor, 'cert-reminder').catch(() => {})
|
|
80
|
+
}
|
|
81
|
+
results.push({ website: w, status: st })
|
|
82
|
+
}
|
|
83
|
+
return results
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// FR8.7 宣传·作品展示:从货架已上架公开商品生成个人网站「作品展示」专栏内容
|
|
87
|
+
showcase() {
|
|
88
|
+
const projects = this.service.listProjects().filter(p => (p.distribution || 'public') === 'public')
|
|
89
|
+
const listings = this.store.list('listings')
|
|
90
|
+
const items = []
|
|
91
|
+
for (const p of projects) {
|
|
92
|
+
const listed = listings.filter(l => l.projectId === p.id && l.status === 'listed')
|
|
93
|
+
if (!listed.length) continue // 仅展示已上架商品
|
|
94
|
+
const repo = (p.remote || '').match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/)?.[1]
|
|
95
|
+
const cover = repo ? `https://raw.githubusercontent.com/${repo}/main/docs/images/cover.png` : null
|
|
96
|
+
const icon = repo ? `https://raw.githubusercontent.com/${repo}/main/docs/images/icon.png` : null
|
|
97
|
+
const ms = this.store.list('metrics').filter(m => m.projectId === p.id)
|
|
98
|
+
// 经营数据:每渠道取最新快照再汇总(与店铺概况同口径:按 date 取最新,at 兜底),避免跨时间重复累加
|
|
99
|
+
const latestByCh = {}
|
|
100
|
+
for (const m of ms) {
|
|
101
|
+
const cur = latestByCh[m.channelId]
|
|
102
|
+
if (!cur || (m.date || '') > (cur.date || '') || ((m.date || '') === (cur.date || '') && (m.at || '') > (cur.at || ''))) latestByCh[m.channelId] = m
|
|
103
|
+
}
|
|
104
|
+
const sum = k => Object.values(latestByCh).reduce((a, m) => a + (m.metrics[k] || 0), 0)
|
|
105
|
+
const metrics = { downloads: sum('downloads'), views: sum('views'), comments: sum('comments'), revenue: sum('revenue') }
|
|
106
|
+
const rel = this.store.list('releases').filter(r => r.projectId === p.id).sort((a, b) => b.releasedAt.localeCompare(a.releasedAt))[0]
|
|
107
|
+
items.push({
|
|
108
|
+
id: p.id, name: p.name, type: p.type, description: p.notes || '',
|
|
109
|
+
cover, icon, url: p.remote || (listed[0] && listed[0].platformUrl) || '',
|
|
110
|
+
version: rel?.version || null, downloads: metrics.downloads, metrics,
|
|
111
|
+
channels: [...new Set(listed.map(l => l.channelId))],
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
return { section: '作品展示', generatedAt: now(), items }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
showcaseHtml() {
|
|
118
|
+
const { items } = this.showcase()
|
|
119
|
+
const esc = s => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
120
|
+
const cards = items.map(it => `
|
|
121
|
+
<article class="work-card">
|
|
122
|
+
${it.cover ? `<img src="${esc(it.cover)}" alt="${esc(it.name)}" loading="lazy"/>` : ''}
|
|
123
|
+
<div class="work-body">
|
|
124
|
+
<h3>${esc(it.name)}${it.version ? ` <span class="ver">v${esc(it.version)}</span>` : ''}</h3>
|
|
125
|
+
<p>${esc(it.description)}</p>
|
|
126
|
+
<div class="work-meta"><span>⬇ ${it.downloads}</span><span>${it.channels.length} 渠道上架</span></div>
|
|
127
|
+
${it.url ? `<a href="${esc(it.url)}" target="_blank" rel="noopener">查看项目 →</a>` : ''}
|
|
128
|
+
</div>
|
|
129
|
+
</article>`).join('')
|
|
130
|
+
return `<!-- 作品展示专栏(项目管家自动生成 ${now()}) -->
|
|
131
|
+
<section id="works" class="works-showcase">
|
|
132
|
+
<h2>作品展示</h2>
|
|
133
|
+
<div class="works-grid">${cards}
|
|
134
|
+
</div>
|
|
135
|
+
</section>
|
|
136
|
+
<style>
|
|
137
|
+
.works-showcase{padding:48px 24px;max-width:1100px;margin:0 auto}
|
|
138
|
+
.works-showcase h2{font-size:28px;margin-bottom:24px}
|
|
139
|
+
.works-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:20px}
|
|
140
|
+
.work-card{border:1px solid #e5e7eb;border-radius:12px;overflow:hidden;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.08)}
|
|
141
|
+
.work-card img{width:100%;height:160px;object-fit:cover;display:block}
|
|
142
|
+
.work-body{padding:16px}
|
|
143
|
+
.work-body h3{font-size:18px;margin:0 0 8px}
|
|
144
|
+
.work-body .ver{font-size:12px;color:#6b7280;font-weight:normal}
|
|
145
|
+
.work-body p{font-size:14px;color:#4b5563;margin:0 0 12px}
|
|
146
|
+
.work-meta{display:flex;gap:16px;font-size:13px;color:#6b7280;margin-bottom:12px}
|
|
147
|
+
.work-body a{color:#ff5000;text-decoration:none;font-size:14px}
|
|
148
|
+
</style>`
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// FR8.8 项目→个人网站同步(GEO/AIO 宣传)。按 website.deploy 配置适配任何站点。
|
|
152
|
+
_worksData() {
|
|
153
|
+
const { items } = this.showcase()
|
|
154
|
+
const typeLabel = { 'dsh-plugin': 'DSH 插件', game: '游戏', 'web-app': 'Web 应用', 'business-system': '业务系统', engine: '引擎', research: '工具' }
|
|
155
|
+
return items.map(it => ({
|
|
156
|
+
title: it.name, subtitle: (typeLabel[it.type] || it.type) + ' · 已上架',
|
|
157
|
+
cover: it.cover, icon: it.icon, description: it.description,
|
|
158
|
+
status: `已上架 ${it.channels.length} 个渠道` + (it.version ? `(v${it.version})` : ''),
|
|
159
|
+
period: String(new Date().getFullYear()), role: '独立开发', version: it.version,
|
|
160
|
+
metrics: it.metrics,
|
|
161
|
+
links: it.url ? [{ label: '查看项目', href: it.url }] : [],
|
|
162
|
+
}))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async deployShowcase(websiteId, opts = {}) {
|
|
166
|
+
const w = this.store.get('websites', websiteId)
|
|
167
|
+
if (!w) throw storeError('NOT_FOUND', `网站 ${websiteId} 不存在`)
|
|
168
|
+
const dep = w.deploy || { method: 'manual' }
|
|
169
|
+
const data = this._worksData()
|
|
170
|
+
const html = this.showcaseHtml()
|
|
171
|
+
if (dep.method === 'manual' || !dep.path) {
|
|
172
|
+
return { synced: false, method: 'manual', works: data.length, html, data, note: '未配置自动部署;已生成 works 数据/HTML,可手动放入网站' }
|
|
173
|
+
}
|
|
174
|
+
const tmp = join(tmpdir(), `steward-works-${w.id}.json`)
|
|
175
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2))
|
|
176
|
+
const log = []
|
|
177
|
+
const ssh = (cmd) => spawnSync('ssh', ['-o', 'ConnectTimeout=20', dep.sshHost, cmd], { encoding: 'utf8', timeout: 300000 })
|
|
178
|
+
try {
|
|
179
|
+
if (dep.method === 'nextjs-json') {
|
|
180
|
+
if (dep.sshHost) { const r = spawnSync('scp', ['-o', 'ConnectTimeout=20', tmp, `${dep.sshHost}:${dep.path}`], { encoding: 'utf8', timeout: 60000 }); log.push('scp works.json ' + (r.status === 0 ? '✓' : '✗')) }
|
|
181
|
+
else { copyFileSync(tmp, dep.path); log.push('write works.json ✓') }
|
|
182
|
+
if (opts.build !== false && dep.buildCmd) { const r = dep.sshHost ? ssh(dep.buildCmd) : spawnSync(dep.buildCmd, { shell: true, encoding: 'utf8', timeout: 300000 }); log.push('build ' + (r.status === 0 ? '✓' : '✗')) }
|
|
183
|
+
if (opts.build !== false && dep.restartCmd) { const r = dep.sshHost ? ssh(dep.restartCmd) : spawnSync(dep.restartCmd, { shell: true, encoding: 'utf8', timeout: 60000 }); log.push('restart ' + (r.status === 0 ? '✓' : '✗')) }
|
|
184
|
+
} else if (dep.method === 'static-html') {
|
|
185
|
+
const tmpHtml = join(tmpdir(), `steward-works-${w.id}.html`)
|
|
186
|
+
writeFileSync(tmpHtml, html)
|
|
187
|
+
if (dep.sshHost) { const r = spawnSync('scp', ['-o', 'ConnectTimeout=20', tmpHtml, `${dep.sshHost}:${dep.path}`], { encoding: 'utf8', timeout: 60000 }); log.push('scp works.html ' + (r.status === 0 ? '✓' : '✗')) }
|
|
188
|
+
else { copyFileSync(tmpHtml, dep.path); log.push('write works.html ✓') }
|
|
189
|
+
}
|
|
190
|
+
return { synced: true, method: dep.method, works: data.length, log }
|
|
191
|
+
} catch (e) { return { synced: false, error: String(e.message || e), log } }
|
|
192
|
+
}
|
|
193
|
+
}
|