| 21 | |
| 22 | class StatusHandler extends Handler { |
| 23 | async get() { |
| 24 | const stats = await getStatus(); |
| 25 | const compilers = {}; |
| 26 | const warn = {}; |
| 27 | const result: Array<{ key: string[], message: string }> = []; |
| 28 | // For each language, select the most common compiler message version, |
| 29 | // then merge languages with the same message. |
| 30 | for (const stat of stats) { |
| 31 | if (!stat.battery?.hasBattery) stat.battery = 'No battery'; |
| 32 | else stat.battery = `${stat.battery.type} ${stat.battery.model} ${stat.battery.percent}%${stat.battery.isCharging ? ' Charging' : ''}`; |
| 33 | if (stat.compilers) { |
| 34 | for (const key in stat.compilers) { |
| 35 | if (!compilers[key]) compilers[key] ||= []; |
| 36 | const related = compilers[key].find((i) => i.message === stat.compilers[key]); |
| 37 | if (related) related.related.push(stat._id); |
| 38 | else { |
| 39 | compilers[key].push({ |
| 40 | related: [stat._id], |
| 41 | message: stat.compilers[key], |
| 42 | }); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | for (const key in compilers) { |
| 48 | compilers[key].sort((a, b) => b.related.length - a.related.length); |
| 49 | const message = compilers[key][0].message; |
| 50 | for (let i = 1; i < compilers[key].length; i++) { |
| 51 | for (const id of compilers[key][i].related) { |
| 52 | warn[id] = true; |
| 53 | } |
| 54 | } |
| 55 | const t = result.find((i) => i.message === message); |
| 56 | if (t) t.key.push(key); |
| 57 | else result.push({ key: [key], message }); |
| 58 | } |
| 59 | const LANGS = SettingModel.langs; |
| 60 | const languages = {}; |
| 61 | for (const key in LANGS) { |
| 62 | if (LANGS[key].hidden) continue; |
| 63 | languages[`${LANGS[key].display}(${key})`] = LANGS[key].compile || LANGS[key].execute; |
| 64 | } |
| 65 | this.response.body = { stats, languages, compilers: result }; |
| 66 | this.response.template = 'status.html'; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | class StatusUpdateHandler extends Handler { |