| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /**
- * 管理员列表:可读摘要 + Arco Tag 色号(与设计约定一致)。
- */
- function parseDetail(raw) {
- if (raw == null || raw === '') return {}
- if (typeof raw === 'object') return raw
- try {
- return JSON.parse(raw)
- } catch {
- return { _text: String(raw) }
- }
- }
- const EVENT_META = {
- fetch: { label: '提取 IP', color: 'green' },
- invalidate: { label: '作废缓存', color: 'orangered' },
- fallback_direct: { label: '回退直连', color: 'red' },
- config_change: { label: '配置变更', color: 'arcoblue' }
- }
- function summarizeLogRow(record) {
- const event = record.event
- const d = parseDetail(record.detail)
- const lines = []
- if (event === 'fetch') {
- if (d.request_id) lines.push(`请求 ID:${d.request_id}`)
- if (d.code) lines.push(`接口状态:${d.code}`)
- } else if (event === 'invalidate') {
- if (d.reason) lines.push(`原因:${d.reason}`)
- if (d.message) lines.push(`说明:${d.message}`)
- if (d.code) lines.push(`错误码:${d.code}`)
- if (d.status) lines.push(`HTTP:${d.status}`)
- } else if (event === 'fallback_direct') {
- if (d.reason) lines.push(`触发原因:${d.reason}`)
- if (d.reason === 'exhausted_proxy_then_direct') {
- lines.push('多轮提取与经代理 POST 均未成功,已改直连接口')
- } else if (d.message) {
- lines.push(`说明:${d.message}`)
- }
- if (d.after) lines.push(`阶段:${d.after}`)
- if (d.code) lines.push(`错误码:${d.code}`)
- } else if (event === 'config_change') {
- lines.push(`代理开关:${d.proxy_enabled === 1 ? '开' : '关'}`)
- if (d.area !== undefined) lines.push(`地区 area:「${d.area || '(空)'}」`)
- if (d.area_ex !== undefined) lines.push(`排除 area_ex:「${d.area_ex || '(空)'}」`)
- if (d.isp !== undefined) lines.push(`运营商 isp:${d.isp ?? '不限'}`)
- if (d.distinct_extract !== undefined) lines.push(`去重提取:${d.distinct_extract ? '是' : '否'}`)
- if (d.invalidate_cache) lines.push('已勾选清空服务端 IP 缓存')
- if (d.operator) lines.push(`操作者 UUID:${d.operator}`)
- } else if (Object.keys(d).length) {
- if (d._text) lines.push(String(d._text))
- else {
- Object.keys(d).slice(0, 6).forEach(k => {
- lines.push(`${k}:${typeof d[k] === 'object' ? JSON.stringify(d[k]) : d[k]}`)
- })
- }
- }
- let summary = lines.length ? lines.join(';') : '—'
- const meta = EVENT_META[event] || { label: event || '未知', color: 'gray' }
- const serverShown = record.server ? `节点 ${record.server}` : ''
- return {
- event_label: meta.label,
- event_color: meta.color,
- summary,
- detail_lines: lines,
- server_tip: serverShown || null,
- ...(record.server && record.deadline ? { deadline_tip: `${record.server} · ${record.deadline}` } : {})
- }
- }
- /**
- * 青果语义下的出口 IP(proxy_ip),非代理节点 host。
- */
- function extractEgressIp(record) {
- const d = parseDetail(record.detail)
- const p = d.proxy_ip
- if (p === null || p === undefined || p === '') return null
- const s = String(p).trim()
- return /^(\d{1,3}\.){3}\d{1,3}$/.test(s) ? s : null
- }
- module.exports = {
- summarizeLogRow,
- parseDetail,
- EVENT_META,
- extractEgressIp
- }
|