import $ from "jquery" import { SystemInfoDescription, SystemInfo as ModelSystemInfo } from "../../src/models/systemInfo"; import { HostnameServiceDescription } from "../../src/models/service"; export namespace DAL { export class SystemInfo { private static lastCachedData: SystemInfoDescription|null = null; private static getData(): Promise { return new Promise(ok => { $.get("/api/sysinfo", response => { this.lastCachedData = response; ok(); }); }); } private static getDataWithCache(): Promise { if (this.lastCachedData) return Promise.resolve(); return this.getData(); } public static async getInfo(hostname: string): Promise { await this.getDataWithCache(); return this.lastCachedData?.systemInfo[hostname]; } public static async listHosts(): Promise> { await this.getDataWithCache(); return Object.keys(this.lastCachedData?.systemInfo ?? {}); } public static async getServices(): Promise { return new Promise(ok => { $.get("/api/services/list", response => { ok(response.services); }); }); } } }