This commit is contained in:
nelle 2024-09-16 00:36:05 -06:00
parent 5d108a2781
commit a794d1d074
2 changed files with 10 additions and 4 deletions

View file

@ -2,6 +2,7 @@
package observer.nelle.nelleObserverBackend
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.auth.*
@ -14,6 +15,8 @@ import io.ktor.server.plugins.cors.routing.*
import kotlinx.coroutines.runBlocking
import observer.nelle.nelleObserverBackend.plugins.configureRouting
val logger = KotlinLogging.logger("karizzma")
fun main(args: Array<String>): Unit = EngineMain.main(args)
fun Application.module() {

View file

@ -10,6 +10,7 @@ import io.ktor.server.response.*
import io.ktor.server.routing.*
import observer.nelle.nelleObserverBackend.Config
import observer.nelle.nelleObserverBackend.getMeow
import observer.nelle.nelleObserverBackend.logger
import observer.nelle.nelleObserverBackend.makePost
import java.util.*
import kotlin.concurrent.timerTask
@ -18,11 +19,10 @@ var meowTimedOut = false
fun meowTimer() {
meowTimedOut = true
println("timed out")
Timer("SettingUp", true).schedule(
timerTask {
meowTimedOut = false
println("not timed out")
logger.debug { "timeout reset" }
},
// 33 minutes in milliseconds
1980000,
@ -36,10 +36,12 @@ fun Application.configureRouting(client: HttpClient) {
if (meowTimedOut) {
call.response.status(HttpStatusCode(423, "Timed Out"))
call.respondText("Timed Out")
logger.debug { "timed out" }
}
if (!meowTimedOut) {
call.response.status(HttpStatusCode(100, "Not Timed Out"))
call.respondText("Not Timed Out")
logger.debug { "not timed out" }
}
}
@ -48,18 +50,19 @@ fun Application.configureRouting(client: HttpClient) {
post("/meow") {
if (call.receiveText() == Config().superSecret) {
call.response.status(HttpStatusCode(201, "Meow Posted"))
println("secret code received, bypassing timeout")
makePost(client, getMeow(), Config().instanceDomain)
println("meow sent!")
logger.debug { "meowed with bypass" }
} else {
if (meowTimedOut) {
call.response.status(HttpStatusCode(423, "Timed Out"))
call.respondText("still Sleeping...")
logger.debug { "failed meow" }
} else {
call.response.status(HttpStatusCode(201, "Meow Posted"))
makePost(client, getMeow(), Config().instanceDomain)
meowTimer()
call.respondText("meow sent!")
logger.debug { "meowed" }
}
}
}