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

This commit is contained in:
Frank Elsinga 2024-03-15 15:02:55 +01:00 committed by GitHub
parent a9a1cf1353
commit 0e3b3a9ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 53 additions and 53 deletions

View File

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

View File

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

View File

@ -65,7 +65,7 @@ class DockerHost {
/**
* Fetches the amount of containers on the Docker host
* @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) {
const options = {

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ class TailscalePing extends MonitorType {
* @param {object} monitor The monitor object associated with the check.
* @param {object} heartbeat The heartbeat object to update.
* @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) {
try {

View File

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

View File

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

View File

@ -21,7 +21,7 @@ class DingDing extends NotificationProvider {
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;
}
} else {
@ -31,7 +31,7 @@ class DingDing extends NotificationProvider {
content: msg
}
};
if (this.sendToDingDing(notification, params)) {
if (await this.sendToDingDing(notification, params)) {
return okMsg;
}
}
@ -44,7 +44,7 @@ class DingDing extends NotificationProvider {
* Send message to DingDing
* @param {BeanModel} notification Notification to send
* @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) {
let timestamp = Date.now();

View File

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

View File

@ -294,7 +294,7 @@ let needSetup = false;
log.debug("server", "Adding socket handler");
io.on("connection", async (socket) => {
sendInfo(socket, true);
await sendInfo(socket, true);
if (needSetup) {
log.info("server", "Redirect to setup page");
@ -326,7 +326,7 @@ let needSetup = false;
}
log.debug("auth", "afterLogin");
afterLogin(socket, user);
await afterLogin(socket, user);
log.debug("auth", "afterLogin ok");
log.info("auth", `Successfully logged in user ${decoded.username}. IP=${clientIP}`);
@ -382,7 +382,7 @@ let needSetup = false;
if (user) {
if (user.twofa_status === 0) {
afterLogin(socket, user);
await afterLogin(socket, user);
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);
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 = ? ", [
data.token,
@ -1351,8 +1351,8 @@ let needSetup = false;
msgi18n: true,
});
sendInfo(socket);
server.sendMaintenanceList(socket);
await sendInfo(socket);
await server.sendMaintenanceList(socket);
} catch (e) {
callback({
@ -1532,7 +1532,7 @@ let needSetup = false;
log.debug("auth", "check auto login");
if (await setting("disableAuth")) {
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");
} else {
log.debug("auth", "need auth");
@ -1548,7 +1548,7 @@ let needSetup = false;
process.exit(1);
});
server.start();
await server.start();
server.httpServer.listen(port, hostname, () => {
if (hostname) {
@ -1619,13 +1619,13 @@ async function afterLogin(socket, user) {
socket.join(user.id);
let monitorList = await server.sendMonitorList(socket);
sendInfo(socket);
server.sendMaintenanceList(socket);
sendNotificationList(socket);
sendProxyList(socket);
sendDockerHostList(socket);
sendAPIKeyList(socket);
sendRemoteBrowserList(socket);
await sendInfo(socket);
await server.sendMaintenanceList(socket);
await sendNotificationList(socket);
await sendProxyList(socket);
await sendDockerHostList(socket);
await sendAPIKeyList(socket);
await sendRemoteBrowserList(socket);
await sleep(500);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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