Added JSDoc to ESLint (#3529)

* Added JSDoc to eslint rules

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>

* Fixed JSDoc eslint errors

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>

* Update the check-linters workflow to Node.js 20

---------

Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
This commit is contained in:
Matthew Nickson
2023-08-11 09:46:41 +02:00
committed by GitHub
parent da4f4e3d76
commit 8a92054c2b
153 changed files with 1505 additions and 574 deletions

View File

@@ -20,7 +20,7 @@ const path = require("path");
*/
class UptimeKumaServer {
/**
*
* Current server instance
* @type {UptimeKumaServer}
*/
static instance = null;
@@ -49,7 +49,6 @@ class UptimeKumaServer {
indexHTML = "";
/**
*
* @type {{}}
*/
static monitorTypeList = {
@@ -62,6 +61,12 @@ class UptimeKumaServer {
*/
jwtSecret = null;
/**
* Get the current instance of the server if it exists, otherwise
* create a new instance.
* @param {object} args Arguments to pass to instance constructor
* @returns {UptimeKumaServer} Server instance
*/
static getInstance(args) {
if (UptimeKumaServer.instance == null) {
UptimeKumaServer.instance = new UptimeKumaServer(args);
@@ -69,6 +74,9 @@ class UptimeKumaServer {
return UptimeKumaServer.instance;
}
/**
* @param {object} args Arguments to initialise server with
*/
constructor(args) {
// SSL
const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined;
@@ -106,7 +114,10 @@ class UptimeKumaServer {
this.io = new Server(this.httpServer);
}
/** Initialise app after the database has been set up */
/**
* Initialise app after the database has been set up
* @returns {Promise<void>}
*/
async initAfterDatabaseReady() {
// Static
this.app.use("/screenshots", express.static(Database.screenshotDir));
@@ -123,8 +134,8 @@ class UptimeKumaServer {
/**
* Send list of monitors to client
* @param {Socket} socket
* @returns {Object} List of monitors
* @param {Socket} socket Socket to send list on
* @returns {object} List of monitors
*/
async sendMonitorList(socket) {
let list = await this.getMonitorJSONList(socket.userID);
@@ -135,7 +146,7 @@ class UptimeKumaServer {
/**
* Get a list of monitors for the given user.
* @param {string} userID - The ID of the user to get 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
*/
@@ -156,7 +167,7 @@ class UptimeKumaServer {
/**
* Send maintenance list to client
* @param {Socket} socket Socket.io instance to send to
* @returns {Object}
* @returns {object} Maintenance list
*/
async sendMaintenanceList(socket) {
return await this.sendMaintenanceListByUserID(socket.userID);
@@ -164,8 +175,8 @@ class UptimeKumaServer {
/**
* Send list of maintenances to user
* @param {number} userID
* @returns {Object}
* @param {number} userID User to send list to
* @returns {object} Maintenance list
*/
async sendMaintenanceListByUserID(userID) {
let list = await this.getMaintenanceJSONList(userID);
@@ -176,7 +187,7 @@ class UptimeKumaServer {
/**
* Get a list of maintenances for the given user.
* @param {string} userID - The ID of the user to get maintenances for.
* @returns {Promise<Object>} A promise that resolves to an object with maintenance IDs as keys and maintenances objects as values.
* @returns {Promise<object>} A promise that resolves to an object with maintenance IDs as keys and maintenances objects as values.
*/
async getMaintenanceJSONList(userID) {
let result = {};
@@ -188,7 +199,7 @@ class UptimeKumaServer {
/**
* Load maintenance list and run
* @param userID
* @param {any} userID Unused
* @returns {Promise<void>}
*/
async loadMaintenanceList(userID) {
@@ -202,6 +213,11 @@ class UptimeKumaServer {
}
}
/**
* Retrieve a specific maintenance
* @param {number} maintenanceID ID of maintenance to retrieve
* @returns {(object|null)} Maintenance if it exists
*/
getMaintenance(maintenanceID) {
if (this.maintenanceList[maintenanceID]) {
return this.maintenanceList[maintenanceID];
@@ -213,6 +229,7 @@ class UptimeKumaServer {
* Write error to log file
* @param {any} error The error to write
* @param {boolean} outputToConsole Should the error also be output to console?
* @returns {void}
*/
static errorLog(error, outputToConsole = true) {
const errorLogStream = fs.createWriteStream(path.join(Database.dataDir, "/error.log"), {
@@ -237,8 +254,8 @@ class UptimeKumaServer {
/**
* Get the IP of the client connected to the socket
* @param {Socket} socket
* @returns {string}
* @param {Socket} socket Socket to query
* @returns {string} IP of client
*/
async getClientIP(socket) {
let clientIP = socket.client.conn.remoteAddress;
@@ -262,7 +279,7 @@ class UptimeKumaServer {
* Attempt to get the current server timezone
* If this fails, fall back to environment variables and then make a
* guess.
* @returns {Promise<string>}
* @returns {Promise<string>} Current timezone
*/
async getTimezone() {
// From process.env.TZ
@@ -307,7 +324,7 @@ class UptimeKumaServer {
/**
* Get the current offset
* @returns {string}
* @returns {string} Time offset
*/
getTimezoneOffset() {
return dayjs().format("Z");
@@ -315,7 +332,9 @@ class UptimeKumaServer {
/**
* Throw an error if the timezone is invalid
* @param timezone
* @param {string} timezone Timezone to test
* @returns {void}
* @throws The timezone is invalid
*/
checkTimezone(timezone) {
try {
@@ -327,7 +346,8 @@ class UptimeKumaServer {
/**
* Set the current server timezone and environment variables
* @param {string} timezone
* @param {string} timezone Timezone to set
* @returns {Promise<void>}
*/
async setTimezone(timezone) {
this.checkTimezone(timezone);
@@ -355,6 +375,7 @@ class UptimeKumaServer {
/**
* Start all system services (e.g. nscd)
* For now, only used in Docker
* @returns {void}
*/
startServices() {
if (process.env.UPTIME_KUMA_IS_CONTAINER) {
@@ -369,6 +390,7 @@ class UptimeKumaServer {
/**
* Stop all system services
* @returns {void}
*/
stopServices() {
if (process.env.UPTIME_KUMA_IS_CONTAINER) {