|
|
|
@ -90,6 +90,8 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|
|
|
|
socket.on("saveStatusPage", async (slug, config, imgDataUrl, publicGroupList, callback) => {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
checkSlug(config.slug);
|
|
|
|
|
|
|
|
|
|
checkLogin(socket);
|
|
|
|
|
apicache.clear();
|
|
|
|
|
|
|
|
|
@ -227,11 +229,7 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|
|
|
|
// 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");
|
|
|
|
|
}
|
|
|
|
|
checkSlug(slug);
|
|
|
|
|
|
|
|
|
|
let statusPage = R.dispense("status_page");
|
|
|
|
|
statusPage.slug = slug;
|
|
|
|
@ -302,3 +300,23 @@ module.exports.statusPageSocketHandler = (socket) => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check slug a-z, 0-9, - only
|
|
|
|
|
* Regex from: https://stackoverflow.com/questions/22454258/js-regex-string-validation-for-slug
|
|
|
|
|
*/
|
|
|
|
|
function checkSlug(slug) {
|
|
|
|
|
if (typeof slug !== "string") {
|
|
|
|
|
throw new Error("Slug must be string");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slug = slug.trim();
|
|
|
|
|
|
|
|
|
|
if (!slug) {
|
|
|
|
|
throw new Error("Slug cannot be empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!slug.match(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/)) {
|
|
|
|
|
throw new Error("Invalid Slug");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|