From 1041812645d199f54cb8c22c115ef2bd267ccaa7 Mon Sep 17 00:00:00 2001 From: DoidoYo Date: Mon, 16 Dec 2024 14:21:39 -0500 Subject: [PATCH] Lint cleanup and comments --- config/vite.config.js | 12 ++--- package.json | 2 + server/notification-providers/Webpush.js | 25 +++++---- server/server.js | 8 +-- src/components/notifications/Webpush.vue | 69 +++++++++++++++--------- src/serviceWorker.ts | 14 ++--- 6 files changed, 73 insertions(+), 57 deletions(-) diff --git a/config/vite.config.js b/config/vite.config.js index cb9accd51..b36591052 100644 --- a/config/vite.config.js +++ b/config/vite.config.js @@ -3,7 +3,7 @@ import { defineConfig } from "vite"; import visualizer from "rollup-plugin-visualizer"; import viteCompression from "vite-plugin-compression"; import VueDevTools from "vite-plugin-vue-devtools"; -import { VitePWA } from 'vite-plugin-pwa'; +import { VitePWA } from "vite-plugin-pwa"; const postCssScss = require("postcss-scss"); const postcssRTLCSS = require("postcss-rtlcss"); @@ -35,13 +35,9 @@ export default defineConfig({ VueDevTools(), VitePWA({ registerType: null, - srcDir: 'src', - filename: 'serviceWorker.ts', - strategies: 'injectManifest', - devOptions: { - enabled: true, - type: 'module' - }, + srcDir: "src", + filename: "serviceWorker.ts", + strategies: "injectManifest", }), ], css: { diff --git a/package.json b/package.json index f8aa982f2..457e1b021 100644 --- a/package.json +++ b/package.json @@ -145,6 +145,7 @@ }, "devDependencies": { "@actions/github": "~5.1.1", + "@eslint/js": "^9.17.0", "@fortawesome/fontawesome-svg-core": "~1.2.36", "@fortawesome/free-regular-svg-icons": "~5.15.4", "@fortawesome/free-solid-svg-icons": "~5.15.4", @@ -177,6 +178,7 @@ "eslint-plugin-vue": "~8.7.1", "favico.js": "~0.3.10", "get-port-please": "^3.1.1", + "globals": "^15.13.0", "node-ssh": "~13.1.0", "postcss-html": "~1.5.0", "postcss-rtlcss": "~3.7.2", diff --git a/server/notification-providers/Webpush.js b/server/notification-providers/Webpush.js index b7d6b65d4..9d7b4d770 100644 --- a/server/notification-providers/Webpush.js +++ b/server/notification-providers/Webpush.js @@ -1,7 +1,6 @@ const NotificationProvider = require("./notification-provider"); -const axios = require("axios"); const { UP } = require("../../src/util"); -const web_push = require('web-push'); +const webpush = require("web-push"); const { setting } = require("../util-server"); class Webpush extends NotificationProvider { @@ -18,31 +17,31 @@ class Webpush extends NotificationProvider { const publicVapidKey = await setting("webpushPublicVapidKey"); const privateVapidKey = await setting("webpushPrivateVapidKey"); // Set Vapid keys in web-push helper lib - web_push.setVapidDetails("https://github.com/louislam/uptime-kuma", publicVapidKey, privateVapidKey); - + webpush.setVapidDetails("https://github.com/louislam/uptime-kuma", publicVapidKey, privateVapidKey); + if (heartbeatJSON === null && monitorJSON === null) { // Test message const data = JSON.stringify({ - title: "TEST", + title: "TEST", body: "Test Alert - " + msg }); //send push notification using web-push lib - await web_push.sendNotification(notification.subscription, data); - + await webpush.sendNotification(notification.subscription, data); + return okMsg; } const title = `Monitor ${heartbeatJSON["status"] === UP ? "UP" : "DOWN"}`; const down = "❌ " + monitorJSON["name"] + " is DOWN ❌"; - const up = "✅ " + monitorJSON["name"] + " is UP ✅";; + const up = "✅ " + monitorJSON["name"] + " is UP ✅"; - const data = JSON.stringify({ - title: title, + const data = JSON.stringify({ + title: title, body: `${heartbeatJSON["status"] === UP ? up : down}` }); //send push notification using web-push lib - await web_push.sendNotification(notification.subscription, data); - + await webpush.sendNotification(notification.subscription, data); + return okMsg; } catch (error) { this.throwGeneralAxiosError(error); @@ -50,4 +49,4 @@ class Webpush extends NotificationProvider { } } -module.exports = Webpush; \ No newline at end of file +module.exports = Webpush; diff --git a/server/server.js b/server/server.js index ff4a5f2da..d8fcb2569 100644 --- a/server/server.js +++ b/server/server.js @@ -97,7 +97,7 @@ log.debug("server", "Importing Notification"); const { Notification } = require("./notification"); Notification.init(); log.debug("server", "Importing Web-Push"); -const web_push = require('web-push'); +const webpush = require("web-push"); log.debug("server", "Importing Database"); const Database = require("./database"); @@ -1493,14 +1493,14 @@ let needSetup = false; socket.on("getWebpushVapidPublicKey", async (callback) => { try { let publicVapidKey = await Settings.get("webpushPublicVapidKey"); - + if (!publicVapidKey) { console.debug("Generating new VAPID keys"); - const vapidKeys = web_push.generateVAPIDKeys(); + const vapidKeys = webpush.generateVAPIDKeys(); await Settings.set("webpushPublicVapidKey", vapidKeys.publicKey); await Settings.set("webpushPrivateVapidKey", vapidKeys.privateKey); - + publicVapidKey = vapidKeys.publicKey; } diff --git a/src/components/notifications/Webpush.vue b/src/components/notifications/Webpush.vue index 7b3d6c5a4..5caa9627a 100644 --- a/src/components/notifications/Webpush.vue +++ b/src/components/notifications/Webpush.vue @@ -1,16 +1,14 @@