Files
dsh_ai1net_server/归档/试验与样例/poc-dsh-local/patch-admin-storage.py
T

19 lines
838 B
Python
Raw Normal View History

#!/usr/bin/env python3
import io
p = '/opt/dshs/src/web/routes/admin.ts'
s = io.open(p, encoding='utf-8').read()
anchor = " app.get('/api/admin/users', { preHandler: requireAdmin },"
assert anchor in s
new = """ // 档案 28:存储用量面板(读取维护脚本生成的快照文件,避免每次请求都 du)
app.get('/api/admin/storage', { preHandler: requireAdmin }, async () => {
const { readFileSync } = await import('node:fs')
try {
return JSON.parse(readFileSync(process.env.DSH_STORAGE_REPORT ?? '/var/run/dsh-storage-report.json', 'utf8'))
} catch {
return { generatedAt: null, users: [], note: '报告尚未生成(cron 每小时刷新一次)' }
}
})
""" + anchor
io.open(p, 'w', encoding='utf-8', newline='').write(s.replace(anchor, new, 1))
print('D admin.ts 新端点已写入')