|
|
@ -208,12 +208,16 @@ class UptimeKumaServer {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Update Monitor into list
|
|
|
|
* Update Monitor into list
|
|
|
|
* @param {Socket} socket Socket to send list on
|
|
|
|
* @param {Socket} socket Socket to send list on
|
|
|
|
* @param {number} monitorID update or deleted monitor id
|
|
|
|
* @param {number | number[]} monitorIDs update or deleted monitor ids
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async sendUpdateMonitorIntoList(socket, monitorID) {
|
|
|
|
async sendUpdateMonitorsIntoList(socket, monitorIDs) {
|
|
|
|
let list = await this.getMonitorJSONList(socket.userID, monitorID);
|
|
|
|
if (!Array.isArray(monitorIDs)) {
|
|
|
|
this.io.to(socket.userID).emit("updateMonitorIntoList", list);
|
|
|
|
monitorIDs = [ monitorIDs ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let list = await this.getMonitorJSONList(socket.userID, monitorIDs);
|
|
|
|
|
|
|
|
this.io.to(socket.userID).emit("updateMonitorsIntoList", list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -229,19 +233,19 @@ class UptimeKumaServer {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get a list of monitors for the given user.
|
|
|
|
* Get a list of monitors for the given user.
|
|
|
|
* @param {string} userID - The ID of the user to get monitors for.
|
|
|
|
* @param {string} userID - The ID of the user to get monitors for.
|
|
|
|
* @param {number} monitorID - The ID of monitor for.
|
|
|
|
* @param {number[]} monitorIDs - The IDs of monitors for.
|
|
|
|
* @returns {Promise<object>} A promise that resolves to an object with monitor IDs as keys and monitor objects as values.
|
|
|
|
* @returns {Promise<object>} A promise that resolves to an object with monitor IDs as keys and monitor objects as values.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Generated by Trelent
|
|
|
|
* Generated by Trelent
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async getMonitorJSONList(userID, monitorID = null) {
|
|
|
|
async getMonitorJSONList(userID, monitorIDs = null) {
|
|
|
|
|
|
|
|
|
|
|
|
let query = " user_id = ? ";
|
|
|
|
let query = " user_id = ? ";
|
|
|
|
let queryParams = [ userID ];
|
|
|
|
let queryParams = [ userID ];
|
|
|
|
|
|
|
|
|
|
|
|
if (monitorID) {
|
|
|
|
if (monitorIDs) {
|
|
|
|
query += "AND id = ? ";
|
|
|
|
query += `AND id IN (${monitorIDs.map((_) => "?").join(",")}) `;
|
|
|
|
queryParams.push(monitorID);
|
|
|
|
queryParams.push(...monitorIDs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let monitorList = await R.find("monitor", query + "ORDER BY weight DESC, name", queryParams);
|
|
|
|
let monitorList = await R.find("monitor", query + "ORDER BY weight DESC, name", queryParams);
|
|
|
|