Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

Added the ntfy stream widget

Al Salehb69a1a5a5b0c
diff --git a/docs/widgets.md b/docs/widgets.md
index d774b4cc..f9df1a63 100644
--- a/docs/widgets.md
+++ b/docs/widgets.md
@@ -66,6 +66,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a
- [Nextcloud System](#nextcloud-system)
- [Nextcloud Stats](#nextcloud-stats)
- [Nextcloud PHP OPcache](#nextcloud-php-opcache-stats)
+ - [Ntfy stream](#ntfy-stream)
- [Proxmox lists](#proxmox-lists)
- [Sabnzbd](#sabnzbd)
- [Gluetun VPN Info](#gluetun-vpn-info)
@@ -2441,6 +2442,39 @@ Shows statistics about PHP OPcache performance on your Nextcloud server.
- **Host**: Self-Hosted (see [Nextcloud](https://nextcloud.com))
- **Privacy**: _See [Nextcloud Privacy Policy](https://nextcloud.com/privacy)_
+---
+
+### ntfy stream
+
+Subscribes to topics on a **private** [ntfy](https://docs.ntfy.sh/) server, and shows **new messages** as they arrive.
+
+#### Options
+
+**Field** | **Type** | **Required** | **Description**
+--- | --- | --- | ---
+**`server_url`** | `string` | Required | The server url
+**`topic`** | `string` | Required | A topic, or a comma separated list of topics
+**`auth`** | `string` | optional | An [auth string](https://docs.ntfy.sh/subscribe/api/#authentication). ⚠️ This is sent as query parameter.
+**`title`** | `string` | optional | A title for the widget.
+
+#### Example
+
+```yaml
+- type: ntfy-stream
+ useProxy: false
+ options:
+ title: NTFY stream
+ server_url: https://myntfy.server.tld
+ topic: alert,warning,mytopic
+```
+
+#### Info
+
+- **CORS**: Disabled
+- **Auth**: Optional
+- **Price**: Free
+- **Host**: [Self-hosted](https://https://docs.ntfy.sh/install/)
+- **Privacy**: [ntfy Privacy Policy](https://docs.ntfy.sh/privacy/)
---
diff --git a/src/components/Widgets/NtfyStream.vue b/src/components/Widgets/NtfyStream.vue
new file mode 100644
index 00000000..6ffe8e34
--- /dev/null
+++ b/src/components/Widgets/NtfyStream.vue
@@ -0,0 +1,89 @@
+<template>
+ <div class="ntfy-stream">
+ <div class="ntfy-stream-widget-title" v-if="title">
+ {{ title }}
+ </div>
+ <div v-for="(item, key) in messages" :key="key" class="ntfy-stream-row">
+ <div v-if="item.title" class="ntfy-stream-title">
+ {{ item.title }}
+ </div>
+ <div v-if="item.message" class="ntfy-stream-content">
+ {{ item.message }}
+ </div>
+ </div>
+ </div>
+</template>
+
+<script>
+import WidgetMixin from '@/mixins/WidgetMixin';
+
+export default {
+ mixins: [WidgetMixin],
+ components: {},
+ data() {
+ return {
+ messages: [],
+ };
+ },
+ computed: {
+ serverUrl() {
+ if (!this.options.server_url) this.error('The server URL is required.');
+ return this.parseAsEnvVar(this.options.server_url) || '';
+ },
+ topic() {
+ if (!this.options.topic) this.error('The topic is required.');
+ return this.parseAsEnvVar(this.options.topic) || '';
+ },
+ auth() {
+ return this.parseAsEnvVar(this.options.auth) || '';
+ },
+ title() {
+ return this.parseAsEnvVar(this.options.title) || '';
+ },
+
+ },
+ methods: {
+ fetchData() {
+ // @see https://docs.ntfy.sh/subscribe/api/#subscribe-as-sse-stream
+ this.finishLoading();
+ let url = `${this.serverUrl}/${this.topic}/sse`;
+ if (this.auth !== '') {
+ url = `${url}?auth=${this.auth}`;
+ }
+ const eventSource = new EventSource(url);
+ eventSource.onmessage = (e) => {
+ this.messages.unshift(JSON.parse(e.data));
+ };
+ },
+ },
+};
+
+</script>
+
+<style scoped lang="scss">
+
+.ntfy-stream {
+ .ntfy-stream-widget-title {
+ outline: 2px solid transparent;
+ border: 1px solid var(--outline-color);
+ border-radius: var(--curve-factor);
+ box-shadow: var(--item-shadow);
+ color: var(--item-text-color);
+ margin: .5rem;
+ padding: 0.3rem;
+ background: var(--item-background);
+ text-align: center;
+
+ }
+ .ntfy-stream-row {
+ color: var(--widget-text-color);
+ font-size: 1.1rem;
+ .ntfy-stream-title {
+ font-weight: bold;
+ }
+ &:not(:last-child) {
+ border-bottom: 1px dashed var(--widget-text-color);
+ }
+ }
+}
+</style>
diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue
index 74c58a6b..e6e8326a 100644
--- a/src/components/Widgets/WidgetBase.vue
+++ b/src/components/Widgets/WidgetBase.vue
@@ -114,6 +114,7 @@ const COMPAT = {
'nextcloud-system': 'NextcloudSystem',
'nextcloud-user': 'NextcloudUser',
'nextcloud-user-status': 'NextcloudUserStatus',
+ 'ntfy-stream': 'NtfyStream',
'pi-hole-stats': 'PiHoleStats',
'pi-hole-stats-v6': 'PiHoleStatsV6',
'pi-hole-top-queries': 'PiHoleTopQueries',