[new status page] wip

This commit is contained in:
Louis Lam
2022-03-10 21:34:30 +08:00
parent ae14ad5a84
commit 50d6e888c2
13 changed files with 220 additions and 40 deletions

View File

@@ -0,0 +1,44 @@
const { BeanModel } = require("redbean-node/dist/bean-model");
const { R } = require("redbean-node");
class StatusPage extends BeanModel {
static async sendStatusPageList(io, socket) {
let result = {};
let list = await R.findAll("status_page", " ORDER BY title ");
for (let item of list) {
result[item.id] = await item.toJSON();
}
io.to(socket.userID).emit("statusPageList", result);
return list;
}
async toJSON() {
return {
id: this.id,
slug: this.slug,
title: this.title,
icon: this.icon,
theme: this.theme,
published: !!this.published,
showTags: !!this.show_tags,
};
}
async toPublicJSON() {
return {
slug: this.slug,
title: this.title,
icon: this.icon,
theme: this.theme,
published: !!this.published,
showTags: !!this.show_tags,
};
}
}
module.exports = StatusPage;

View File

@@ -83,33 +83,28 @@ router.get("/api/push/:pushToken", async (request, response) => {
});
// Status Page Config
router.get("/api/status-page/config", async (_request, response) => {
router.get("/api/status-page/config/:slug", async (request, response) => {
allowDevAllOrigin(response);
let slug = request.params.slug;
let config = await getSettings("statusPage");
let statusPage = await R.findOne("status_page", " slug = ? ", [
slug
]);
if (! config.statusPageTheme) {
config.statusPageTheme = "light";
if (!statusPage) {
response.statusCode = 404;
response.json({
msg: "Not Found"
});
return;
}
if (! config.statusPagePublished) {
config.statusPagePublished = true;
}
if (! config.statusPageTags) {
config.statusPageTags = false;
}
if (! config.title) {
config.title = "Uptime Kuma";
}
response.json(config);
response.json(await statusPage.toPublicJSON());
});
// Status Page - Get the current Incident
// Can fetch only if published
router.get("/api/status-page/incident", async (_, response) => {
router.get("/api/status-page/incident/:slug", async (_, response) => {
allowDevAllOrigin(response);
try {
@@ -133,7 +128,7 @@ router.get("/api/status-page/incident", async (_, response) => {
// Status Page - Monitor List
// Can fetch only if published
router.get("/api/status-page/monitor-list", cache("5 minutes"), async (_request, response) => {
router.get("/api/status-page/monitor-list/:slug", cache("5 minutes"), async (_request, response) => {
allowDevAllOrigin(response);
try {
@@ -172,7 +167,7 @@ router.get("/api/status-page/monitor-list", cache("5 minutes"), async (_request,
// Status Page Polling Data
// Can fetch only if published
router.get("/api/status-page/heartbeat", cache("5 minutes"), async (_request, response) => {
router.get("/api/status-page/heartbeat/:slug", cache("5 minutes"), async (_request, response) => {
allowDevAllOrigin(response);
try {

View File

@@ -132,6 +132,7 @@ const { sendNotificationList, sendHeartbeatList, sendImportantHeartbeatList, sen
const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler");
const databaseSocketHandler = require("./socket-handlers/database-socket-handler");
const TwoFA = require("./2fa");
const StatusPage = require("./model/status_page");
app.use(express.json());
@@ -1414,6 +1415,8 @@ async function afterLogin(socket, user) {
for (let monitorID in monitorList) {
await Monitor.sendStats(io, monitorID, user.id);
}
await StatusPage.sendStatusPageList(io, socket);
}
async function getMonitorJSONList(userID) {