_ops_fresh.mjs 1.1 KB

1234567891011121314151617181920212223
  1. // P92-6:破缓存读取 /ops/api/state 与 /api/fleet(带 ?ts= 与 no-cache 头)
  2. const GW = 'http://106.120.102.238:28084'
  3. const ts = Date.now()
  4. async function get(path, json) {
  5. const r = await fetch(GW + path + (path.includes('?') ? '&' : '?') + 'ts=' + ts, {
  6. headers: { 'Cache-Control': 'no-cache', Pragma: 'no-cache' },
  7. })
  8. const b = await r.text()
  9. console.log(path + ' -> ' + r.status + ' ' + b.length + ' B')
  10. if (json) { try { return JSON.parse(b) } catch { return null } }
  11. return b
  12. }
  13. const j = await get('/ops/api/state', true)
  14. if (j) {
  15. console.log(' now=' + j.now + ' · job.status=' + (j.job || {}).status + ' · rc=' + (j.job || {}).rc + ' · seconds=' + (j.job || {}).seconds)
  16. const tail = (j.job || {}).log_tail || []
  17. console.log(' 日志尾部:')
  18. for (const l of tail.slice(-6)) console.log(' ' + String(l).slice(0, 180))
  19. console.log(' products=' + JSON.stringify(j.products).slice(0, 200))
  20. console.log(' anchors=' + JSON.stringify(j.anchors))
  21. }
  22. const f = await get('/api/fleet', false)
  23. if (typeof f === 'string') console.log(' fleet 前 160 字: ' + f.slice(0, 160))