Skip to content

Commit bf7f2cc

Browse files
committed
impr: update maintenance/server down message based on instatus api
1 parent d567130 commit bf7f2cc

File tree

1 file changed

+55
-8
lines changed
  • frontend/src/ts/elements

1 file changed

+55
-8
lines changed

frontend/src/ts/elements/psa.ts

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,63 @@ async function getLatest(): Promise<PSA[] | null> {
4141
false
4242
);
4343
} else {
44-
Notifications.addPSA(
45-
"Looks like the server is experiencing maintenance or some unexpected down time.<br>Check the <a target= '_blank' href='https://monkeytype.instatus.com/'>status page</a> or <a target= '_blank' href='https://x.com/monkeytype'>Twitter</a> for more information.",
46-
-1,
47-
"exclamation-triangle",
48-
false,
49-
undefined,
50-
true
44+
type InstatusSummary = {
45+
page: {
46+
name: string;
47+
url: string;
48+
status: string;
49+
};
50+
activeIncidents: {
51+
id: string;
52+
name: string;
53+
started: string;
54+
status: string;
55+
impact: string;
56+
url: string;
57+
updatedAt: string;
58+
}[];
59+
activeMaintenances: {
60+
id: string;
61+
name: string;
62+
start: string;
63+
status: "NOTSTARTEDYET" | "INPROGRESS" | "COMPLETED";
64+
duration: number;
65+
url: string;
66+
updatedAt: string;
67+
}[];
68+
};
69+
70+
const instatus = await fetch(
71+
"https://monkeytype.instatus.com/summary.json"
5172
);
52-
}
73+
const instatusData =
74+
(await instatus.json()) as unknown as InstatusSummary;
5375

76+
const maintenanceData = instatusData.activeMaintenances[0];
77+
78+
if (
79+
maintenanceData !== undefined &&
80+
maintenanceData.status === "INPROGRESS"
81+
) {
82+
Notifications.addPSA(
83+
`Server is currently offline for scheduled maintenance. <a target= '_blank' href='${maintenanceData.url}'>Check the status page</a> for more info.`,
84+
-1,
85+
"bullhorn",
86+
true,
87+
undefined,
88+
true
89+
);
90+
} else {
91+
Notifications.addPSA(
92+
"Looks like the server is experiencing unexpected down time.<br>Check the <a target= '_blank' href='https://monkeytype.instatus.com/'>status page</a> for more information.",
93+
-1,
94+
"exclamation-triangle",
95+
false,
96+
undefined,
97+
true
98+
);
99+
}
100+
}
54101
return null;
55102
} else if (response.status === 503) {
56103
Notifications.addPSA(

0 commit comments

Comments
 (0)