mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 12:00:35 +03:00
fbfa5a33ed
This should fully implement #1221 by modifying the API and adding two new properties to the result. The `sendUrl` property denotes if the URL is sent and `url` is included when required. Client side checks have been implemented in order to only show a link when the URL is vaugely correct. I.e not "" or "https://". This prevents the link from being included if the monitor type is not HTTP without having to publicly expose the monitor type. The exposure of the URL is configuarable for each monitor on each status page by clicking on the link icon. Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const { BeanModel } = require("redbean-node/dist/bean-model");
|
|
const { R } = require("redbean-node");
|
|
|
|
class Group extends BeanModel {
|
|
|
|
/**
|
|
* Return an object that ready to parse to JSON for public
|
|
* Only show necessary data to public
|
|
* @param {boolean} [showTags=false] Should the JSON include monitor tags
|
|
* @returns {Object}
|
|
*/
|
|
async toPublicJSON(showTags = false) {
|
|
let monitorBeanList = await this.getMonitorList();
|
|
let monitorList = [];
|
|
|
|
for (let bean of monitorBeanList) {
|
|
monitorList.push(await bean.toPublicJSON(showTags));
|
|
}
|
|
|
|
return {
|
|
id: this.id,
|
|
name: this.name,
|
|
weight: this.weight,
|
|
monitorList,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get all monitors
|
|
* @returns {Bean[]}
|
|
*/
|
|
async getMonitorList() {
|
|
return R.convertToBeans("monitor", await R.getAll(`
|
|
SELECT monitor.*, monitor_group.send_url FROM monitor, monitor_group
|
|
WHERE monitor.id = monitor_group.monitor_id
|
|
AND group_id = ?
|
|
ORDER BY monitor_group.weight
|
|
`, [
|
|
this.id,
|
|
]));
|
|
}
|
|
}
|
|
|
|
module.exports = Group;
|