()
| 126 | } |
| 127 | |
| 128 | async function fetchData(){ |
| 129 | try{ |
| 130 | const res = await fetch('json/stats.json?_=' + Date.now(), { cache: 'no-store' }); |
| 131 | if(!res.ok) throw new Error(String(res.status)); |
| 132 | const data = await res.json(); |
| 133 | if(data.reload && !shouldSuppressStatsReload()) { |
| 134 | location.reload(); |
| 135 | return; |
| 136 | } |
| 137 | S.updated = Number(data.updated || 0); |
| 138 | S.servers = (data.servers || []).map((server, index) => { |
| 139 | const base = [server.name || '-', server.location || '-', server.type || '-'].join('|'); |
| 140 | const key = `${base}#${index + 1}`; |
| 141 | server._key = key; |
| 142 | if(!S.hist[key]) S.hist[key] = { cu: [], ct: [], cm: [] }; |
| 143 | if(!S.loadHist[key]) S.loadHist[key] = { l1: [], l5: [], l15: [] }; |
| 144 | pushHistory(S.hist[key].cu, server.time_10010); |
| 145 | pushHistory(S.hist[key].ct, server.time_189); |
| 146 | pushHistory(S.hist[key].cm, server.time_10086); |
| 147 | pushHistory(S.loadHist[key].l1, server.load_1); |
| 148 | pushHistory(S.loadHist[key].l5, server.load_5); |
| 149 | pushHistory(S.loadHist[key].l15, server.load_15); |
| 150 | return server; |
| 151 | }); |
| 152 | S.ssl = data.sslcerts || []; |
| 153 | render(); |
| 154 | }catch(err){ |
| 155 | const notice = $('notice'); |
| 156 | notice.style.display = 'flex'; |
| 157 | notice.textContent = '数据获取失败: ' + err.message; |
| 158 | } |
| 159 | } |
| 160 | function shouldSuppressStatsReload(){ |
| 161 | return S.admin.saving || S.activeTab === 'config' || Date.now() < S.suppressStatsReloadUntil; |
| 162 | } |
no test coverage detected