From 94e0d5da923dc32997cd07a766a052069c69d1d4 Mon Sep 17 00:00:00 2001 From: nelle Date: Sat, 28 Dec 2024 09:09:39 -0700 Subject: [PATCH] as a test --- backend/.idea/ktlint-plugin.xml | 3 + .../nelle/nelleObserverBackend/Application.kt | 1 - .../nelleObserverBackend/plugins/Routing.kt | 242 +++++++++--------- 3 files changed, 124 insertions(+), 122 deletions(-) diff --git a/backend/.idea/ktlint-plugin.xml b/backend/.idea/ktlint-plugin.xml index bee5678..2657bf7 100644 --- a/backend/.idea/ktlint-plugin.xml +++ b/backend/.idea/ktlint-plugin.xml @@ -3,4 +3,7 @@ DISTRACT_FREE + + DISTRACT_FREE + \ No newline at end of file diff --git a/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/Application.kt b/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/Application.kt index bf85700..104e2af 100644 --- a/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/Application.kt +++ b/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/Application.kt @@ -16,7 +16,6 @@ import io.ktor.server.plugins.ratelimit.* import kotlinx.coroutines.runBlocking import observer.nelle.nelleObserverBackend.helpers.checkCreate import observer.nelle.nelleObserverBackend.plugins.configureRouting -import kotlin.time.Duration.Companion.minutes val logger = KotlinLogging.logger("nelle.observer API") diff --git a/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/plugins/Routing.kt b/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/plugins/Routing.kt index 8b70ea5..79025d8 100644 --- a/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/plugins/Routing.kt +++ b/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/plugins/Routing.kt @@ -19,7 +19,7 @@ import kotlin.time.Duration.Companion.minutes var meowTimedOut = true var beepTimedOut = true -var kaomojiTimedOut = true +var kaomojiTimedOut = false // function to facilitate the timeout for meows fun meowTimer() { @@ -67,136 +67,136 @@ fun kaomojiTimer() { // this is where the fun REST comes in! fun Application.configureRouting(client: HttpClient) { routing { - // route all paths of */api - route("/api") { - // meow - route("/meow") { - // get meow timeout - get { + // route all paths of */api + route("/api") { + // meow + route("/meow") { + // get meow timeout + get { + if (meowTimedOut) { + call.response.status(HttpStatusCode(423, "Timed Out")) + call.respondText("Timed Out") + logger.debug { "timed out for some time" } + } else { + call.response.status(HttpStatusCode(100, "Not Timed Out")) + call.respondText("Not Timed Out") + logger.debug { "not timed out" } + } + } + // meow button + post { + if (call.receiveText() == superSecret) { + call.response.status(HttpStatusCode(201, "Meow Posted")) + makePost(client, getMeow(), instanceDomain) + call.respondText("meowed with bypass") + logger.info { "meowed with bypass" } + } else { if (meowTimedOut) { call.response.status(HttpStatusCode(423, "Timed Out")) - call.respondText("Timed Out") - logger.debug { "timed out for some time" } + call.respondText("still sleeping... timed out for some time") + logger.info { "failed meow" } } else { - call.response.status(HttpStatusCode(100, "Not Timed Out")) - call.respondText("Not Timed Out") - logger.debug { "not timed out" } - } - } - // meow button - post { - if (call.receiveText() == superSecret) { call.response.status(HttpStatusCode(201, "Meow Posted")) makePost(client, getMeow(), instanceDomain) - call.respondText("meowed with bypass") - logger.info { "meowed with bypass" } - } else { - if (meowTimedOut) { - call.response.status(HttpStatusCode(423, "Timed Out")) - call.respondText("still sleeping... timed out for some time") - logger.info { "failed meow" } - } else { - call.response.status(HttpStatusCode(201, "Meow Posted")) - makePost(client, getMeow(), instanceDomain) - meowTimer() - call.respondText("meow' sent! timed out for some time") - logger.info { "meowed" } - } + meowTimer() + call.respondText("meow' sent! timed out for some time") + logger.info { "meowed" } } } } - - // beep - route("/beep") { - // get beep timeout - get { - if (beepTimedOut) { - call.response.status(HttpStatusCode(423, "Timed Out")) - call.respondText("Timed Out") - logger.debug { "timed out" } - } else { - call.response.status(HttpStatusCode(100, "Not Timed Out")) - call.respondText("Not Timed Out") - logger.debug { "not timed out" } - } - } - // beep button - post { - if (call.receiveText() == superSecret) { - call.response.status(HttpStatusCode(201, "Meow Posted")) - makePost(client, getBeep(), instanceDomain) - call.respondText("beeped with bypass") - logger.info { "beeped with bypass" } - } else { - if (beepTimedOut) { - call.response.status(HttpStatusCode(423, "Timed Out")) - call.respondText("still sleeping...") - logger.info { "failed beeped" } - } else { - call.response.status(HttpStatusCode(201, "Meow Posted")) - makePost(client, getBeep(), instanceDomain) - beepTimer() - call.respondText("beep sent!") - logger.info { "beeped" } - } - } - } - } - - // kaomoji - route("/kaomoji") { - // get kamoji timeout - get { - if (beepTimedOut) { - call.response.status(HttpStatusCode(423, "Timed Out")) - call.respondText("Timed Out") - logger.debug { "timed out" } - } else { - call.response.status(HttpStatusCode(100, "Not Timed Out")) - call.respondText("Not Timed Out") - logger.debug { "not timed out" } - } - } - // kaomoji button - post { - if (call.receiveText() == superSecret) { - call.response.status(HttpStatusCode(201, "Meow Posted")) - makePost(client, getKaomoji(), instanceDomain) - call.respondText("beeped with bypass") - logger.info { "beeped with bypass" } - } else { - if (beepTimedOut) { - call.response.status(HttpStatusCode(423, "Timed Out")) - call.respondText("still sleeping...") - logger.info { "failed beeped" } - } else { - call.response.status(HttpStatusCode(201, "Meow Posted")) - makePost(client, getKaomoji(), instanceDomain) - kaomojiTimer() - call.respondText("beep sent!") - logger.info { "beeped" } - } - } - } - } - - route("/ntfy") { - get { - } - post { - 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, ntfyEndpoint, title, message, attach, click) - storeMessage(title, message, attach, click) - } - } } + // beep + route("/beep") { + // get beep timeout + get { + if (beepTimedOut) { + call.response.status(HttpStatusCode(423, "Timed Out")) + call.respondText("Timed Out") + logger.debug { "timed out" } + } else { + call.response.status(HttpStatusCode(100, "Not Timed Out")) + call.respondText("Not Timed Out") + logger.debug { "not timed out" } + } + } + // beep button + post { + if (call.receiveText() == superSecret) { + call.response.status(HttpStatusCode(201, "Meow Posted")) + makePost(client, getBeep(), instanceDomain) + call.respondText("beeped with bypass") + logger.info { "beeped with bypass" } + } else { + if (beepTimedOut) { + call.response.status(HttpStatusCode(423, "Timed Out")) + call.respondText("still sleeping...") + logger.info { "failed beeped" } + } else { + call.response.status(HttpStatusCode(201, "Meow Posted")) + makePost(client, getBeep(), instanceDomain) + beepTimer() + call.respondText("beep sent!") + logger.info { "beeped" } + } + } + } + } + + // kaomoji + route("/kaomoji") { + // get kamoji timeout + get { + if (beepTimedOut) { + call.response.status(HttpStatusCode(423, "Timed Out")) + call.respondText("Timed Out") + logger.debug { "timed out" } + } else { + call.response.status(HttpStatusCode(100, "Not Timed Out")) + call.respondText("Not Timed Out") + logger.debug { "not timed out" } + } + } + // kaomoji button + post { + if (call.receiveText() == superSecret) { + call.response.status(HttpStatusCode(201, "Meow Posted")) + makePost(client, getKaomoji(), instanceDomain) + call.respondText("beeped with bypass") + logger.info { "beeped with bypass" } + } else { + if (beepTimedOut) { + call.response.status(HttpStatusCode(423, "Timed Out")) + call.respondText("still sleeping...") + logger.info { "failed beeped" } + } else { + call.response.status(HttpStatusCode(201, "Meow Posted")) + makePost(client, getKaomoji(), instanceDomain) + kaomojiTimer() + call.respondText("beep sent!") + logger.info { "beeped" } + } + } + } + } + + route("/ntfy") { + get { + } + post { + 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, ntfyEndpoint, title, message, attach, click) + storeMessage(title, message, attach, click) + } + } + } + // deprecate route("/meow") { get {