main #8
3 changed files with 39 additions and 115 deletions
|
@ -3,6 +3,7 @@
|
||||||
package observer.nelle.nelleObserverBackend.plugins
|
package observer.nelle.nelleObserverBackend.plugins
|
||||||
|
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.request.forms.*
|
import io.ktor.client.request.forms.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
|
@ -32,5 +33,20 @@ suspend fun makePost(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a ntfy message
|
// Send a ntfy message
|
||||||
suspend fun ntfyMsg() {
|
suspend fun ntfyMsg(
|
||||||
|
client: HttpClient,
|
||||||
|
title: String,
|
||||||
|
message: String,
|
||||||
|
attach: String,
|
||||||
|
click: String,
|
||||||
|
) {
|
||||||
|
val message: HttpResponse =
|
||||||
|
client.post("https://ntfy.ouroboros.group/pushy") {
|
||||||
|
headers {
|
||||||
|
append("Title", title)
|
||||||
|
append("Attach", title)
|
||||||
|
append("Click", title)
|
||||||
|
}
|
||||||
|
setBody(message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,13 @@ fun Application.configureRouting(client: HttpClient) {
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
val formParameters = call.receiveParameters()
|
val formParameters = call.receiveParameters()
|
||||||
|
val title = formParameters["Title"].toString()
|
||||||
|
val message = formParameters["Message"].toString()
|
||||||
|
val attach = formParameters["Attach"].toString()
|
||||||
|
val click = formParameters["Click"].toString()
|
||||||
|
call.response.status(HttpStatusCode(201, "Received..."))
|
||||||
|
call.respondText("Received:: Title: $title, Message: $message, Attachment: $attach, Click: $click")
|
||||||
|
ntfyMsg(client, title, message, attach, click)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// i deeply apologize for the horrors within...
|
// i deeply apologize for the horrors within...
|
||||||
const ntfyEndpoint = "https://ntfy.ouroboros.group/pushy";
|
const ntfyEndpoint = "https://nelle.observer/api/ntfy";
|
||||||
|
|
||||||
// text fields and buttons
|
// text fields and buttons
|
||||||
const ntfyMessage = document.getElementById("ntfy-message");
|
const ntfyMessage = document.getElementById("ntfy-message");
|
||||||
|
@ -34,7 +34,7 @@ const clickPFX = "click-action: ";
|
||||||
|
|
||||||
// Ctrl + Enter to send
|
// Ctrl + Enter to send
|
||||||
document.addEventListener("keydown", (event) => {
|
document.addEventListener("keydown", (event) => {
|
||||||
if (event.ctrlKey && event.key == "Enter") {
|
if (event.ctrlKey && event.key === "Enter") {
|
||||||
ntfyClick()
|
ntfyClick()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -173,118 +173,25 @@ async function ntfyClick() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only message
|
|
||||||
function sendNone(endpoint, message) {
|
|
||||||
const r = new XMLHttpRequest();
|
|
||||||
r.open("POST", endpoint, true);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.send(message);
|
|
||||||
}
|
|
||||||
// send all
|
// send all
|
||||||
function sendAll(endpoint, title, message, attachment, click) {
|
function sendAll(endpoint, title, message, attachment, click) {
|
||||||
const r = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
r.open("POST", endpoint, true);
|
const formData = new FormData();
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.setRequestHeader("Title", title);
|
formData.append("Title", title);
|
||||||
r.setRequestHeader("Attach", attachment);
|
formData.append("Message", message);
|
||||||
r.setRequestHeader("Click", click);
|
formData.append("Attach", attachment);
|
||||||
r.send(message);
|
formData.append("Click", click);
|
||||||
}
|
|
||||||
// send title only
|
// Submit the data via fetch()
|
||||||
function sendTitle(endpoint, title, message) {
|
fetch(endpoint, {
|
||||||
const r = new XMLHttpRequest();
|
method: "POST",
|
||||||
r.open("POST", endpoint, true);
|
body: formData,
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
});
|
||||||
r.setRequestHeader("Title", title);
|
|
||||||
r.send(message);
|
|
||||||
}
|
|
||||||
// send attachment only
|
|
||||||
function sendAttach(endpoint, message, attachment) {
|
|
||||||
const r = new XMLHttpRequest();
|
|
||||||
r.open("POST", endpoint, true);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.setRequestHeader("Attach", attachment);
|
|
||||||
r.send(message);
|
|
||||||
}
|
|
||||||
// send click only
|
|
||||||
function sendClick(endpoint, message, click) {
|
|
||||||
const r = new XMLHttpRequest();
|
|
||||||
r.open("POST", endpoint, true);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.setRequestHeader("Click", click);
|
|
||||||
r.send(message);
|
|
||||||
}
|
|
||||||
// send Title & Attachment
|
|
||||||
function sendTitleAttach(endpoint, title, message, attachment) {
|
|
||||||
const r = new XMLHttpRequest();
|
|
||||||
r.open("POST", endpoint, true);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.setRequestHeader("Title", title);
|
|
||||||
r.setRequestHeader("Attach", attachment);
|
|
||||||
r.send(message);
|
|
||||||
}
|
|
||||||
// send Title & Click
|
|
||||||
function sendTitleClick(endpoint, title, message, click) {
|
|
||||||
const r = new XMLHttpRequest();
|
|
||||||
r.open("POST", endpoint, true);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.setRequestHeader("Title", title);
|
|
||||||
r.setRequestHeader("Click", click);
|
|
||||||
r.send(message);
|
|
||||||
}
|
|
||||||
// send Attach & Click
|
|
||||||
function sendAttachClick(endpoint, message, attachment, click) {
|
|
||||||
const r = new XMLHttpRequest();
|
|
||||||
r.open("POST", endpoint, true);
|
|
||||||
r.setRequestHeader("Content-Type", "text/plain");
|
|
||||||
r.setRequestHeader("Attach", attachment);
|
|
||||||
r.setRequestHeader("Click", click);
|
|
||||||
r.send(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send notification
|
// send notification
|
||||||
function sendNotification() {
|
function sendNotification() {
|
||||||
// title only
|
|
||||||
if (titleEnabled && !attachmentEnabled && !clickEnabled) {
|
|
||||||
sendTitle(ntfyTitle.value, ntfyMessage.value);
|
|
||||||
ntfyTitle.value = "";
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
}
|
|
||||||
// attachment only
|
|
||||||
if (!titleEnabled && attachmentEnabled && !clickEnabled) {
|
|
||||||
sendAttach(ntfyEndpoint, ntfyMessage.value, ntfyAttach.value);
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
ntfyAttach.value = "";
|
|
||||||
}
|
|
||||||
// click only
|
|
||||||
if (!titleEnabled && !attachmentEnabled && clickEnabled) {
|
|
||||||
sendClick(ntfyEndpoint, ntfyMessage.value, ntfyClickAction.value);
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
ntfyClickAction.value = "";
|
|
||||||
}
|
|
||||||
// title & attachment
|
|
||||||
if (titleEnabled && attachmentEnabled && !clickEnabled) {
|
|
||||||
sendTitleAttach(ntfyEndpoint, ntfyTitle.value, ntfyMessage.value, ntfyAttach.value);
|
|
||||||
ntfyTitle.value = "";
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
ntfyAttach.value = "";
|
|
||||||
}
|
|
||||||
// title & click
|
|
||||||
if (titleEnabled && !attachmentEnabled && clickEnabled) {
|
|
||||||
sendTitleClick(ntfyEndpoint, ntfyTitle.value, ntfyMessage.value, ntfyClickAction.value);
|
|
||||||
ntfyTitle.value = "";
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
ntfyClickAction.value = "";
|
|
||||||
}
|
|
||||||
// attachment & click
|
|
||||||
if (!titleEnabled && attachmentEnabled && clickEnabled) {
|
|
||||||
sendAttachClick(ntfyEndpoint, ntfyMessage.value, ntfyAttach.value, ntfyClickAction.value);
|
|
||||||
ntfyAttach.value = "";
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
ntfyClickAction.value = "";
|
|
||||||
}
|
|
||||||
// all three
|
|
||||||
if (titleEnabled && attachmentEnabled && clickEnabled) {
|
|
||||||
sendAll(
|
sendAll(
|
||||||
ntfyEndpoint,
|
ntfyEndpoint,
|
||||||
ntfyTitle.value,
|
ntfyTitle.value,
|
||||||
|
@ -297,9 +204,3 @@ function sendNotification() {
|
||||||
ntfyAttach.value = "";
|
ntfyAttach.value = "";
|
||||||
ntfyClickAction.value = "";
|
ntfyClickAction.value = "";
|
||||||
}
|
}
|
||||||
// none
|
|
||||||
else {
|
|
||||||
sendNone(ntfyEndpoint, ntfyMessage.value);
|
|
||||||
ntfyMessage.value = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue