2022-03-10 13:34:30 +00:00
|
|
|
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,
|
2022-03-16 06:14:47 +00:00
|
|
|
description: this.description,
|
2022-03-17 08:42:26 +00:00
|
|
|
icon: this.getIcon(),
|
2022-03-10 13:34:30 +00:00
|
|
|
theme: this.theme,
|
|
|
|
published: !!this.published,
|
|
|
|
showTags: !!this.show_tags,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async toPublicJSON() {
|
|
|
|
return {
|
|
|
|
slug: this.slug,
|
|
|
|
title: this.title,
|
2022-03-16 06:14:47 +00:00
|
|
|
description: this.description,
|
2022-03-17 08:42:26 +00:00
|
|
|
icon: this.getIcon(),
|
2022-03-10 13:34:30 +00:00
|
|
|
theme: this.theme,
|
|
|
|
published: !!this.published,
|
|
|
|
showTags: !!this.show_tags,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-16 07:38:10 +00:00
|
|
|
static async slugToID(slug) {
|
|
|
|
return await R.getCell("SELECT id FROM status_page WHERE slug = ? ", [
|
|
|
|
slug
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:42:26 +00:00
|
|
|
getIcon() {
|
|
|
|
if (!this.icon) {
|
|
|
|
return "/icon.svg";
|
|
|
|
} else {
|
|
|
|
return this.icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 13:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = StatusPage;
|