systemInfo.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import $ from "jquery"
  2. import { SystemInfoDescription, SystemInfo as ModelSystemInfo } from "../../src/models/systemInfo";
  3. import { HostnameServiceDescription } from "../../src/models/service";
  4. export namespace DAL {
  5. export class SystemInfo {
  6. private static lastCachedData: SystemInfoDescription|null = null;
  7. private static getData(): Promise<void> {
  8. return new Promise(ok => {
  9. $.get("/api/sysinfo", response => {
  10. this.lastCachedData = response;
  11. ok();
  12. });
  13. });
  14. }
  15. private static getDataWithCache(): Promise<void> {
  16. if (this.lastCachedData)
  17. return Promise.resolve();
  18. return this.getData();
  19. }
  20. public static async getInfo(hostname: string): Promise<ModelSystemInfo|undefined> {
  21. await this.getDataWithCache();
  22. return this.lastCachedData?.systemInfo[hostname];
  23. }
  24. public static async listHosts(): Promise<Array<string>> {
  25. await this.getDataWithCache();
  26. return Object.keys(this.lastCachedData?.systemInfo ?? {});
  27. }
  28. public static async getServices(): Promise<HostnameServiceDescription> {
  29. return new Promise(ok => {
  30. $.get("/api/services/list", response => {
  31. ok(response.services);
  32. });
  33. });
  34. }
  35. }
  36. }