Skip to content

Commit

Permalink
Merge pull request #679 from gnmyt/features/pushover-integration
Browse files Browse the repository at this point in the history
⏩ Pushover Integration hinzugefügt
  • Loading branch information
gnmyt authored May 19, 2024
2 parents 2d13a6c + dbf2cab commit 5d8a83a
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 11 deletions.
13 changes: 13 additions & 0 deletions client/public/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@
"finished_message_placeholder": "%ping% ms, %download% Mbps, %upload% Mbps"
}
},
"pushover": {
"title": "Pushover",
"fields": {
"token": "App token",
"user_key": "User key",
"error_message": "Error message",
"error_message_placeholder": "Error: %error%",
"send_failed": "Send error messages",
"send_finished": "Send finished messages",
"finished_message": "Finished message",
"finished_message_placeholder": "%ping% ms, %download% Mbps, %upload% Mbps"
}
},
"healthChecks": {
"title": "HealthChecks",
"fields": {
Expand Down
2 changes: 2 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import {NodeProvider} from "@/common/contexts/Node";
import { library } from '@fortawesome/fontawesome-svg-core';
import { fas } from '@fortawesome/free-solid-svg-icons';
import { fab } from "@fortawesome/free-brands-svg-icons";
import {PushOverIcon} from "@/common/assets/icons/pushover";

library.add(fas, fab);
library.add(PushOverIcon);

const MainContent = () => {
const [view] = useContext(ViewContext);
Expand Down
8 changes: 8 additions & 0 deletions client/src/common/assets/icons/pushover.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions client/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import i18n from "i18next";
import {initReactI18next} from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
import EnglishFlag from "@/common/languages/en.webp";
import GermanFlag from "@/common/languages/de.webp";
import BulgarianFlag from "@/common/languages/bg.webp";
import ChineseFlag from "@/common/languages/zh.webp";
import DutchFlag from "@/common/languages/nl.webp";
import FranceFlag from "@/common/languages/fr.webp";
import ItalianFlag from "@/common/languages/it.webp";
import PortugueseBrazilFlag from "@/common/languages/br.webp";
import RussianFlag from "@/common/languages/ru.webp";
import SpanishFlag from "@/common/languages/es.webp";
import TurkishFlag from "@/common/languages/tr.webp";
import EnglishFlag from "@/common/assets/languages/en.webp";
import GermanFlag from "@/common/assets/languages/de.webp";
import BulgarianFlag from "@/common/assets/languages/bg.webp";
import ChineseFlag from "@/common/assets/languages/zh.webp";
import DutchFlag from "@/common/assets/languages/nl.webp";
import FranceFlag from "@/common/assets/languages/fr.webp";
import ItalianFlag from "@/common/assets/languages/it.webp";
import PortugueseBrazilFlag from "@/common/assets/languages/br.webp";
import RussianFlag from "@/common/assets/languages/ru.webp";
import SpanishFlag from "@/common/assets/languages/es.webp";
import TurkishFlag from "@/common/assets/languages/tr.webp";

if (localStorage.getItem('language') === null)
localStorage.setItem('language', navigator.language.split('-')[0]);
Expand Down
47 changes: 47 additions & 0 deletions server/integrations/pushover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const axios = require("axios");
const {replaceVariables} = require("../util/helpers");

const BASE_URL = "https://api.pushover.net/1";

const defaults = {
finished: "A speedtest is finished:\nPing: %ping% ms\nUpload: %upload% Mbps\nDownload: %download% Mbps",
failed: "A speedtest has failed. Reason: %error%"
}

module.exports = (registerEvent) => {
registerEvent('testFinished', async (integration, data, triggerActivity) => {
if (!integration.data.send_finished) return;

const message = replaceVariables(integration.data.finished_message || defaults.finished, data);

axios.post(`${BASE_URL}/messages.json`, {
token: integration.data.token,
user: integration.data.user_key, message
}).then(() => triggerActivity())
.catch(() => triggerActivity(true));
});

registerEvent('testFailed', async (integration, error, triggerActivity) => {
if (!integration.data.send_failed) return;

const message = replaceVariables(integration.data.error_message || defaults.failed, {error});

axios.post(`${BASE_URL}/messages.json`, {
token: integration.data.token,
user: integration.data.user_key, message
}).then(() => triggerActivity())
.catch(() => triggerActivity(true));
});

return {
icon: "fa-solid fa-pushover",
fields: [
{name: "token", type: "text", required: true, regex: /^[a-z0-9]{30}$/},
{name: "user_key", type: "text", required: true, regex: /^[a-z0-9]{30}$/},
{name: "send_finished", type: "boolean", required: false},
{name: "finished_message", type: "textarea", required: false},
{name: "send_failed", type: "boolean", required: false},
{name: "error_message", type: "textarea", required: false}
]
};
}

0 comments on commit 5d8a83a

Please sign in to comment.