main #8
4 changed files with 36 additions and 1 deletions
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
|
@ -46,3 +46,4 @@ bin/
|
|||
|
||||
### Other ###
|
||||
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.ratelimit.*
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import observer.nelle.nelleObserverBackend.helpers.checkCreate
|
||||
import observer.nelle.nelleObserverBackend.plugins.configureRouting
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
|
@ -36,6 +37,8 @@ fun Application.module() {
|
|||
allowHeader(HttpHeaders.ContentType)
|
||||
anyHost()
|
||||
}
|
||||
// check for ntfyhistory file, and if it doesnt exist, create it
|
||||
checkCreate()
|
||||
runBlocking {
|
||||
val client =
|
||||
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.helpers.getBeep
|
||||
import observer.nelle.nelleObserverBackend.helpers.getMeow
|
||||
import observer.nelle.nelleObserverBackend.helpers.storeMessage
|
||||
import java.util.*
|
||||
import kotlin.concurrent.timerTask
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
@ -140,6 +141,7 @@ fun Application.configureRouting(client: HttpClient) {
|
|||
val click = formParameters["Click"].toString()
|
||||
call.response.status(HttpStatusCode(201, "Received..."))
|
||||
call.respondText("Received:: Title: $title, Message: $message, Attachment: $attach, Click: $click")
|
||||
storeMessage(title, message, attach, click)
|
||||
ntfyMsg(client, title, message, attach, click)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue