we have history babeeee!
This commit is contained in:
parent
fe32062d98
commit
303e4061c6
4 changed files with 36 additions and 1 deletions
3
backend/.gitignore
vendored
3
backend/.gitignore
vendored
|
@ -45,4 +45,5 @@ bin/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
### Other ###
|
### Other ###
|
||||||
bot.cfg
|
bot.cfg
|
||||||
|
ntfyHistory.txt
|
|
@ -14,6 +14,7 @@ import io.ktor.server.plugins.contentnegotiation.*
|
||||||
import io.ktor.server.plugins.cors.routing.*
|
import io.ktor.server.plugins.cors.routing.*
|
||||||
import io.ktor.server.plugins.ratelimit.*
|
import io.ktor.server.plugins.ratelimit.*
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import observer.nelle.nelleObserverBackend.helpers.checkCreate
|
||||||
import observer.nelle.nelleObserverBackend.plugins.configureRouting
|
import observer.nelle.nelleObserverBackend.plugins.configureRouting
|
||||||
import kotlin.time.Duration.Companion.minutes
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ fun Application.module() {
|
||||||
allowHeader(HttpHeaders.ContentType)
|
allowHeader(HttpHeaders.ContentType)
|
||||||
anyHost()
|
anyHost()
|
||||||
}
|
}
|
||||||
|
// check for ntfyhistory file, and if it doesnt exist, create it
|
||||||
|
checkCreate()
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val client =
|
val client =
|
||||||
HttpClient(CIO) {
|
HttpClient(CIO) {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package observer.nelle.nelleObserverBackend.helpers
|
||||||
|
|
||||||
|
import observer.nelle.nelleObserverBackend.prop
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
val historyPath = Paths.get("").toAbsolutePath().toString()
|
||||||
|
val historyFile = File("$historyPath/ntfyHistory.txt")
|
||||||
|
|
||||||
|
fun checkCreate() {
|
||||||
|
if (historyFile.exists()) {
|
||||||
|
FileInputStream(historyFile).use { prop.load(it) }
|
||||||
|
} else {
|
||||||
|
Files.createFile(Paths.get("$historyPath/ntfyHistory.txt"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun storeMessage(
|
||||||
|
title: String,
|
||||||
|
message: String,
|
||||||
|
attach: String,
|
||||||
|
click: String,
|
||||||
|
) {
|
||||||
|
val text = "Title: $title, Message: $message, Attach: $attach, Click: $click\n"
|
||||||
|
|
||||||
|
historyFile.appendText(text, Charsets.UTF_8)
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import io.ktor.server.routing.*
|
||||||
import observer.nelle.nelleObserverBackend.*
|
import observer.nelle.nelleObserverBackend.*
|
||||||
import observer.nelle.nelleObserverBackend.helpers.getBeep
|
import observer.nelle.nelleObserverBackend.helpers.getBeep
|
||||||
import observer.nelle.nelleObserverBackend.helpers.getMeow
|
import observer.nelle.nelleObserverBackend.helpers.getMeow
|
||||||
|
import observer.nelle.nelleObserverBackend.helpers.storeMessage
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.timerTask
|
import kotlin.concurrent.timerTask
|
||||||
import kotlin.time.Duration.Companion.minutes
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
@ -140,6 +141,7 @@ fun Application.configureRouting(client: HttpClient) {
|
||||||
val click = formParameters["Click"].toString()
|
val click = formParameters["Click"].toString()
|
||||||
call.response.status(HttpStatusCode(201, "Received..."))
|
call.response.status(HttpStatusCode(201, "Received..."))
|
||||||
call.respondText("Received:: Title: $title, Message: $message, Attachment: $attach, Click: $click")
|
call.respondText("Received:: Title: $title, Message: $message, Attachment: $attach, Click: $click")
|
||||||
|
storeMessage(title, message, attach, click)
|
||||||
ntfyMsg(client, title, message, attach, click)
|
ntfyMsg(client, title, message, attach, click)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue