Made sure that more of the async usages are awaited (#4574)

pull/4541/head^2
Frank Elsinga 8 months ago committed by GitHub
parent a9a1cf1353
commit 0e3b3a9ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -130,7 +130,7 @@ function userAuthorizer(username, password, callback) {
* @param {express.Request} req Express request object * @param {express.Request} req Express request object
* @param {express.Response} res Express response object * @param {express.Response} res Express response object
* @param {express.NextFunction} next Next handler in chain * @param {express.NextFunction} next Next handler in chain
* @returns {void} * @returns {Promise<void>}
*/ */
exports.basicAuth = async function (req, res, next) { exports.basicAuth = async function (req, res, next) {
const middleware = basicAuth({ const middleware = basicAuth({
@ -153,7 +153,7 @@ exports.basicAuth = async function (req, res, next) {
* @param {express.Request} req Express request object * @param {express.Request} req Express request object
* @param {express.Response} res Express response object * @param {express.Response} res Express response object
* @param {express.NextFunction} next Next handler in chain * @param {express.NextFunction} next Next handler in chain
* @returns {void} * @returns {Promise<void>}
*/ */
exports.apiAuth = async function (req, res, next) { exports.apiAuth = async function (req, res, next) {
if (!await Settings.get("disableAuth")) { if (!await Settings.get("disableAuth")) {

@ -378,7 +378,7 @@ class Database {
/** /**
* Patch the database * Patch the database
* @returns {void} * @returns {Promise<void>}
*/ */
static async patch() { static async patch() {
// Still need to keep this for old versions of Uptime Kuma // Still need to keep this for old versions of Uptime Kuma

@ -65,7 +65,7 @@ class DockerHost {
/** /**
* Fetches the amount of containers on the Docker host * Fetches the amount of containers on the Docker host
* @param {object} dockerHost Docker host to check for * @param {object} dockerHost Docker host to check for
* @returns {number} Total amount of containers on the host * @returns {Promise<number>} Total amount of containers on the host
*/ */
static async testDockerHost(dockerHost) { static async testDockerHost(dockerHost) {
const options = { const options = {

@ -9,7 +9,7 @@ class Group extends BeanModel {
* @param {boolean} showTags Should the JSON include monitor tags * @param {boolean} showTags Should the JSON include monitor tags
* @param {boolean} certExpiry Should JSON include info about * @param {boolean} certExpiry Should JSON include info about
* certificate expiry? * certificate expiry?
* @returns {object} Object ready to parse * @returns {Promise<object>} Object ready to parse
*/ */
async toPublicJSON(showTags = false, certExpiry = false) { async toPublicJSON(showTags = false, certExpiry = false) {
let monitorBeanList = await this.getMonitorList(); let monitorBeanList = await this.getMonitorList();
@ -29,7 +29,7 @@ class Group extends BeanModel {
/** /**
* Get all monitors * Get all monitors
* @returns {Bean[]} List of monitors * @returns {Promise<Bean[]>} List of monitors
*/ */
async getMonitorList() { async getMonitorList() {
return R.convertToBeans("monitor", await R.getAll(` return R.convertToBeans("monitor", await R.getAll(`

@ -11,7 +11,7 @@ class Maintenance extends BeanModel {
/** /**
* Return an object that ready to parse to JSON for public * Return an object that ready to parse to JSON for public
* Only show necessary data to public * Only show necessary data to public
* @returns {object} Object ready to parse * @returns {Promise<object>} Object ready to parse
*/ */
async toPublicJSON() { async toPublicJSON() {
@ -98,7 +98,7 @@ class Maintenance extends BeanModel {
/** /**
* Return an object that ready to parse to JSON * Return an object that ready to parse to JSON
* @param {string} timezone If not specified, the timeRange will be in UTC * @param {string} timezone If not specified, the timeRange will be in UTC
* @returns {object} Object ready to parse * @returns {Promise<object>} Object ready to parse
*/ */
async toJSON(timezone = null) { async toJSON(timezone = null) {
return this.toPublicJSON(timezone); return this.toPublicJSON(timezone);
@ -143,7 +143,7 @@ class Maintenance extends BeanModel {
* Convert data from socket to bean * Convert data from socket to bean
* @param {Bean} bean Bean to fill in * @param {Bean} bean Bean to fill in
* @param {object} obj Data to fill bean with * @param {object} obj Data to fill bean with
* @returns {Bean} Filled bean * @returns {Promise<Bean>} Filled bean
*/ */
static async jsonToBean(bean, obj) { static async jsonToBean(bean, obj) {
if (obj.id) { if (obj.id) {
@ -189,9 +189,9 @@ class Maintenance extends BeanModel {
/** /**
* Throw error if cron is invalid * Throw error if cron is invalid
* @param {string|Date} cron Pattern or date * @param {string|Date} cron Pattern or date
* @returns {Promise<void>} * @returns {void}
*/ */
static async validateCron(cron) { static validateCron(cron) {
let job = new Cron(cron, () => {}); let job = new Cron(cron, () => {});
job.stop(); job.stop();
} }
@ -324,7 +324,7 @@ class Maintenance extends BeanModel {
/** /**
* Is this maintenance currently active * Is this maintenance currently active
* @returns {boolean} The maintenance is active? * @returns {Promise<boolean>} The maintenance is active?
*/ */
async isUnderMaintenance() { async isUnderMaintenance() {
return (await this.getStatus()) === "under-maintenance"; return (await this.getStatus()) === "under-maintenance";
@ -332,7 +332,7 @@ class Maintenance extends BeanModel {
/** /**
* Get the timezone of the maintenance * Get the timezone of the maintenance
* @returns {string} timezone * @returns {Promise<string>} timezone
*/ */
async getTimezone() { async getTimezone() {
if (!this.timezone || this.timezone === "SAME_AS_SERVER") { if (!this.timezone || this.timezone === "SAME_AS_SERVER") {
@ -343,7 +343,7 @@ class Maintenance extends BeanModel {
/** /**
* Get offset for timezone * Get offset for timezone
* @returns {string} offset * @returns {Promise<string>} offset
*/ */
async getTimezoneOffset() { async getTimezoneOffset() {
return dayjs.tz(dayjs(), await this.getTimezone()).format("Z"); return dayjs.tz(dayjs(), await this.getTimezone()).format("Z");
@ -351,7 +351,7 @@ class Maintenance extends BeanModel {
/** /**
* Get the current status of the maintenance * Get the current status of the maintenance
* @returns {string} Current status * @returns {Promise<string>} Current status
*/ */
async getStatus() { async getStatus() {
if (!this.active) { if (!this.active) {

@ -43,7 +43,7 @@ class Monitor extends BeanModel {
* @param {boolean} showTags Include tags in JSON * @param {boolean} showTags Include tags in JSON
* @param {boolean} certExpiry Include certificate expiry info in * @param {boolean} certExpiry Include certificate expiry info in
* JSON * JSON
* @returns {object} Object ready to parse * @returns {Promise<object>} Object ready to parse
*/ */
async toPublicJSON(showTags = false, certExpiry = false) { async toPublicJSON(showTags = false, certExpiry = false) {
let obj = { let obj = {
@ -74,7 +74,7 @@ class Monitor extends BeanModel {
* Return an object that ready to parse to JSON * Return an object that ready to parse to JSON
* @param {boolean} includeSensitiveData Include sensitive data in * @param {boolean} includeSensitiveData Include sensitive data in
* JSON * JSON
* @returns {object} Object ready to parse * @returns {Promise<object>} Object ready to parse
*/ */
async toJSON(includeSensitiveData = true) { async toJSON(includeSensitiveData = true) {
@ -947,7 +947,7 @@ class Monitor extends BeanModel {
log.debug("monitor", `[${this.name}] apicache clear`); log.debug("monitor", `[${this.name}] apicache clear`);
apicache.clear(); apicache.clear();
UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id); await UptimeKumaServer.getInstance().sendMaintenanceListByUserID(this.user_id);
} else { } else {
bean.important = false; bean.important = false;
@ -1377,7 +1377,7 @@ class Monitor extends BeanModel {
let notifyDays = await setting("tlsExpiryNotifyDays"); let notifyDays = await setting("tlsExpiryNotifyDays");
if (notifyDays == null || !Array.isArray(notifyDays)) { if (notifyDays == null || !Array.isArray(notifyDays)) {
// Reset Default // Reset Default
setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general"); await setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general");
notifyDays = [ 7, 14, 21 ]; notifyDays = [ 7, 14, 21 ];
} }

@ -18,7 +18,7 @@ class StatusPage extends BeanModel {
* @param {Response} response Response object * @param {Response} response Response object
* @param {string} indexHTML HTML to render * @param {string} indexHTML HTML to render
* @param {string} slug Status page slug * @param {string} slug Status page slug
* @returns {void} * @returns {Promise<void>}
*/ */
static async handleStatusPageResponse(response, indexHTML, slug) { static async handleStatusPageResponse(response, indexHTML, slug) {
// Handle url with trailing slash (http://localhost:3001/status/) // Handle url with trailing slash (http://localhost:3001/status/)
@ -42,7 +42,7 @@ class StatusPage extends BeanModel {
* SSR for status pages * SSR for status pages
* @param {string} indexHTML HTML page to render * @param {string} indexHTML HTML page to render
* @param {StatusPage} statusPage Status page populate HTML with * @param {StatusPage} statusPage Status page populate HTML with
* @returns {void} * @returns {Promise<string>} the rendered html
*/ */
static async renderHTML(indexHTML, statusPage) { static async renderHTML(indexHTML, statusPage) {
const $ = cheerio.load(indexHTML); const $ = cheerio.load(indexHTML);

@ -16,7 +16,7 @@ class TailscalePing extends MonitorType {
* @param {object} monitor The monitor object associated with the check. * @param {object} monitor The monitor object associated with the check.
* @param {object} heartbeat The heartbeat object to update. * @param {object} heartbeat The heartbeat object to update.
* @returns {Promise<void>} * @returns {Promise<void>}
* @throws Will throw an error if checking Tailscale ping encounters any error * @throws Error if checking Tailscale ping encounters any error
*/ */
async check(monitor, heartbeat) { async check(monitor, heartbeat) {
try { try {

@ -44,7 +44,7 @@ class AliyunSMS extends NotificationProvider {
* Send the SMS notification * Send the SMS notification
* @param {BeanModel} notification Notification details * @param {BeanModel} notification Notification details
* @param {string} msgbody Message template * @param {string} msgbody Message template
* @returns {boolean} True if successful else false * @returns {Promise<boolean>} True if successful else false
*/ */
async sendSms(notification, msgbody) { async sendSms(notification, msgbody) {
let params = { let params = {

@ -92,7 +92,7 @@ class Bark extends NotificationProvider {
* @param {string} title Message title * @param {string} title Message title
* @param {string} subtitle Message * @param {string} subtitle Message
* @param {string} endpoint Endpoint to send request to * @param {string} endpoint Endpoint to send request to
* @returns {string} Success message * @returns {Promise<string>} Success message
*/ */
async postNotification(notification, title, subtitle, endpoint) { async postNotification(notification, title, subtitle, endpoint) {
let result; let result;

@ -21,7 +21,7 @@ class DingDing extends NotificationProvider {
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
} }
}; };
if (this.sendToDingDing(notification, params)) { if (await this.sendToDingDing(notification, params)) {
return okMsg; return okMsg;
} }
} else { } else {
@ -31,7 +31,7 @@ class DingDing extends NotificationProvider {
content: msg content: msg
} }
}; };
if (this.sendToDingDing(notification, params)) { if (await this.sendToDingDing(notification, params)) {
return okMsg; return okMsg;
} }
} }
@ -44,7 +44,7 @@ class DingDing extends NotificationProvider {
* Send message to DingDing * Send message to DingDing
* @param {BeanModel} notification Notification to send * @param {BeanModel} notification Notification to send
* @param {object} params Parameters of message * @param {object} params Parameters of message
* @returns {boolean} True if successful else false * @returns {Promise<boolean>} True if successful else false
*/ */
async sendToDingDing(notification, params) { async sendToDingDing(notification, params) {
let timestamp = Date.now(); let timestamp = Date.now();

@ -107,7 +107,7 @@ class Nostr extends NotificationProvider {
/** /**
* Get public keys for recipients * Get public keys for recipients
* @param {string} recipients Newline delimited list of recipients * @param {string} recipients Newline delimited list of recipients
* @returns {nip19.DecodeResult[]} Public keys * @returns {Promise<nip19.DecodeResult[]>} Public keys
*/ */
async getPublicKeys(recipients) { async getPublicKeys(recipients) {
const recipientsList = recipients.split("\n"); const recipientsList = recipients.split("\n");

@ -294,7 +294,7 @@ let needSetup = false;
log.debug("server", "Adding socket handler"); log.debug("server", "Adding socket handler");
io.on("connection", async (socket) => { io.on("connection", async (socket) => {
sendInfo(socket, true); await sendInfo(socket, true);
if (needSetup) { if (needSetup) {
log.info("server", "Redirect to setup page"); log.info("server", "Redirect to setup page");
@ -326,7 +326,7 @@ let needSetup = false;
} }
log.debug("auth", "afterLogin"); log.debug("auth", "afterLogin");
afterLogin(socket, user); await afterLogin(socket, user);
log.debug("auth", "afterLogin ok"); log.debug("auth", "afterLogin ok");
log.info("auth", `Successfully logged in user ${decoded.username}. IP=${clientIP}`); log.info("auth", `Successfully logged in user ${decoded.username}. IP=${clientIP}`);
@ -382,7 +382,7 @@ let needSetup = false;
if (user) { if (user) {
if (user.twofa_status === 0) { if (user.twofa_status === 0) {
afterLogin(socket, user); await afterLogin(socket, user);
log.info("auth", `Successfully logged in user ${data.username}. IP=${clientIP}`); log.info("auth", `Successfully logged in user ${data.username}. IP=${clientIP}`);
@ -405,7 +405,7 @@ let needSetup = false;
let verify = notp.totp.verify(data.token, user.twofa_secret, twoFAVerifyOptions); let verify = notp.totp.verify(data.token, user.twofa_secret, twoFAVerifyOptions);
if (user.twofa_last_token !== data.token && verify) { if (user.twofa_last_token !== data.token && verify) {
afterLogin(socket, user); await afterLogin(socket, user);
await R.exec("UPDATE `user` SET twofa_last_token = ? WHERE id = ? ", [ await R.exec("UPDATE `user` SET twofa_last_token = ? WHERE id = ? ", [
data.token, data.token,
@ -1351,8 +1351,8 @@ let needSetup = false;
msgi18n: true, msgi18n: true,
}); });
sendInfo(socket); await sendInfo(socket);
server.sendMaintenanceList(socket); await server.sendMaintenanceList(socket);
} catch (e) { } catch (e) {
callback({ callback({
@ -1532,7 +1532,7 @@ let needSetup = false;
log.debug("auth", "check auto login"); log.debug("auth", "check auto login");
if (await setting("disableAuth")) { if (await setting("disableAuth")) {
log.info("auth", "Disabled Auth: auto login to admin"); log.info("auth", "Disabled Auth: auto login to admin");
afterLogin(socket, await R.findOne("user")); await afterLogin(socket, await R.findOne("user"));
socket.emit("autoLogin"); socket.emit("autoLogin");
} else { } else {
log.debug("auth", "need auth"); log.debug("auth", "need auth");
@ -1548,7 +1548,7 @@ let needSetup = false;
process.exit(1); process.exit(1);
}); });
server.start(); await server.start();
server.httpServer.listen(port, hostname, () => { server.httpServer.listen(port, hostname, () => {
if (hostname) { if (hostname) {
@ -1619,13 +1619,13 @@ async function afterLogin(socket, user) {
socket.join(user.id); socket.join(user.id);
let monitorList = await server.sendMonitorList(socket); let monitorList = await server.sendMonitorList(socket);
sendInfo(socket); await sendInfo(socket);
server.sendMaintenanceList(socket); await server.sendMaintenanceList(socket);
sendNotificationList(socket); await sendNotificationList(socket);
sendProxyList(socket); await sendProxyList(socket);
sendDockerHostList(socket); await sendDockerHostList(socket);
sendAPIKeyList(socket); await sendAPIKeyList(socket);
sendRemoteBrowserList(socket); await sendRemoteBrowserList(socket);
await sleep(500); await sleep(500);

@ -27,7 +27,7 @@ module.exports = (socket) => {
socket.on("shrinkDatabase", async (callback) => { socket.on("shrinkDatabase", async (callback) => {
try { try {
checkLogin(socket); checkLogin(socket);
Database.shrink(); await Database.shrink();
callback({ callback({
ok: true, ok: true,
}); });

@ -195,7 +195,7 @@ class UptimeKumaServer {
/** /**
* Send list of monitors to client * Send list of monitors to client
* @param {Socket} socket Socket to send list on * @param {Socket} socket Socket to send list on
* @returns {object} List of monitors * @returns {Promise<object>} List of monitors
*/ */
async sendMonitorList(socket) { async sendMonitorList(socket) {
let list = await this.getMonitorJSONList(socket.userID); let list = await this.getMonitorJSONList(socket.userID);
@ -227,7 +227,7 @@ class UptimeKumaServer {
/** /**
* Send maintenance list to client * Send maintenance list to client
* @param {Socket} socket Socket.io instance to send to * @param {Socket} socket Socket.io instance to send to
* @returns {object} Maintenance list * @returns {Promise<object>} Maintenance list
*/ */
async sendMaintenanceList(socket) { async sendMaintenanceList(socket) {
return await this.sendMaintenanceListByUserID(socket.userID); return await this.sendMaintenanceListByUserID(socket.userID);
@ -236,7 +236,7 @@ class UptimeKumaServer {
/** /**
* Send list of maintenances to user * Send list of maintenances to user
* @param {number} userID User to send list to * @param {number} userID User to send list to
* @returns {object} Maintenance list * @returns {Promise<object>} Maintenance list
*/ */
async sendMaintenanceListByUserID(userID) { async sendMaintenanceListByUserID(userID) {
let list = await this.getMaintenanceJSONList(userID); let list = await this.getMaintenanceJSONList(userID);

@ -288,7 +288,7 @@ export default {
/** /**
* Submit tag and monitorTag changes to server * Submit tag and monitorTag changes to server
* @returns {void} * @returns {Promise<void>}
*/ */
async submit() { async submit() {
this.processing = true; this.processing = true;
@ -348,7 +348,7 @@ export default {
/** /**
* Delete the editing tag from server * Delete the editing tag from server
* @returns {void} * @returns {Promise<void>}
*/ */
async deleteTag() { async deleteTag() {
this.processing = true; this.processing = true;

@ -384,7 +384,7 @@ export default {
/** /**
* Submit the form data * Submit the form data
* @param {number} monitorId ID of monitor this change affects * @param {number} monitorId ID of monitor this change affects
* @returns {void} * @returns {Promise<void>}
*/ */
async submit(monitorId) { async submit(monitorId) {
console.log(`Submitting tag changes for monitor ${monitorId}...`); console.log(`Submitting tag changes for monitor ${monitorId}...`);

@ -85,7 +85,7 @@ export default {
/** /**
* Get the telegram chat ID * Get the telegram chat ID
* @returns {void} * @returns {Promise<void>}
* @throws The chat ID could not be found * @throws The chat ID could not be found
*/ */
async autoGetTelegramChatID() { async autoGetTelegramChatID() {

@ -1470,7 +1470,7 @@ message HealthCheckResponse {
/** /**
* Submit the form data for processing * Submit the form data for processing
* @returns {void} * @returns {Promise<void>}
*/ */
async submit() { async submit() {
@ -1535,7 +1535,7 @@ message HealthCheckResponse {
// Start the new parent monitor after edit is done // Start the new parent monitor after edit is done
if (createdNewParent) { if (createdNewParent) {
this.startParentGroupMonitor(); await this.startParentGroupMonitor();
} }
this.processing = false; this.processing = false;
this.$root.getMonitorList(); this.$root.getMonitorList();

Loading…
Cancel
Save