summaryrefslogtreecommitdiffstats
path: root/server/socket-handlers/proxy-socket-handler.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/socket-handlers/proxy-socket-handler.js')
-rw-r--r--server/socket-handlers/proxy-socket-handler.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/server/socket-handlers/proxy-socket-handler.js b/server/socket-handlers/proxy-socket-handler.js
new file mode 100644
index 0000000..9e80371
--- /dev/null
+++ b/server/socket-handlers/proxy-socket-handler.js
@@ -0,0 +1,61 @@
+const { checkLogin } = require("../util-server");
+const { Proxy } = require("../proxy");
+const { sendProxyList } = require("../client");
+const { UptimeKumaServer } = require("../uptime-kuma-server");
+const server = UptimeKumaServer.getInstance();
+
+/**
+ * Handlers for proxy
+ * @param {Socket} socket Socket.io instance
+ * @returns {void}
+ */
+module.exports.proxySocketHandler = (socket) => {
+ socket.on("addProxy", async (proxy, proxyID, callback) => {
+ try {
+ checkLogin(socket);
+
+ const proxyBean = await Proxy.save(proxy, proxyID, socket.userID);
+ await sendProxyList(socket);
+
+ if (proxy.applyExisting) {
+ await Proxy.reloadProxy();
+ await server.sendMonitorList(socket);
+ }
+
+ callback({
+ ok: true,
+ msg: "Saved.",
+ msgi18n: true,
+ id: proxyBean.id,
+ });
+
+ } catch (e) {
+ callback({
+ ok: false,
+ msg: e.message,
+ });
+ }
+ });
+
+ socket.on("deleteProxy", async (proxyID, callback) => {
+ try {
+ checkLogin(socket);
+
+ await Proxy.delete(proxyID, socket.userID);
+ await sendProxyList(socket);
+ await Proxy.reloadProxy();
+
+ callback({
+ ok: true,
+ msg: "successDeleted",
+ msgi18n: true,
+ });
+
+ } catch (e) {
+ callback({
+ ok: false,
+ msg: e.message,
+ });
+ }
+ });
+};