From 524cf7c6077cf5a499709b789d95ea075add3b1e Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 31 Mar 2023 21:34:05 +0800 Subject: [PATCH] WIP --- server/model/maintenance.js | 3 +-- server/model/status_page.js | 25 ++++++++++--------------- src/pages/StatusPage.vue | 6 +++++- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/server/model/maintenance.js b/server/model/maintenance.js index c92f8189d..189a513aa 100644 --- a/server/model/maintenance.js +++ b/server/model/maintenance.js @@ -1,6 +1,5 @@ const { BeanModel } = require("redbean-node/dist/bean-model"); -const { parseTimeObject, parseTimeFromTimeObject, utcToLocal, localToUTC, log } = require("../../src/util"); -const { timeObjectToUTC, timeObjectToLocal } = require("../util-server"); +const { parseTimeObject, parseTimeFromTimeObject, log } = require("../../src/util"); const { R } = require("redbean-node"); const dayjs = require("dayjs"); const Cron = require("croner"); diff --git a/server/model/status_page.js b/server/model/status_page.js index 84af99e88..65b77367e 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -3,7 +3,6 @@ const { R } = require("redbean-node"); const cheerio = require("cheerio"); const { UptimeKumaServer } = require("../uptime-kuma-server"); const jsesc = require("jsesc"); -const Maintenance = require("./maintenance"); const googleAnalytics = require("../google-analytics"); class StatusPage extends BeanModel { @@ -290,21 +289,17 @@ class StatusPage extends BeanModel { try { const publicMaintenanceList = []; - let activeCondition = Maintenance.getActiveMaintenanceSQLCondition(); - let maintenanceBeanList = R.convertToBeans("maintenance", await R.getAll(` - SELECT DISTINCT maintenance.* - FROM maintenance - JOIN maintenance_status_page - ON maintenance_status_page.maintenance_id = maintenance.id - AND maintenance_status_page.status_page_id = ? - LEFT JOIN maintenance_timeslot - ON maintenance_timeslot.maintenance_id = maintenance.id - WHERE ${activeCondition} - ORDER BY maintenance.end_date - `, [ statusPageId ])); + let maintenanceIDList = await R.getCol(` + SELECT DISTINCT maintenance_id + FROM maintenance_status_page + WHERE status_page_id = ? + `, [ statusPageId ]); - for (const bean of maintenanceBeanList) { - publicMaintenanceList.push(await bean.toPublicJSON()); + for (const maintenanceID of maintenanceIDList) { + let maintenance = UptimeKumaServer.getInstance().getMaintenance(maintenanceID); + if (maintenance && await maintenance.isUnderMaintenance()) { + publicMaintenanceList.push(await maintenance.toPublicJSON()); + } } return publicMaintenanceList; diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index b202be305..defa458e6 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -923,7 +923,11 @@ export default { * @returns {string} Sanitized HTML */ maintenanceHTML(description) { - return DOMPurify.sanitize(marked(description)); + if (description) { + return DOMPurify.sanitize(marked(description)); + } else { + return ""; + } }, }