mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 23:04:04 +00:00
62780001f7
* [empty commit] pull request for remote browser support * Remote browser: Added UI screens and DB tables. * Remote browser working * Fixing tests * Fix tests * Fix tests * fix tests * Test browser * revert init_db.js * Changed drop down to ActionSelect * Fix translations * added remote browsers toggle * revert changes package-lock * Fix bad english * Set default remote browser * Remote browsers Requested changes * fixed description.
84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
const { R } = require("redbean-node");
|
|
const { testRemoteBrowser } = require("./monitor-types/real-browser-monitor-type.js");
|
|
class RemoteBrowser {
|
|
|
|
/**
|
|
* Gets remote browser from ID
|
|
* @param {number} remoteBrowserID ID of the remote browser
|
|
* @param {number} userID ID of the user who created the remote browser
|
|
* @returns {Promise<Bean>} Remote Browser
|
|
*/
|
|
static async get(remoteBrowserID, userID) {
|
|
let bean = await R.findOne("remote_browser", " id = ? AND user_id = ? ", [ remoteBrowserID, userID ]);
|
|
|
|
if (!bean) {
|
|
throw new Error("Remote browser not found");
|
|
}
|
|
|
|
return bean;
|
|
}
|
|
|
|
/**
|
|
* Save a Remote Browser
|
|
* @param {object} remoteBrowser Remote Browser to save
|
|
* @param {?number} remoteBrowserID ID of the Remote Browser to update
|
|
* @param {number} userID ID of the user who adds the Remote Browser
|
|
* @returns {Promise<Bean>} Updated Remote Browser
|
|
*/
|
|
static async save(remoteBrowser, remoteBrowserID, userID) {
|
|
let bean;
|
|
|
|
if (remoteBrowserID) {
|
|
bean = await R.findOne("remote_browser", " id = ? AND user_id = ? ", [ remoteBrowserID, userID ]);
|
|
|
|
if (!bean) {
|
|
throw new Error("Remote browser not found");
|
|
}
|
|
|
|
} else {
|
|
bean = R.dispense("remote_browser");
|
|
}
|
|
|
|
bean.user_id = userID;
|
|
bean.name = remoteBrowser.name;
|
|
bean.url = remoteBrowser.url;
|
|
|
|
await R.store(bean);
|
|
|
|
return bean;
|
|
}
|
|
|
|
/**
|
|
* Delete a Remote Browser
|
|
* @param {number} remoteBrowserID ID of the Remote Browser to delete
|
|
* @param {number} userID ID of the user who created the Remote Browser
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async delete(remoteBrowserID, userID) {
|
|
let bean = await R.findOne("remote_browser", " id = ? AND user_id = ? ", [ remoteBrowserID, userID ]);
|
|
|
|
if (!bean) {
|
|
throw new Error("Remote Browser not found");
|
|
}
|
|
|
|
// Delete removed remote browser from monitors if exists
|
|
await R.exec("UPDATE monitor SET remote_browser = null WHERE remote_browser = ?", [ remoteBrowserID ]);
|
|
|
|
await R.trash(bean);
|
|
}
|
|
|
|
/**
|
|
* Tests the connection to Remote Browser
|
|
* @param {object} remoteBrowser Docker host to check for
|
|
* @returns {boolean} Returns if connection worked
|
|
*/
|
|
static async test(remoteBrowser) {
|
|
const testResult = await testRemoteBrowser(remoteBrowser.id, remoteBrowser.user_id);
|
|
return testResult;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
RemoteBrowser,
|
|
};
|