diff --git a/astro/public/scripts/ntfy.js b/astro/public/scripts/ntfy.js index 948a1fc..b6c1edb 100644 --- a/astro/public/scripts/ntfy.js +++ b/astro/public/scripts/ntfy.js @@ -1,5 +1,11 @@ -const ntfyInput = document.getElementById("ntfy-input"); -const ntfyButton = document.getElementById("ntfy-send"); +const ntfyMessage = document.getElementById("ntfy-message"); +const ntfyTitle = document.getElementById("ntfy-title"); +const ntfyTags = document.getElementById("ntfy-tags"); +const ntfyAttach = document.getElementById("ntfy-attach"); +const ntfyClickAction = document.getElementById("ntfy-click"); +const ntfyButton = document.getElementById("ntfy-button"); + +const msgPFX = "message: " // Random placeholder @@ -7,56 +13,64 @@ function getPlaceholder() { placeholderSelector = Math.floor(Math.random() * 8) + 1; switch (placeholderSelector) { case 1: - ntfyInput.placeholder = "hi nelle! (。>﹏<。)"; + ntfyMessage.placeholder = `${msgPFX}hi nelle! (。>﹏<。)`; break; case 2: - ntfyInput.placeholder = "(╹◡╹)凸"; + ntfyMessage.placeholder = `${msgPFX}(╹◡╹)凸`; break; case 3: - ntfyInput.placeholder = "Confession of sin: I dont like SciAdv"; + ntfyMessage.placeholder = `${msgPFX}Confession of sin: I dont like SciAdv`; break; case 4: - ntfyInput.placeholder = "Knock Knock..."; + ntfyMessage.placeholder = `${msgPFX}Knock Knock...`; break; case 5: - ntfyInput.placeholder = "El. Psy. Kongroo."; + ntfyMessage.placeholder = `${msgPFX}El. Psy. Kongroo.`; break; case 6: - ntfyInput.placeholder = "the organization is after you."; + ntfyMessage.placeholder = `${msgPFX}the organization is after you.`; break; case 7: - ntfyInput.placeholder = - "you wouldnt happen to know where an IBN5100 is, would you?"; + ntfyMessage.placeholder = + `${msgPFX}you wouldnt happen to know where an IBN5100 is, would you?`; break; case 8: - ntfyInput.placeholder = - "if you had to choose, between: bacon, unlimited bacon, but no games. or. games. unlimited games, but no games. which would you pick?"; + ntfyMessage.placeholder = + `${msgPFX}if you had to choose, between: bacon, unlimited bacon, but no games. or. games. unlimited games, but no games. which would you pick?`; break; case 9: - ntfyInput.placeholder = "time travel?"; + ntfyMessage.placeholder = `${msgPFX}time travel?`; break; default: - ntfyInput.placeholder = "type some words and hit send"; + ntfyMessage.placeholder = `${msgPFX}type some words and hit send`; } } // send function -function send(message) { +function send(message, title, tags, attachment, click) { const r = new XMLHttpRequest(); r.open("POST", "https://ntfy.ouroboros.group/beep", true); r.setRequestHeader("Content-Type", "text/plain"); + r.setRequestHeader("Title", title); + r.setRequestHeader("Tags", tags); + r.setRequestHeader("Attach", attachment); + r.setRequestHeader("Click", click); r.send(message); } // send notification function sendNotification() { - send(ntfyInput.value); - ntfyInput.value = ""; + send(ntfyTitle.value, ntfyMessage.value, ntfyTags.value, ntfyAttach.value, ntfyClickAction.value); + ntfyTitle.value = ""; + ntfyTags.value = ""; + ntfyAttach.value = ""; + ntfyClickAction.value = ""; + ntfyMessage.value = ""; } // on send button click async function ntfyClick() { - if (!ntfyInput.value.replace(/\s/g, "").length) { + if (!ntfyMessage.value.replace(/\s/g, "").length) { ntfyButton.innerHTML = "ಠ﹏ಠ"; setTimeout(() => { ntfyButton.innerHTML = "Send"; diff --git a/astro/src/components/main-page/silly-widgets.astro b/astro/src/components/main-page/silly-widgets.astro index ffc0315..ba7637e 100644 --- a/astro/src/components/main-page/silly-widgets.astro +++ b/astro/src/components/main-page/silly-widgets.astro @@ -20,15 +20,21 @@

-
- - -
+ + + + + + +
+ +
if it doesnt seem to be working, or you have javascript disabled,
you can POST to https://ntfy.ouroboros.group/beep.
\ No newline at end of file diff --git a/ktor/build.gradle.kts b/ktor/build.gradle.kts index 2afc796..11ce999 100644 --- a/ktor/build.gradle.kts +++ b/ktor/build.gradle.kts @@ -35,6 +35,11 @@ dependencies { implementation("io.ktor:ktor-server-netty-jvm") implementation("ch.qos.logback:logback-classic:$logback_version") implementation("io.ktor:ktor-server-config-yaml") + implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.0") + implementation("io.ktor:ktor-client-core:$ktor_version") + implementation("io.ktor:ktor-client-cio:$ktor_version") + implementation("io.ktor:ktor-client-auth:$ktor_version") + implementation("io.ktor:ktor-client-content-negotiation:$ktor_version") } kotlin { diff --git a/ktor/src/main/kotlin/Application.kt b/ktor/src/main/kotlin/Application.kt index d14d349..09797f4 100644 --- a/ktor/src/main/kotlin/Application.kt +++ b/ktor/src/main/kotlin/Application.kt @@ -1,11 +1,19 @@ package observer.nelle +import io.ktor.client.* +import io.ktor.client.engine.cio.* +import io.ktor.client.plugins.auth.* +import io.ktor.client.plugins.auth.providers.* import io.ktor.server.application.* +import kotlinx.coroutines.runBlocking +import observer.nelle.api.sendMessage import observer.nelle.plugins.configureRouting import observer.nelle.plugins.configureSecurity import observer.nelle.plugins.configureTemplating fun main(args: Array) { + + io.ktor.server.netty.EngineMain.main(args) } diff --git a/ktor/src/main/kotlin/api/ntfy.kt b/ktor/src/main/kotlin/api/ntfy.kt new file mode 100644 index 0000000..717d434 --- /dev/null +++ b/ktor/src/main/kotlin/api/ntfy.kt @@ -0,0 +1,23 @@ +package observer.nelle.api + +import io.ktor.client.* +import io.ktor.client.call.* +import io.ktor.client.request.* +import io.ktor.client.request.forms.* +import io.ktor.client.statement.* +import io.ktor.http.* + +suspend fun sendMessage(client: HttpClient, title: String, tags: String, attachment: String, click: String, messageText: String) { + // Fetch posts from the Home timeline, amount of posts configurable + val sendMessage: HttpResponse = client.post("https://ntfy.ouroboros.group/beep") { + headers { + append(HttpHeaders.ContentType, "text/html") + append("Title", title) + append("Tags", tags) + append("Attach", attachment) + append("Click", click) + } + setBody(messageText) + } + println(sendMessage.status) +} \ No newline at end of file diff --git a/ktor/src/main/kotlin/plugins/Routing.kt b/ktor/src/main/kotlin/plugins/Routing.kt index 62bfa57..be637b3 100644 --- a/ktor/src/main/kotlin/plugins/Routing.kt +++ b/ktor/src/main/kotlin/plugins/Routing.kt @@ -21,6 +21,6 @@ fun Application.configureRouting() {/* routing { // Set a static resource path 'resources/content/' to be served - staticFiles("/", File("static")) + staticResources("/", "static") } }