Skip to content

Commit

Permalink
Merge pull request louislam#2744 from bobby-ore/add-lunasea-user-id
Browse files Browse the repository at this point in the history
Add ability to use User ID for LunaSea notifications
  • Loading branch information
louislam authored Mar 4, 2023
2 parents 44077b3 + b21c2ad commit 8d1847c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
13 changes: 9 additions & 4 deletions server/notification-providers/lunasea.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ class LunaSea extends NotificationProvider {

async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
let lunaseadevice = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice;
let lunaseaurl = "";
if (notification.lunaseaTarget === "user") {
lunaseaurl = "https://notify.lunasea.app/v1/custom/user/" + notification.lunaseaUserID;
} else {
lunaseaurl = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice;
}

try {
if (heartbeatJSON == null) {
let testdata = {
"title": "Uptime Kuma Alert",
"body": msg,
};
await axios.post(lunaseadevice, testdata);
await axios.post(lunaseaurl, testdata);
return okMsg;
}

Expand All @@ -25,7 +30,7 @@ class LunaSea extends NotificationProvider {
"title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
};
await axios.post(lunaseadevice, downdata);
await axios.post(lunaseaurl, downdata);
return okMsg;
}

Expand All @@ -34,7 +39,7 @@ class LunaSea extends NotificationProvider {
"title": "UptimeKuma Alert: " + monitorJSON["name"],
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
};
await axios.post(lunaseadevice, updata);
await axios.post(lunaseaurl, updata);
return okMsg;
}

Expand Down
30 changes: 27 additions & 3 deletions src/components/notifications/LunaSea.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<template>
<div class="mb-3">
<label for="lunasea-device" class="form-label">{{ $t("LunaSea Device ID") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="lunasea-device" v-model="$parent.notification.lunaseaDevice" type="text" class="form-control" required>
<label for="lunasea-notification-target" class="form-label">{{ $t("Target") }}<span style="color: red;"><sup>*</sup></span></label>
<div class="form-text">
<p><span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}</p>
<p>
<select id="lunasea-notification-target" v-model="$parent.notification.lunaseaTarget" class="form-select" required>
<option value="device">Device</option>
<option value="user">User</option>
</select>
</p>
</div>
<div v-if="$parent.notification.lunaseaTarget === 'device'">
<label for="lunasea-device" class="form-label">{{ $t("Device ID") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="lunasea-device" v-model="$parent.notification.lunaseaDevice" type="text" class="form-control">
</div>
<div v-if="$parent.notification.lunaseaTarget === 'user'">
<label for="lunasea-device" class="form-label">{{ $t("User ID") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="lunasea-device" v-model="$parent.notification.lunaseaUserID" type="text" class="form-control">
</div>
</div>
</template>

<script lang="ts">
export default {
mounted() {
if (typeof this.$parent.notification.lunaseaTarget === "undefined") {
this.$parent.notification.lunaseaTarget = "device";
}
}
};
</script>

0 comments on commit 8d1847c

Please # to comment.