diff --git a/.github/workflows/format-code.yml b/.github/workflows/format-code.yml index eb5a091..9ec30f4 100644 --- a/.github/workflows/format-code.yml +++ b/.github/workflows/format-code.yml @@ -11,6 +11,10 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} - name: Format Code with Prettier - run: npx prettier --write "**/*.js" --tab-width + uses: creyD/prettier_action@v4.3 + with: + prettier_options: --write --tab-width 4 **/*.{js,md} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index c5f8114..a563db6 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -8,9 +8,9 @@ jobs: steps: - uses: actions/stale@v4.1.1 with: - days-before-issue-stale: 360 - days-before-issue-close: 30 + days-before-issue-stale: 180 + days-before-issue-close: 7 stale-issue-message: "This issue is being marked as stale due to no recent activity" - days-before-pr-stale: 180 + days-before-pr-stale: 90 days-before-pr-close: 30 close-pr-message: "This PR is being marked as stale due to no recent activity" diff --git a/MMM-pihole-stats.js b/MMM-pihole-stats.js index 560836a..dd5e9ea 100644 --- a/MMM-pihole-stats.js +++ b/MMM-pihole-stats.js @@ -23,11 +23,11 @@ Module.register("MMM-pihole-stats", { initialLoadDelay: 0, }, - formatInt (n) { + formatInt(n) { return n.toLocaleString(); }, - formatFloat (n) { + formatFloat(n) { if (this.config.floatingPoints) { const x = 10 ** this.config.floatingPoints; return Math.round(parseFloat(n) * x) / x; @@ -36,7 +36,7 @@ Module.register("MMM-pihole-stats", { }, // Define start sequence. - start () { + start() { Log.info(`Starting module: ${this.name}`); this.domains_being_blocked = null; @@ -50,7 +50,7 @@ Module.register("MMM-pihole-stats", { }, // Override dom generator. - getDom () { + getDom() { const wrapper = document.createElement("div"); if (!this.loaded) { @@ -61,8 +61,7 @@ Module.register("MMM-pihole-stats", { const header = document.createElement("div"); header.className = "small bright"; - header.innerHTML - = `${this.formatInt(this.ads_blocked_today)} + header.innerHTML = `${this.formatInt(this.ads_blocked_today)} ads blocked today. ( ${this.formatFloat(this.ads_percentage_today)} %)`; @@ -112,8 +111,7 @@ Module.register("MMM-pihole-stats", { const footer = document.createElement("div"); footer.className = "xsmall"; - footer.innerHTML - = `${this.formatInt(this.dns_queries_today)} + footer.innerHTML = `${this.formatInt(this.dns_queries_today)} DNS queries, ${this.formatInt(this.domains_being_blocked)} domains blacklisted.`; @@ -122,16 +120,16 @@ Module.register("MMM-pihole-stats", { return wrapper; }, - updateStats () { + updateStats() { Log.info(`${this.name}: Getting data`); this.sendSocketNotification("GET_PIHOLE", { - config: this.config + config: this.config, }); }, // Handle node helper response - socketNotificationReceived (notification, payload) { + socketNotificationReceived(notification, payload) { if (notification === "PIHOLE_DATA") { this.processSummary(payload); this.loaded = true; @@ -142,7 +140,7 @@ Module.register("MMM-pihole-stats", { this.updateDom(this.config.animationSpeed); }, - scheduleUpdate (delay) { + scheduleUpdate(delay) { let nextLoad = this.config.updateInterval; if (typeof delay !== "undefined" && delay >= 0) { nextLoad = delay; @@ -155,7 +153,7 @@ Module.register("MMM-pihole-stats", { }, nextLoad); }, - processSummary (data) { + processSummary(data) { if (!data) { // Did not receive usable new data. return; @@ -167,7 +165,7 @@ Module.register("MMM-pihole-stats", { this.ads_percentage_today = data.ads_percentage_today || "0.0"; }, - processSources (data) { + processSources(data) { if (!data) { // Did not receive usable new data. return; diff --git a/README.md b/README.md index 13a3c4a..303d0ce 100755 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ Without `config.showSources` enabled: ## Dependencies -- [MagicMirror²](https://github.com/MagicMirrorOrg/MagicMirror) -- [Pi-hole](https://pi-hole.net) +- [MagicMirror²](https://github.com/MagicMirrorOrg/MagicMirror) +- [Pi-hole](https://pi-hole.net) ## Installation 1. Clone this repo into `~/MagicMirror/modules` directory. - `git clone https://github.com/sheyabernstein/MMM-pihole-stats` + `git clone https://github.com/sheyabernstein/MMM-pihole-stats` 2. Obtain an API token from your PiHole installation by navigating to [http://pi.hole/admin/settings.php?tab=api](http://pi.hole/admin/settings.php?tab=api) and clicking `Show API token` 3. Configure your `~/MagicMirror/config/config.js` @@ -40,7 +40,7 @@ Here is an example entry for `config.js`: ## Configuration Options | **Option** | **Default** | **Description** | -|--------------------------|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------| +| ------------------------ | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | | `apiURL` | `http://pi.hole/admin/api.php` | URL to Pi-hole admin, including HTTP protocol | | `apiToken` | | API Token from Pi-hole (required for `showSources`) | | `showSources` | `true` | Show request sources (clients) | @@ -52,6 +52,6 @@ Here is an example entry for `config.js`: ## Notes -- Feb 28, 2024 update: This module needs no external packages anymore. -- Feb 27, 2024 update: This module now requires `npm install` when installing. -- Sep 27, 2020 update: Configuring the Pi-hole server to allow CORS is no longer needed. +- Feb 28, 2024 update: This module needs no external packages anymore. +- Feb 27, 2024 update: This module now requires `npm install` when installing. +- Sep 27, 2020 update: Configuring the Pi-hole server to allow CORS is no longer needed. diff --git a/node_helper.js b/node_helper.js index 8f49883..f2c4625 100644 --- a/node_helper.js +++ b/node_helper.js @@ -2,11 +2,11 @@ const Log = require("logger"); const NodeHelper = require("node_helper"); module.exports = NodeHelper.create({ - start () { + start() { Log.info(`Starting node_helper for module [${this.name}]`); }, - socketNotificationReceived (notification, payload) { + socketNotificationReceived(notification, payload) { if (notification === "GET_PIHOLE") { const config = payload.config; @@ -20,19 +20,21 @@ module.exports = NodeHelper.create({ if (config.showSources && config.sourcesCount > 0) { if (config.showSources && !config.apiToken) { - Log.error(`${this.name}: Can't load sources because the apiKey is not set.`); + Log.error( + `${this.name}: Can't load sources because the apiKey is not set.`, + ); } else { this.getPiholeData( config, { getQuerySources: config.sourcesCount }, - "PIHOLE_SOURCES" + "PIHOLE_SOURCES", ); } } } }, - isValidURL (url) { + isValidURL(url) { try { new URL(url); return true; @@ -41,7 +43,7 @@ module.exports = NodeHelper.create({ } }, - buildURL (config, params) { + buildURL(config, params) { params = params || {}; if (config.apiToken && !params.hasOwnProperty("auth")) { @@ -54,7 +56,7 @@ module.exports = NodeHelper.create({ return url.toString(); }, - async getPiholeData (config, params, notification) { + async getPiholeData(config, params, notification) { const self = this, url = self.buildURL(config, params), headers = { Referer: url }; @@ -66,14 +68,20 @@ module.exports = NodeHelper.create({ if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } - if (response.headers.get('content-type').includes('application/json')) { + if ( + response.headers + .get("content-type") + .includes("application/json") + ) { const data = await response.json(); self.sendSocketNotification(notification, data); } else { - throw new Error(`Expected JSON but received ${response.headers.get('content-type')}`); + throw new Error( + `Expected JSON but received ${response.headers.get("content-type")}`, + ); } } catch (error) { Log.error(self.name + " ERROR:", error); } }, -}); \ No newline at end of file +});