1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2025-07-15 01:44:19 +02:00

[Status Page] Add a new status page

This commit is contained in:
Louis Lam
2022-03-17 23:38:43 +08:00
parent 719a136d1e
commit 27bfae67af
3 changed files with 104 additions and 19 deletions

View File

@ -185,7 +185,7 @@ module.exports.statusPageSocketHandler = (socket) => {
});
} catch (error) {
console.log(error);
console.error(error);
callback({
ok: false,
@ -194,4 +194,52 @@ module.exports.statusPageSocketHandler = (socket) => {
}
});
// Add a new status page
socket.on("addStatusPage", async (title, slug, callback) => {
try {
checkLogin(socket);
title = title?.trim();
slug = slug?.trim();
// Check empty
if (!title || !slug) {
throw new Error("Please input all fields");
}
// Make sure slug is string
if (typeof slug !== "string") {
throw new Error("Slug -Accept string only");
}
// lower case only
slug = slug.toLowerCase();
// Check slug a-z, 0-9, - only
// Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
if (!slug.match(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/)) {
throw new Error("Invalid Slug");
}
let statusPage = R.dispense("status_page");
statusPage.slug = slug;
statusPage.title = title;
statusPage.theme = "light";
statusPage.icon = "";
await R.store(statusPage);
callback({
ok: true,
msg: "OK!"
});
} catch (error) {
console.error(error);
callback({
ok: false,
msg: error.message,
});
}
});
};