Revert "Use kotlin coroutines instead of raw threads (+ refactorings) (#6801)"

This reverts commit f8e0f572
This commit is contained in:
Yair Morgenstern
2022-05-15 19:20:23 +03:00
parent c4de3530f6
commit 7ef2bbc56c
33 changed files with 378 additions and 533 deletions

View File

@ -6,7 +6,6 @@ import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.int
import com.github.ajalt.clikt.parameters.types.restrictTo
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
@ -15,7 +14,6 @@ import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileNotFoundException
internal object UncivServer {
@ -62,10 +60,7 @@ private class UncivServerRunner : CliktCommand() {
val fileName = call.parameters["fileName"] ?: throw Exception("No fileName!")
println("Get file: $fileName")
val file = File(fileFolderName, fileName)
if (!file.exists()) {
call.respond(HttpStatusCode.NotFound, "File does not exist")
return@get
}
if (!file.exists()) throw Exception("File does not exist!")
val fileText = file.readText()
println("Text read: $fileText")
call.respondText(fileText)
@ -73,10 +68,7 @@ private class UncivServerRunner : CliktCommand() {
delete("/files/{fileName}") {
val fileName = call.parameters["fileName"] ?: throw Exception("No fileName!")
val file = File(fileFolderName, fileName)
if (!file.exists()) {
call.respond(HttpStatusCode.NotFound, "File does not exist")
return@delete
}
if (!file.exists()) throw Exception("File does not exist!")
file.delete()
}
}